Sorting alpha blended grass

Started by
1 comment, last by DracoLacertae 12 years, 5 months ago
Hi,
I am not satisfied with alpha tested grass, harsh edges are the main problem.
Also dissolving at distance is a problem too, I tried to use noise texture to simulate "fade out effect" but it still looks like garbage.
I also used a 2 pass approach alpha blending and alpha testing, but in the end I decided to use alpha blending only with semi transparent grass billboards. This is expensive but looks very natural, this gave me the best results, but I dont know how to sort the billboards properly.
I read somewhere that one can first sort the grass batches(grid cells) and then use pre calculated view positions, if I understand correctly, but this would eat alot memory.
So how do you sort grass billboards in an efficient way.

Thanks

Advertisement
I mean grass rendering as described here
Anyone tried to sort like this?
Or another approach?
Any suggestions?
To sort the billboards, just sort from distance to the camera. Qsort is a good place to start for the first frame, but after that, since the camera moves slowly frame-to-frame, and the desired render order for the billboards will change a little at a time, bubble sort is a usable choice. Bubble sort is the 'worst' sort because its O(n^2), but for incremental updates, its close to O(n). If you're worried about the worst-case scenario where a bunch of things suddenly reverse sort order, you can limit the number of iterations of the bubble sort per frame. What this will do, is it will keep up with the 'small' changes, but if there's a LOT of things changing order at once, the job will be broken into multiple frames. The user will see the incorrect order for a few frame, and then it will 'pop' to the correct order. But this is probably better than just stalling..

If your terrain is broken into difference sections (like a grid or whatever), then you can do the sort in two levels: Sort the sections based on distance, and then the contents of each section by distance. This breaks the sort down to where its easier to manage. In fact, distance sections don't have to be sorted every frame, since at a distance, the view angle changes very slowly. Basically you would re-sort the section the camera is in, then then re-sort the other sections only if their view angle has changed more than some threshold angle. This should work as long as each grass part is restricted to a particular section; if a piece of grass spans two sections, there will be problems.

This topic is closed to new replies.

Advertisement