Much improved cube map visualization
Now displays all six cube map faces as a single cross
This commit is contained in:
parent
50e4972d02
commit
bfdf821d31
5 changed files with 57 additions and 20 deletions
|
|
@ -2,12 +2,53 @@
|
||||||
|
|
||||||
layout (binding = 1) uniform samplerCube shadowCubeMap;
|
layout (binding = 1) uniform samplerCube shadowCubeMap;
|
||||||
|
|
||||||
layout (location = 0) in vec3 inUVW;
|
layout (location = 0) in vec2 inUV;
|
||||||
|
|
||||||
layout (location = 0) out vec4 outFragColor;
|
layout (location = 0) out vec4 outFragColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float dist = length(texture(shadowCubeMap, inUVW).rgb) * 0.005;
|
outFragColor.rgb = vec3(0.0, 0.0, 0.2);
|
||||||
outFragColor = vec4(vec3(dist), 1.0);
|
|
||||||
|
vec3 samplePos = vec3(0.0f);
|
||||||
|
|
||||||
|
// Crude statement to visualize different cube map faces based on UV coordinates
|
||||||
|
int x = int(floor(inUV.x / 0.25f));
|
||||||
|
int y = int(floor(inUV.y / (1.0 / 3.0)));
|
||||||
|
if (y == 1) {
|
||||||
|
vec2 uv = vec2(inUV.x * 4.0f, (inUV.y - 1.0/3.0) * 3.0);
|
||||||
|
uv = 2.0 * vec2(uv.x - float(x) * 1.0, uv.y) - 1.0;
|
||||||
|
switch (x) {
|
||||||
|
case 0: // NEGATIVE_X
|
||||||
|
samplePos = vec3(-1.0f, uv.y, uv.x);
|
||||||
|
break;
|
||||||
|
case 1: // POSITIVE_Z
|
||||||
|
samplePos = vec3(uv.x, uv.y, 1.0f);
|
||||||
|
break;
|
||||||
|
case 2: // POSITIVE_X
|
||||||
|
samplePos = vec3(1.0, uv.y, -uv.x);
|
||||||
|
break;
|
||||||
|
case 3: // NEGATIVE_Z
|
||||||
|
samplePos = vec3(-uv.x, uv.y, -1.0f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (x == 1) {
|
||||||
|
vec2 uv = vec2((inUV.x - 0.25) * 4.0, (inUV.y - float(y) / 3.0) * 3.0);
|
||||||
|
uv = 2.0 * uv - 1.0;
|
||||||
|
switch (y) {
|
||||||
|
case 0: // NEGATIVE_Y
|
||||||
|
samplePos = vec3(uv.x, -1.0f, uv.y);
|
||||||
|
break;
|
||||||
|
case 2: // POSITIVE_Y
|
||||||
|
samplePos = vec3(uv.x, 1.0f, -uv.y);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((samplePos.x != 0.0f) && (samplePos.y != 0.0f)) {
|
||||||
|
float dist = length(texture(shadowCubeMap, samplePos).xyz) * 0.005;
|
||||||
|
outFragColor = vec4(vec3(dist), 1.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
|
@ -1,7 +1,5 @@
|
||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
layout (location = 0) in vec3 inPos;
|
|
||||||
|
|
||||||
layout (binding = 0) uniform UBO
|
layout (binding = 0) uniform UBO
|
||||||
{
|
{
|
||||||
mat4 projection;
|
mat4 projection;
|
||||||
|
|
@ -9,16 +7,11 @@ layout (binding = 0) uniform UBO
|
||||||
mat4 model;
|
mat4 model;
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
||||||
layout (location = 0) out vec3 outUVW;
|
layout (location = 0) out vec2 outUV;
|
||||||
|
|
||||||
out gl_PerVertex
|
|
||||||
{
|
|
||||||
vec4 gl_Position;
|
|
||||||
};
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
outUVW = inPos;
|
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
||||||
gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0);
|
gl_Position = vec4(outUV.xy * 2.0f - 1.0f, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -78,7 +78,7 @@ public:
|
||||||
struct {
|
struct {
|
||||||
VkPipeline scene;
|
VkPipeline scene;
|
||||||
VkPipeline offscreen;
|
VkPipeline offscreen;
|
||||||
VkPipeline cubeMap;
|
VkPipeline cubemapDisplay;
|
||||||
} pipelines;
|
} pipelines;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|
@ -154,7 +154,7 @@ public:
|
||||||
// Pipelibes
|
// Pipelibes
|
||||||
vkDestroyPipeline(device, pipelines.scene, nullptr);
|
vkDestroyPipeline(device, pipelines.scene, nullptr);
|
||||||
vkDestroyPipeline(device, pipelines.offscreen, nullptr);
|
vkDestroyPipeline(device, pipelines.offscreen, nullptr);
|
||||||
vkDestroyPipeline(device, pipelines.cubeMap, nullptr);
|
vkDestroyPipeline(device, pipelines.cubemapDisplay, nullptr);
|
||||||
|
|
||||||
vkDestroyPipelineLayout(device, pipelineLayouts.scene, nullptr);
|
vkDestroyPipelineLayout(device, pipelineLayouts.scene, nullptr);
|
||||||
vkDestroyPipelineLayout(device, pipelineLayouts.offscreen, nullptr);
|
vkDestroyPipelineLayout(device, pipelineLayouts.offscreen, nullptr);
|
||||||
|
|
@ -552,10 +552,12 @@ public:
|
||||||
|
|
||||||
if (displayCubeMap)
|
if (displayCubeMap)
|
||||||
{
|
{
|
||||||
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.cubeMap);
|
// Display all six sides of the shadow cube map
|
||||||
|
// Note: Visualization of the different faces is done in the fragment shader, see cubemapdisplay.frag
|
||||||
|
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.cubemapDisplay);
|
||||||
vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &models.skybox.vertices.buffer, offsets);
|
vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &models.skybox.vertices.buffer, offsets);
|
||||||
vkCmdBindIndexBuffer(drawCmdBuffers[i], models.skybox.indices.buffer, 0, VK_INDEX_TYPE_UINT32);
|
vkCmdBindIndexBuffer(drawCmdBuffers[i], models.skybox.indices.buffer, 0, VK_INDEX_TYPE_UINT32);
|
||||||
vkCmdDrawIndexed(drawCmdBuffers[i], models.skybox.indexCount, 1, 0, 0, 0);
|
vkCmdDraw(drawCmdBuffers[i], 3, 1, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -752,15 +754,16 @@ public:
|
||||||
// Cube map display pipeline
|
// Cube map display pipeline
|
||||||
shaderStages[0] = loadShader(getAssetPath() + "shaders/shadowmapomni/cubemapdisplay.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
shaderStages[0] = loadShader(getAssetPath() + "shaders/shadowmapomni/cubemapdisplay.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
||||||
shaderStages[1] = loadShader(getAssetPath() + "shaders/shadowmapomni/cubemapdisplay.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
shaderStages[1] = loadShader(getAssetPath() + "shaders/shadowmapomni/cubemapdisplay.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||||
rasterizationState.cullMode = VK_CULL_MODE_FRONT_BIT;
|
VkPipelineVertexInputStateCreateInfo emptyInputState = vks::initializers::pipelineVertexInputStateCreateInfo();
|
||||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.cubeMap));
|
pipelineCreateInfo.pVertexInputState = &emptyInputState;
|
||||||
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.cubemapDisplay));
|
||||||
|
|
||||||
// Offscreen pipeline
|
// Offscreen pipeline
|
||||||
shaderStages[0] = loadShader(getAssetPath() + "shaders/shadowmapomni/offscreen.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
shaderStages[0] = loadShader(getAssetPath() + "shaders/shadowmapomni/offscreen.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
||||||
shaderStages[1] = loadShader(getAssetPath() + "shaders/shadowmapomni/offscreen.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
shaderStages[1] = loadShader(getAssetPath() + "shaders/shadowmapomni/offscreen.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||||
rasterizationState.cullMode = VK_CULL_MODE_BACK_BIT;
|
|
||||||
pipelineCreateInfo.layout = pipelineLayouts.offscreen;
|
pipelineCreateInfo.layout = pipelineLayouts.offscreen;
|
||||||
pipelineCreateInfo.renderPass = offscreenPass.renderPass;
|
pipelineCreateInfo.renderPass = offscreenPass.renderPass;
|
||||||
|
pipelineCreateInfo.pVertexInputState = &vertexInputState;
|
||||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.offscreen));
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.offscreen));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue