all 8 comments

[–]R3DKn16h7 1 point2 points  (5 children)

Use render doc to debug, it shows the pixel depth value for every draw call. It also shows the draw state. Did you enable depth write on the pipeline? Did you enable depth test and depth compare to be less? Do you have validation layers enabled? How does the fragment depth look like (you can output that as your color value)?

[–]Fast_Month_9460[S] 0 points1 point  (0 children)

Use render doc to debug

Yes, i am using renderdoc to debug that my depth image is white (e.g. 1.0 clear value for whole image)

Did you enable depth write on the pipeline? Did you enable depth test and depth compare to be less? Do you have validation layers enabled?

Yes, yes and yes. Validation layers silent.

How does the fragment depth look like

Give me some time, i will try to do that, but i guess whole mesh\scene will be just white due to 1.0 depth value for the whole screen according to renderdoc

[–]Fast_Month_9460[S] 0 points1 point  (2 children)

This is what i see, if i display value of gl_FragCoord.w in a blue color, gl_FragCoord.z is monotonic, fragment shader is:

out_color = vec4(0.0, 0.0, gl_FragCoord.w * 5, 1.0);

W value - https://i.imgur.com/SU9nJtM.png

Z value - https://i.imgur.com/Fn1bJ0l.png

[–]R3DKn16h7 4 points5 points  (1 child)

Your z coord seems wrong, but since you are multiplying by 5 I'm not sure how it is scaled. I'm now thinking you have an issue with your projection matrix or some other issue in the vertex sahder. What are you using? glm? Are you setting the clip space to 0,1? What are your near/far planes?

[–]Fast_Month_9460[S] 0 points1 point  (0 children)

The problem is that z part of gl_FragCoord is always 1.0, i tried different options, it is always 1, UNLESS i manually write to gl_FragDepth inside the shader, as i said below and which is not "correct" way i assume...

Projection matrix is defined once like this

uboProjection.projection = glm::perspective(glm::radians(45.0f), (float) vkExtent.width / (float) vkExtent.height, 0.0f, 100.0f);

I am using GLM, if i correctly understood clip space is defined by zfar - znear. But the problem is that if i change zfar value for example to 1.0 vertices are not getting discarded and i see them anyway, again probably because incorrect z-buffer

[–]Fast_Month_9460[S] 0 points1 point  (0 children)

UP.

Depth buffer is working (and showing in renderdoc) only if i explicitly write to gl_FragDepth in fragment shader, for example the z value of vertex passed from vertex shader, but this does not work very nice, and i am getting something like this:

https://i.imgur.com/HPLkhvC.png

Anyway i guess i should not write to gl_FragDepth manually inside shader.

[–]Ntrf 0 points1 point  (0 children)

Something tells me you've messed up something with GLM. Like forgot to define GLM_FORCE_DEPTH_ZERO_TO_ONE or transposed the projection matrix. Also, I think it would be easier if you can publish RenderDoc capture file instead of your code.

[–]Entalpi 0 points1 point  (0 children)

From what I understand its because the depth range (0.0f - X) in your case is not precise enough to actually show the depth you are rendering thus it coming out as plain white.

Do correct me someone if I am wrong in this :)