Sign in to follow this  
BradDaBug

Rendering vegetation

Recommended Posts

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

Share this post


Link to post
Share on other sites
zedzeek    528
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)

Share this post


Link to post
Share on other sites
Zemedelec    229
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...

Share this post


Link to post
Share on other sites
bluntman    255
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.

Share this post


Link to post
Share on other sites
BradDaBug    913
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?

Share this post


Link to post
Share on other sites
zedzeek    528
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)

Share this post


Link to post
Share on other sites
BradDaBug    913
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.

Share this post


Link to post
Share on other sites
bluntman    255
Yeah just use a vertex shader and for each vertex have an attribute which is its target position. Then your shader measures the distance, calculates a scaling factor (smoothstep or equivalent) scale and draw. Pass the vertex shader 2 uniform values for minimum and maximum scaling distance to make it easily tweakable.
I was playing bf2 last night and scaling is definitly what it uses for grass, but I think it handles shrubs differently, with imposters and fading.
Anyone know how FarCry handles vegetation (seeing as its the daddy of veggie environments)?

Share this post


Link to post
Share on other sites
Zemedelec    229
Quote:
Original post by bluntman
Anyone know how FarCry handles vegetation (seeing as its the daddy of veggie environments)?


Generally - all the basic stuff - sorting the grass, trees -> sprites, batching low-polys, patches to billboards, etc.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this