PDA

View Full Version : glPolygonOffset and GLSL



eldritch
06-18-2010, 08:07 AM
Hi,

I have a large outdoor scene where i use the logarithmic depth buffer method described here:

http://outerra.blogspot.com/2009/08/logarithmic-z-buffer.html

This works nicely and my depth precision is extremely good. However, I need to render some runways with runway markings, and for this I have used glPolygonOffset. Now, it appears that when I write to the gl_FragDepth in the shader, the glPolygonOffset is disabled.

Is there any way to read out the offset values in the shader? Any built-in uniforms or similar?

This z-buffer method is implemented in all my material shaders, and I would rather not have to define this as a new uniform variable in all my various shaders.

Any idea how to fix this?

Alfonse Reinheart
06-18-2010, 09:39 AM
Now, it appears that when I write to the gl_FragDepth in the shader, the glPolygonOffset is disabled.

Of course it does. glPolygonOffset changes what the computed depth is. If you're overriding the computed depth, it will have no effect.


Is there any way to read out the offset values in the shader?

Not for polygon offsetting. You could pass the offset values to the shader and use shader logic to compute the offset for your computed depth, though.

eldritch
06-21-2010, 03:42 AM
Now, it appears that when I write to the gl_FragDepth in the shader, the glPolygonOffset is disabled.

Of course it does. glPolygonOffset changes what the computed depth is. If you're overriding the computed depth, it will have no effect.



I understand that, but I kind of hoped that the offset parameters would be passed as global uniforms like many other parameters from the fixed function pipeline.

Adding these parameters as shader uniforms will be difficult in my engine, but I guess I can (mis)use some other global uniform, such as a random clip plane or fog parameters or something.