I am building a 3d renderer in C++ using Vulkan. I am in the process of implementing…
- User
I am building a 3d renderer in C++ using Vulkan. I am in the process of implementing point shadows using cube maps. I have previously implemented directional shadows to texture maps and am leveraging and then modifying those processes for cube maps. I have created the cube maps, along with the appropriate images and image views, and the shader programs to write to them, but want to ensure I am modifying all of the correct parts of the rendering pipeline to accommodate cube maps. I have changed the layers attribute to 6 in the framebuffercreateinfo. Is there anything else I should be making sure I modify to ensure the pipeline can handle cube maps?
- Assistant
- User
Sorry I should have been more detailed on my current state. I am using a geometry shader to handle the 6 faces of the cube map. This in turn takes the perspective matrix as a uniform buffer to determine the 6 faces. All other required uniform inputs in the shaders are also being handled. I believe the shader program should be working to correctly write cube maps. I am currently not reading the cube map output and am instead using RenderDoc to verify it is being written to correctly before I incorporate the cube map texture outputs back into the rendering pipeline. Based on this, and my previous comments, is there anything else I should be specifically modifying to ensure the cube map can be properly written to?
- Assistant
- User
As a means of testing the process, I have hard-coded the output of the fragment shader to 0.5. However, the actual output seems to be defaulting back to the clear value. I have tried changing the clear value, and the value is being reflected in the resulting cube map, so it seems the framebuffer is set up correctly. Do you know of any reason why the fragment shader may not be writing to the cube map output?
- Assistant
- User
Just to confirm on your 3rd point, I am currently writing the output to gl_FragDepth. Is this a standard glsl output variable or does the output variable need to be specified when writing to a depth buffer output?
- Assistant
- User
- Assistant
- User
I have checked the key points you have specified and can't find any issues. Here is the shader code for further reference. Can you see any thing in this code and what I have supplied so far that might be preventing the 0.5 depth value being written to the cube map?
Vertex Shader:
#version 450 core layout (location = 0) in vec3 aPos;
layout(binding = 0) buffer ModelBufferObject { mat4 models[]; } modelUBO;
void main() { gl_Position = modelUBO.models[gl_InstanceIndex] * vec4(aPos, 1.0); }
Geometry Shader:
#version 450 core layout(triangles) in;
layout(triangle_strip, max_vertices=18) out; layout(location = 0) out vec4 FragPos;
layout(binding = 1) uniform ShadowMatrixObject { mat4 shadowMatrices[6]; } shadowmatrixUBO;
void main() { for(int face = 0; face < 6; ++face) { gl_Layer = face; // built-in variable that specifies to which face we render. for(int i = 0; i < 3; ++i) // for each triangle's vertices { FragPos = gl_in[i].gl_Position; gl_Position = shadowmatrixUBO.shadowMatrices[face] * FragPos; EmitVertex(); } EndPrimitive(); } }
- Assistant
- User
- Assistant
- User
Based on your review of all of the code I have provided so far, can you see anything that might be causing the output depth fragment value of 0.5 to not be written to the cube map?
- Assistant
- User
- Assistant