Code cleanup, comments, android assets
This commit is contained in:
parent
75b2a72957
commit
1b1bb4cbd2
2 changed files with 35 additions and 19 deletions
|
|
@ -5,8 +5,14 @@
|
||||||
},
|
},
|
||||||
"assets": {
|
"assets": {
|
||||||
"models": [
|
"models": [
|
||||||
"trees.dae",
|
"terrain_simple.dae",
|
||||||
"samplescene.dae"
|
"oak_trunk.dae",
|
||||||
|
"oak_leafs.dae"
|
||||||
|
],
|
||||||
|
"textures": [
|
||||||
|
"gridlines.ktx",
|
||||||
|
"oak_bark.ktx",
|
||||||
|
"oak_leafs.ktx"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,21 @@
|
||||||
/*
|
/*
|
||||||
* Vulkan Example - Cascaded shadow mapping for directional light sources
|
Vulkan Example - Cascaded shadow mapping for directional light sources
|
||||||
*
|
Copyright (C) 2017 by Sascha Willems - www.saschawillems.de
|
||||||
* Copyright (C) 2017 by Sascha Willems - www.saschawillems.de
|
This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||||
*
|
*/
|
||||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
|
||||||
|
/*
|
||||||
|
This example implements projective cascaded shadow mapping. This technique splits up the camera frustum into
|
||||||
|
multiple frustums with each getting it's own full-res shadow map, implemented as a layered depth-only image.
|
||||||
|
The shader then selects the proper shadow map layer depending on what split of the frustum the depth value
|
||||||
|
to compare fits into.
|
||||||
|
|
||||||
|
This results in a better shadow map resolution distribution that can be tweaked even further by increasing
|
||||||
|
the number of frustum splits.
|
||||||
|
|
||||||
|
A further optimization could be done using a geometry shader to do a single-pass render for the depth map
|
||||||
|
cascades instead of multiple passes (geometry shaders are not supported on all target devices).
|
||||||
*/
|
*/
|
||||||
// Note: Could be simplified with a layered frame buffer using geometry shaders (not available on all devices)
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -27,7 +37,7 @@
|
||||||
#define ENABLE_VALIDATION false
|
#define ENABLE_VALIDATION false
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#define SHADOWMAP_DIM 1024
|
#define SHADOWMAP_DIM 2048
|
||||||
#else
|
#else
|
||||||
#define SHADOWMAP_DIM 4096
|
#define SHADOWMAP_DIM 4096
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -157,12 +167,8 @@ public:
|
||||||
camera.type = Camera::CameraType::firstperson;
|
camera.type = Camera::CameraType::firstperson;
|
||||||
camera.movementSpeed = 2.5f;
|
camera.movementSpeed = 2.5f;
|
||||||
camera.setPerspective(45.0f, (float)width / (float)height, zNear, zFar);
|
camera.setPerspective(45.0f, (float)width / (float)height, zNear, zFar);
|
||||||
camera.setPosition(glm::vec3(0.0f, 0.62f, -2.4f));
|
|
||||||
camera.setRotation(glm::vec3(0.0f, -13.0f, 0.0f));
|
|
||||||
|
|
||||||
camera.setPosition(glm::vec3(-0.12f, 1.14f, -2.25f));
|
camera.setPosition(glm::vec3(-0.12f, 1.14f, -2.25f));
|
||||||
camera.setRotation(glm::vec3(-17.0f, 7.0f, 0.0f));
|
camera.setRotation(glm::vec3(-17.0f, 7.0f, 0.0f));
|
||||||
|
|
||||||
settings.overlay = true;
|
settings.overlay = true;
|
||||||
timer = 0.2f;
|
timer = 0.2f;
|
||||||
}
|
}
|
||||||
|
|
@ -209,8 +215,11 @@ public:
|
||||||
enabledFeatures.depthClamp = deviceFeatures.depthClamp;
|
enabledFeatures.depthClamp = deviceFeatures.depthClamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup resources used for the shadow map cascades
|
/*
|
||||||
void prepareShadowMaps()
|
Setup resources used by the depth pass
|
||||||
|
The depth image is layered with each layer storing one shadow map cascade
|
||||||
|
*/
|
||||||
|
void prepareDepthPass()
|
||||||
{
|
{
|
||||||
VkFormat depthFormat;
|
VkFormat depthFormat;
|
||||||
vks::tools::getSupportedDepthFormat(physicalDevice, &depthFormat);
|
vks::tools::getSupportedDepthFormat(physicalDevice, &depthFormat);
|
||||||
|
|
@ -276,7 +285,6 @@ public:
|
||||||
Layered depth image and views
|
Layered depth image and views
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Layered depth image
|
|
||||||
VkImageCreateInfo imageInfo = vks::initializers::imageCreateInfo();
|
VkImageCreateInfo imageInfo = vks::initializers::imageCreateInfo();
|
||||||
imageInfo.imageType = VK_IMAGE_TYPE_2D;
|
imageInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||||
imageInfo.extent.width = SHADOWMAP_DIM;
|
imageInfo.extent.width = SHADOWMAP_DIM;
|
||||||
|
|
@ -731,8 +739,10 @@ public:
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate frustum split depths and matrices for the shadow map cascades
|
/*
|
||||||
// Based on https://johanmedestrom.wordpress.com/2016/03/18/opengl-cascaded-shadow-maps/
|
Calculate frustum split depths and matrices for the shadow map cascades
|
||||||
|
Based on https://johanmedestrom.wordpress.com/2016/03/18/opengl-cascaded-shadow-maps/
|
||||||
|
*/
|
||||||
void updateCascades()
|
void updateCascades()
|
||||||
{
|
{
|
||||||
float cascadeSplits[SHADOW_MAP_CASCADE_COUNT];
|
float cascadeSplits[SHADOW_MAP_CASCADE_COUNT];
|
||||||
|
|
@ -889,7 +899,7 @@ public:
|
||||||
loadAssets();
|
loadAssets();
|
||||||
updateLight();
|
updateLight();
|
||||||
updateCascades();
|
updateCascades();
|
||||||
prepareShadowMaps();
|
prepareDepthPass();
|
||||||
prepareUniformBuffers();
|
prepareUniformBuffers();
|
||||||
setupLayoutsAndDescriptors();
|
setupLayoutsAndDescriptors();
|
||||||
preparePipelines();
|
preparePipelines();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue