-
Crossed Polygons and blend problems
I'm rendering two crossed quads (one polygon intersects another at the middle point) and applying a grass texture on them to simulate a field of grass in real time.
like this image: 
Im using glEnable(GL_BLEND) and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) for the blend func.
But as they are at the same level on Z buffer, I think opengl cant know who's first and the second one doesnt get the trasparency correctly.
Im using a TGA 32-bit with alpha channel as textures.
Anyone knows a solution for this?
Thnxs in advance,
Bruce Sinner
-
Re: Crossed Polygons and blend problems
dont update the zbuffer when rendering the first quad
or
draw 4 quads
-
Re: Crossed Polygons and blend problems
I tried:
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
Draw();
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
But still didnt get good results. Now one polygon overlaps the second when they are at a certain angle...
The only way i did it correctly was turning on Alpha_Test (glEnable(GL_ALHA_TEST)) and putting alphafunc to
glAlphaFunc(GL_GREATER, 0.5);
But it leads me to some visual artifacts on the texture...
Any tips?
-
Advanced Member
Frequent Contributor
Re: Crossed Polygons and blend problems
The blending mode you have selected isn't commutative so you'll have to sort all your polygons in back to front order to get correct results.
edit: if the polygons are intersecting/co-planar and this causes z-fighting, use glPolygonOffset or simply push them further apart.
-
Re: Crossed Polygons and blend problems
Harshman,
They intersect, but exactly at the middle point.
So how can I use glPolygonOffset on this???
Im a little lost with this problem...
-
Re: Crossed Polygons and blend problems
The ultimate solution is to not render intersecting faces, and render them back-to-front. Split your two quads into four quads and sort them.
Other approaches may give you "acceptable" results, but they are basically just hacks. Worth a shot if run into severe performance problems, but keep in mind that they will not produce "correct" results.
-
Re: Crossed Polygons and blend problems
Yes, I thought about this solution, but one thing comes to my mind. Every time i change my camera, i will need to re-sort all the polys???
And other thing...using just glBlend i can see the polygon edge...but if i turn alpha on i get terrible looking results...any tip?
-
Super Moderator
OpenGL Lord
Re: Crossed Polygons and blend problems
>> Every time i change my camera, i will need to re-sort all the polys???
Right. Search for radix sort, I've heard it gives good results.
>> using glBlend i can see the polygon edge...
Can you be more precise or post a screenshot ?
It may be that the grass blade color and alpha change at exactly the same place. Try to color the whole texture in green.
Else you end up with 2 crossfades, one from (ie) black to green, the other from transparent to opaque. In between, there is... half transparent dark green, and it is ugly.
-
Re: Crossed Polygons and blend problems
ZbuffeR you can get the project here:
Project Link
Just run the EXE and see for yourself. If you want you can mess with source too, it is in the zip. (M$ Visual Studio 6)
-
Super Moderator
OpenGL Guru
Re: Crossed Polygons and blend problems
The way this is normaly solved (or at least mitigated) is to enable alpha testing and set an appropriate threshold and test with glAlphaFunc.
Your problem is the zbuffer with unsorted transparency. There's no way around this besides sorting and in this case that requires splitting the quads, however the alpha test will allow you to eliminate transparent pixels before they are written to the depth buffer and eliminate the most obvious problems without the need for a primitive level sort.
There is a more advanced technique if you are multisampling where you can asign subpixel sample coverage based of fragment alpha to do this disable blending and call glSampleCoverageARB with the SAMPLE_ALPHA_TO_COVERAGE_ARB token and the multisample mask of the tree fragments will occlude correctly using the zbuffer at the subsample level. Although the edge transition won't be as smooth as a blended one this will give you a few shades of transparency (how many depends on your multisample count) and it will allow correct depth buffered semi-transparent occlusion.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules