• Advertisement
Sign in to follow this  

Sweet Grass

This topic is 4489 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've been working on making my grass look (even :) ) better, but I landed on a problem, which has to do which depth buffering/sequence of drawing I guess. The Idea is to project quads randomly distributed around my landscape which are textured with grass/plant texture (billboarding idea, but with(out) the twist). I use (GL_DST_COLOR, GL_ZERO) to make sure only the grass is visible (anything white in the texture looks transparent). Seen from above I draw 2 quads which intersect; seen from above it would look like; | -- -- | Each quad is blended and contains a picture of a small plant. The idea is that the white becomes transparent so you're left with only the plant; drawn in 2 directions to make it look more natural. Screen shot to illustrate the problem I also lines the texture with a red line to make more clear how the quads are placed; Screen shot to illustrate the problem The solution would be to turn of the depthbuffer while drawing the grass. But then it's visible everywhere, (also behind a mountain), so thats no solution. Is it maybe possible to only turn of depth buffer between the grass/plant elements, but not between the enitire grass display and the rest of the screne ????? Can anyone tell how to fix this, cause I think this is a very common problem, since it produces problems with all sort of thing which involve many polygons and blending etc... Thanx in advance to anyone whom takes the effort to spoil his/her time with my insignificant little troubleshootings ;) [Edited by - Kincaid on October 8, 2005 3:11:22 PM]

Share this post


Link to post
Share on other sites
Advertisement
Try this set up. I used it for my particle system but it should still apply.

Leave depth testing enabled, but disable depth-writing, using glDepthMask(0) while rendering the plants.

Share this post


Link to post
Share on other sites
Excellent !
thanx.

My faith in opengl never dissapoint me :)
Love it when a solution is this simple

Share this post


Link to post
Share on other sites
Now that it works it seems that the blend mode isn't the most perfect.
It cutts the blacks away nicely but the rest of the plants are blended in some way.
Is their another blend mode to make sure the plant looks exaclty like in the texture, but the blacks are transparent ???

Or is there a trick ??

I tried masking, from nehe tutorial, but that requires the depthmask to be turned off.
I cant do this cause the nothing is abscured by the landscape ??

Any suggestions ????

Share this post


Link to post
Share on other sites
You might find alpha testing suits your needs. Keep depth reading and writing enabled, and set the alpha test so that fragments are only rendered if their alpha value is non-zero (they are visible.)

In your first image, even the 0-alpha (invisible) framgents are being drawn- this means depth values are being written to the z-buffer despite the fragment being invisible. Fragments behind the invisible one should be visible, but are being rejected based on the depth test (since the z-buffer read is saying that they are obscured.)

Hope that helps! Just ask if you need anything clarifying.

Edit: MSDN resource- might be better.

Share this post


Link to post
Share on other sites
The alphafunc reeds the alphavalues, so the values dat are defined by glColor4f in glBegin routine (?)
these values are all 1. de mode of (GL_DST_COLOR,GL_ZERO) make it that the black disappear.

Should I load TGA textures or something (now still using bmp).
They have an alpha channel right ?

Share this post


Link to post
Share on other sites
The alpha function checks the alpha values per fragment. So yes, if you use the alpha function you'll need to use a format that supports alpha transparency (sorry, I missed the bit about blending based on colour rather than alpha [embarrass])

And yes, .TGAs can have alpha channes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement