PDA

View Full Version : Strange edge artifacts with gl_FrontFacing



awangk
12-06-2011, 02:00 PM
I'm trying to do two-sided lighting, but I'm getting these annoying artifacts on the edges (see attached picture). Apparently for these fragments gl_FrontFacing is false..?

Shaders are simply:



#version 120
void main()
{
gl_Position = ftransform();
}


and..


#version 120
void main()
{
if (gl_FrontFacing)
gl_FragColor = vec4(1,0,1,1);
else
gl_FragColor = vec4(0,0,1,1);
}


Thanks!

dorbie
12-09-2011, 10:33 AM
This is zfighting at the silhouettes due to the back facing fragments winning the zbuffer evaluation, due to front back order and z fragment equality at the silhouette.

Try to increase z precision if you can, push near clip plane out and pull far clip plane in.

You could also do a two pass render, in pass one have front faces off, then in pass 2 with backfaces off you make sure you have less than or equal to instead of a less than test.

awangk
12-09-2011, 02:32 PM
Okay, thanks!

I managed to get it work using glPolygonOffset, so that the backfaces are offset a bit before being drawn.