View Full Version : gl_FragCoord.z confusion
07-12-2011, 08:57 AM
my question is simple.
Where do gl_FragCoord.z come from?
Is it coming from the rasterizer ( the eventually new incoming depth buffer value ) or is it the actual value grabbed from the depth buffer?
07-12-2011, 09:21 AM
I'll give you an answer by asking you a question.
Does fragment shader execution comes before writing to a framebuffer of after? If you don't change fragmet's depth some of early-z techniques would eliminate FS execution if they are sure it wouldn't generate a new value in the framebuffer.
07-12-2011, 09:28 AM
:) ok ok.
I'm trying to figure out how to access depth buffer directly in the fragment shader. It seems that DX10 can do that via Shader Resource View without rendering into a texture and binding it again in the second pass.
Does OpenGL exposes this feature too?
07-12-2011, 11:44 AM
Why do you need that? To write your own function that will decide whether to write new Z-value in the dept buffer or something else? If you need the final values of the depth buffer you would need a second pass anyway.
07-12-2011, 12:50 PM
I'm trying to figure out how to access depth buffer directly in the fragment shader.
It seems that DX10 can do that via Shader Resource View without rendering into a texture and binding it again in the second pass.
That's just because D3D10 requires you to create the equivalent to OpenGL's "default" buffers itself. Shader Resource View is just a way to bind parts of textures (particular mipmaps, groups of mipmaps, etc) as textures to fetch from.
07-13-2011, 02:47 AM
Yes i would like to write my custom depth testing when i need it ( to avoid Z-fighting for example ). So is not possible to access depth buffer in the fragment shader.
There is a similar problem with blending. You can't access color buffer in the fragment shader and write your custom blending function. Right?
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.