sorting grass for alpha blending

Started by
16 comments, last by s_p_oneil 18 years, 9 months ago
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
¿We Create World?
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.
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)


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... :(
"Game Maker For Life, probably never professional thou." =)
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.


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.
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.


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
¿We Create World?
I would stick with alpha testing and alpha coverage (which is multisampled alpha testing, http://humus.ca/index.php?page=3D).
[size="1"]Perl - Made by Idiots, Java - Made for Idiots, C++ - Envied by Idiots | http://sunray.cplusplus.se
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.

This topic is closed to new replies.

Advertisement