In our current project we have probability of having some lines drawing on exact same place. Than we are having a flickering effect like this.
I am trying to manipulate gl_FragDepth values depending on the geometry types to over come this problem. In my fragment shader I have something like:
if ( offset > 0.0 )
gl_FragDepth = gl_FragCoord.z - offset*0.001;
Some lines have priorities over other objects and I am manipulating the uniform variable "offset" to achieve that.
The result is a bit better at first glance :
Even the object which have exact some position looks better I have problems in normal case objects are jumping on top of each other.
My questions are :
1 - Is manipulating gl_FragDepth with smallest possible z-depth for specific prioritized objects a good strategy?
2 - If so instead of assigning gl_FragCoord.z should I use something like described here. ?
Which I tried by calling this function :
float findRealDepth(in highp mat4 modelViewProjectinMatrix,
in highp vec4 objectPosition)
{
float far=gl_DepthRange.far; float near=gl_DepthRange.near;
vec4 clip_space_pos = modelViewProjectinMatrix * vec4(objectPosition.xyz, 1.0);
float ndc_depth = clip_space_pos.z / clip_space_pos.w;
return (((far-near) * ndc_depth) + near + far) / 2.0;
};