Sign in to follow this  

Alpha Blending and Intersecting Triangles

This topic is 4688 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I believe the only way to get 'correct' alpha blending in this situation is to split one or both of the triangles into pieces along the line formed by the intersection of the triangles, then render the pieces in correct back to front order. This only applies if alpha blending is being performed. If the alpha of the textures is either 1 or 0 (ie, 0 simply defining areas of transparency) and no blending is being done--which I gather might be the case, since you are doing leaves--you can simply enable alpha testing so that pixels where alpha=0 do not modify the depth buffer; in this case, you can simply draw the two triangles as-is without splitting.

Share this post


Link to post
Share on other sites
Quote:
Original post by VertexNormal
...you can simply enable alpha testing so that pixels where alpha=0 do not modify the depth buffer...


How exactly do you do this? You can either enable or disable writing to the depth buffer using the glDepthMask function. But once you start drawing the polygon, away it goes. How can you put a condition depending on the alpha of each pixel?

Share this post


Link to post
Share on other sites
You can use alpha testing becuase it comes before depth testing in the order of operations. As Alphatesting is a boolean operation it will either pass, and update the zbuffer, or fail and not touch it (if you have depth writes active of course).


The draw back to this approach is clearly that you'll get alaised results, instead of nice alpha blending. If this is for the case of rendering tree leaves or other folliage then I believe a method sometimes emplloyed is to render the alpha texture sveral times with a different alphatest and blend value to simulate smoother blending.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ryback
...How can you put a condition depending on the alpha of each pixel?...


glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);

With that, all fragments with an alpha value greater than 0.0 will fail the alpha test and will not be written to the framebuffer (color/depth/stencil).

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalidor

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);

With that, all fragments with an alpha value greater than 0.0 will fail the alpha test and will not be written to the framebuffer (color/depth/stencil).


Don't you mean the opposite? With that code, all fragments with an alpha value greater than 0.0 will PASS the alpha test and will be written to the framebuffer.

Anyways, thanks for the info, I will try it tonight!

Share this post


Link to post
Share on other sites
Quote:
Original post by RybackDon't you mean the opposite? With that code, all fragments with an alpha value greater than 0.0 will PASS the alpha test and will be written to the framebuffer.

Anyways, thanks for the info, I will try it tonight!


Err... yeah that's what I meant. :P
Sorry about that.

Share this post


Link to post
Share on other sites

This topic is 4688 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this