Rendering vegetation

Started by
10 comments, last by Zemedelec 18 years, 4 months ago
My goal is to have vegetation stored as a polygon soup stored in a vertex buffer. Each terrain block that makes up my terrain has its own vertex buffer for vegetation. Each little piece of vegetation is a simple X shaped pair of quads, and the vertex buffer is built with just lots of those things. Next, as vegetation moves closer to the player I want them to fade in, and fade out as they get farther away, so I don't have to draw ALL the little pieces of vegetation. So far I've got a little multipass system that I found here that is able to blend all the vegetation fairly nicely (not perfect) without having to sort them. But I can't really figure out a good way to combine this system with fading them in and out. I thought about using a shader to do it, but there'd be major problems with all the Z buffer nonsense going on since they aren't being sorted. Is the only way to do what I want to sort ALL the little polygons that make up the vegetation? I'm getting fairly good performance at the moment, and I'd hate to have to kill it. I could easily end up sorting 90000 or so triangles each frame.
I like the DARK layout!
Advertisement
Check out radix sort. If you need to sort stuff like this, it's the only way to go.
no need to sort
2 options
A/ alphatest
B/ multisample with glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);

B looks better (and is only slightly slower)
Quote:Original post by BradDaBug
...


1. Sort when needed (usually it will be very rare, and dependant on camera position)

2. Keep some (4-6-8?) IB-s, where VB is sorted from a given direction and just use the appropriate IB.

Blending (or applying different shader) the distant grass is just rendering with different shader the more distant part of the IB. I.e. cut your IB into IBnear and IBfar, and apply the effects needed. Of course, that is just for performance...
I think Battlefield 2 "grows" vegetation as you approach it. i.e. it scales from zero height to full height as it approaches. I guess this would maybe only work for grass and other dense, simple vegetation, but you wouldn't need to sort.
Also I think scaling the UVs inversely so that the vegetation is cropped rather than scaled might make it look better, otherwise it would appear to spring out of the ground.
Quote:Original post by zedzeek
B/ multisample with glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);

How exactly do I use that? I tried just adding glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB) before rendering the vegetation (no multipass stuff, just a single pass) and I couldn't tell any difference with it on or off.
Quote:Original post by bluntman
I think Battlefield 2 "grows" vegetation as you approach it. i.e. it scales from zero height to full height as it approaches. I guess this would maybe only work for grass and other dense, simple vegetation, but you wouldn't need to sort.
Also I think scaling the UVs inversely so that the vegetation is cropped rather than scaled might make it look better, otherwise it would appear to spring out of the ground.

That sounds simple. But wouldn't I need some kind of vertex shader to scale the plants based on their distances (if I wanted to still use a vertex buffer)? And wouldn't the vertex shader only work on individual vertices? How would I know how to move the vertex around to scale the plants? Would I need to scale each individual plant and not use a vertex buffer?
I like the DARK layout!
Quote:How exactly do I use that?

check the spec www.opengl.org, u also need to enable multisample + enable antialaising
im doing vegetation as well (more than 100,000 pieces onscreen at once when is needless to say impossible to sort)
also... humus.ca has some source for reference
id recommend alpha tested grass polygons if you grass isn t too high, otherwise it use the radix sort
http://www.8ung.at/basiror/theironcross.html
I added the multisampling approach as a "high" graphics setting, since on my machine it cuts the framerate in half (GeForceFX 5700), and I left an option to use plain old alpha testing. To solve the problem of "fading" in the plants as the camera approaches them I wrote a vertex shader to scale the plants. The shader requires that the normals be aimed away from the "origin" of the plants, since it uses the normal to figure out how to move the vertices around. Kind of hacky but it seems to work pretty well.
I like the DARK layout!

This topic is closed to new replies.

Advertisement