BlackMojito Posted January 23, 2018 Share Posted January 23, 2018 I have some doubt about the depth shader. The output seems not to be the depth value in NDC space, nor the value like gl_FragCoord.z. So what it is about? Please correct me if I am wrong. gl_Position = viewProjection * finalWorld * vec4(position, 1.0); vDepthMetric = ((gl_Position.z + depthValues.x) / (depthValues.y)); Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 23, 2018 Share Posted January 23, 2018 Hello! The value is in linear space See here an example on how to use it: https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/ssao2.fragment.fx#L43 Quote Link to comment Share on other sites More sharing options...
BlackMojito Posted January 24, 2018 Author Share Posted January 24, 2018 5 hours ago, Deltakosh said: Hello! The value is in linear space See here an example on how to use it: https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/ssao2.fragment.fx#L43 Thank you @Deltakosh. Hummm...I am really confused. As far as I understand, the z component in projection space (some sort of 1/Zviewspace) is linear in screen space (for interpolation reason) but non linear as depth. So this is for convert it again to a linear depth but mapped in [0, 1]? The value of vDepthMetric is 1 - ((far - gl_Position.z) / (far + near)). I am not sure why it is linear again. Maybe it is a stupid question though...Thanks in advance for more explanation. One more question, is gl_FragCoord.z the interpolation result of z in projection space? Quote Link to comment Share on other sites More sharing options...
BlackMojito Posted January 24, 2018 Author Share Posted January 24, 2018 8 hours ago, Deltakosh said: Hello! The value is in linear space See here an example on how to use it: https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/ssao2.fragment.fx#L43 Hi @Deltakosh, the sample you gave was about the SSAO2, it uses the GeometryBufferRenderer which is based on the shader geometry.vertex.fx and geometry.fragment.fx. Please see the links below. Here we output directly depth in view space (although I don't understand why we need to divide z by w because w should always be 1.0 here). It works perfectly with the SSAO2 sample as it construct a viewRay in View space. https://github.com/BabylonJS/Babylon.js/blob/1dd71f9e125247a54c315d870b979ee0ec731433/src/Shaders/geometry.vertex.fx#L40 https://github.com/BabylonJS/Babylon.js/blob/1dd71f9e125247a54c315d870b979ee0ec731433/src/Shaders/geometry.fragment.fx#L30 My initial question is about depth.vertex.fx and depth.fragment.fx, which I believe are used by DepthRenderer. Then the output of DepthRenderer is used by SSAO effect. in depth.vertex.fx gl_Position = viewProjection * finalWorld * vec4(position, 1.0); vDepthMetric = ((gl_Position.z + depthValues.x) / (depthValues.y)); float depth = texture2D(textureSampler, vUV).r; vec3 position = vec3(vUV, depth); Quote Link to comment Share on other sites More sharing options...
BlackMojito Posted January 24, 2018 Author Share Posted January 24, 2018 8 hours ago, Deltakosh said: Hello! The value is in linear space See here an example on how to use it: https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/ssao2.fragment.fx#L43 Hi @Deltakosh, the sample you gave was about the SSAO2, it uses the GeometryBufferRenderer which is based on the shader geometry.vertex.fx and geometry.fragment.fx. Please see the links below. Here we output directly depth in view space. This should be the linear depth. It works with the SSAO2 sample as it construct a viewRay in View space. https://github.com/BabylonJS/Babylon.js/blob/1dd71f9e125247a54c315d870b979ee0ec731433/src/Shaders/geometry.vertex.fx#L40 https://github.com/BabylonJS/Babylon.js/blob/1dd71f9e125247a54c315d870b979ee0ec731433/src/Shaders/geometry.fragment.fx#L30 My initial question is about depth.vertex.fx and depth.fragment.fx, which I believe are used by DepthRenderer. Then the output of DepthRenderer is used by SSAO effect. in depth.vertex.fx gl_Position = viewProjection * finalWorld * vec4(position, 1.0); vDepthMetric = ((gl_Position.z + depthValues.x) / (depthValues.y)); in ssao.fragment.fx float depth = texture2D(textureSampler, vUV).r; vec3 position = vec3(vUV, depth); As we know that vUV is [0, 1], so should be the "depth". My question is why we don't directly use gl_FragCoord.z? Why we use the "vDepthMetric"? Quote Link to comment Share on other sites More sharing options...
BlackMojito Posted January 24, 2018 Author Share Posted January 24, 2018 @Luaacro, would you please help answer the question as you are the implementer of SSAO? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 24, 2018 Share Posted January 24, 2018 Hello unfortunately gl_FragCoord.z is NOT linear check the answer here: https://stackoverflow.com/questions/13711252/what-does-gl-fragcoord-z-gl-fragcoord-w-represent (z = (clip.z/clip.w)/2 + 0.5) julien-moreau 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.