opengl es - How to emulate GL_DEPTH_CLAMP_NV? -
i have platform extension not available ( non nvidia ). how emulate functionality ? need solve far plane clipping problem when rendering stencil shadow volumes z-fail algorithm.
since you're using opengl es, mentioned trying clamp gl_fragdepth, i'm assuming you're using opengl es 2.0, here's shader trick:
you can emulate arb_depth_clamp using separate varying z-component.
vertex shader:
varying float z; void main() { gl_position = ftransform(); // transform z window coordinates z = gl_position.z / gl_position.w; z = (gl_depthrange.diff * z + gl_depthrange.near + gl_depthrange.far) * 0.5; // prevent z-clipping gl_position.z = 0.0; }
fragment shader:
varying float z; void main() { gl_fragcolor = vec4(vec3(z), 1.0); gl_fragdepth = clamp(z, 0.0, 1.0); }
Comments
Post a Comment