Jump to content
  • Advertisement
Sign in to follow this  
mictian

sorting grass for alpha blending

This topic is 4793 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 am trying to render a bunch of meshes with alpha-blended grass textures on them. I know I have to render them back to front for a proper effect, but what is the best way to do this? I guess if I use some n^2 sort I might be able to get a better runtime by exploiting temporal coherence. However I had a different idea that I want some feedback on. I was thinking of doing a radix based sort, on the squared distance from viewpoint to the grass mesh. But instead of having each radix "bucket" be the same size, I would have them more fine-grained near the user and larger in the distance, like some sort of logarthmic scale. Let me know what you think of this idea, or if i sould just go ahead with some n^2 crapola. Rob edit: drunk typing

Share this post


Link to post
Share on other sites
Advertisement
Alternativly, cheat and just use alpha testing. Then you don't need any sorting (or blending) so you can have much denser grass. With a suitable alpha test value you still get nice irregular edges.

Share this post


Link to post
Share on other sites
just to extend the sort talk, n^2 is the worse algorithm you can think of for general use, use mergesort or quicksort (better) which has O(n*log(n)) as complexity, making theme slaughter insertionsort O(n^2). (the only reason insertionsort exists is because of the O(n) best case for already sorted lists)

Share this post


Link to post
Share on other sites
Hi there, Orangytang!

Could you perhaps explain a little more about alpha testing...?

Do I have to disable glBlend first?

p.s a sample code would be very nice. :D



btw, I tried using alpha testing before, but it still needed sorting... :(

Share this post


Link to post
Share on other sites
Quote:
Original post by Rasmadrakbtw, I tried using alpha testing before, but it still needed sorting... :(


The point of alpha testing is to not require sorting... and according to nvidia and the people who tried it, it works.

Share this post


Link to post
Share on other sites
I haven't used alpha testing, so my info is limited, but I am able to give you some pointers from NeHe lesson 32.

Instead of
glEnable(GL_BLEND);
you can use

glAlphaFunc(GL_GREATER,0.1f);
glEnable(GL_ALPHA_TEST);
and you don't need to sort your grass meshes. However, you can only blend using completely transparent pixels and completely opaque.
How you can get irregular edges by playing with the alpha value I don't know, maybe OrangyTang can help you with that.

Share this post


Link to post
Share on other sites
Sorry I said the wrong name.
http://developer.nvidia.com/object/Interactive_Order_Transparency.html
There you have true alpha transparency without sorting at all.

However, using the Alpha Test you will still get artifacts, one way or the other, either the outer edges might get cut away (more or less), or you will see through (more or less), will get the worst away.

However, doing sorting or the nvidia-documentation is the only way without sorting that I've ever heard of (and likely there is no other to speak of as the nvidia solution has been brought up).

So it's just too choose, I'm guessing the nvidia solution is overkill for most applications.

Share this post


Link to post
Share on other sites
Thanks guys, I have never heard of the alpha test before, I will give this a go and see what results I can get.

Thanks again.

rob

Share this post


Link to post
Share on other sites
I would stick with alpha testing and alpha coverage (which is multisampled alpha testing, http://humus.ca/index.php?page=3D).

Share this post


Link to post
Share on other sites
There are a couple of other possibilities depending on how you are doing your grass.

One trick is to have about 6-12 different index lists, each with the grass sorted in a different order, along a different world space xz vector. When rendering the grass, choose the one that most matches the camera's view vector.

If you are creating grass around the player, you could create it in radial bands, with each band drawn from furthest to nearest.

I should point out that these two approaches would allow for alpha blending, and not simply alpha testing.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!