Sign in to follow this  
lancekt

GeForce6 grass and alpha testing

Recommended Posts

lancekt    348
Here's a demo of a technique for rendering grass that I'm giving a talk about at SIGGRAPH this summer. (Here, third item.) It requires a GeForce6 with reasonably recent drivers. ZIP file What's cool about it is that the whole scene in the demo is a single batch (one big triangle strip), the geometry of which is generated (almost completely) on the graphics hardware. (It'll produce a new distribution each time you run the program--but the distribution algorithm is also implemented in hardware.) Anyway, I do have a question here. :) I'm using an ugly hack for transparency at the moment--black backgrounds on the source images and discarding fragments below a threshold color. Does anyone have any advice for doing good-looking alpha testing? (Blending wouldn't really be practical here.) Also, I'd appreciate any general advice about making the grass itself look nicer without hammering the framerate too much more. Right now it's just textured with no attempt at simulating lighting or shading. Thanks. :) Screenie for the GF6-challenged:

Share this post


Link to post
Share on other sites
skow    248
A video would really help those of use without a geforce 6xxx, if you can't host one i would be happy to host it for you.

As far as a better looking alpha test, i've not been able to achive a good enough effect. Using a sort + blend yeilds the nicer looking result than any alpha test will. Seeing how it is one batch I would assume sorting is out of the question?

Share this post


Link to post
Share on other sites
MickeyMouse    201
I'm a lucky owner of GeForce 6 :-)

Looks good, but what I'm missing a lot in your demo is lighting. I believe that even the simplest per-vertex light would make it much more realistic. The second thing that would help would be shadows. I think some less intensive green color for the grass would be good too if you want it more realistic.

Have you thought about animating your grass using vertex shaders?

Share this post


Link to post
Share on other sites
toucel    188

I would have responded a whole lot earlier, but ah... gamedev seemed... a little down ;)

Wow, first off thank you for sharing this - it has inspired me a quite a bit

I decided to play with your shaders a bit and figure out how it works

I think I have come up with a way to make the end image a bit nicer without adding much time at all,

essentially it simulates lighting conditions by approximating the surface normal of the grass (or leaf, etc) - for testing purposes lets say this is (0,0,1)

note that this will not take into effect the arching of the geometry or the notion that there are two sides to the geometry with opposing normals - this, if we play with the numbers enough, shouldnt affect the outcome too much; at least not in a really negative way

now you rotate each of these "blades" by a random amount - I propose that we rotate this approximate surface normal by the same amount and use this to, in turn, do basic normal based lighting

this will at the very least bring in some needed contrast to the image

I have put this in place and it seems to work pretty well

Free Image Hosting at www.ImageShack.us

Free Image Hosting at www.ImageShack.us

I would also suggest, though I would guess that it is a bit beyond your intentions, that you could animate the blades by doing a few things...

you could apply a sin based "wind" model to the upper vertices of the geometry (this would be easily checked via the texcoords) further, you could vary the amount of influence by both noise and type of "blade"

I was thinking that setting the transparency threshold to a lower value would help to define the edge of the different "blades" but I think it makes it look too messy, especially with aliasing artifacts - this looks better (still using the ideas above)

Free Image Hosting at www.ImageShack.us

anyway, If you have any questions for me feel more than free to ask; If anything is unclear here, I can provide the changes (trivial, really) - I look forward to hearing your reply

By the way, I too am unsure about the leaves...

Share this post


Link to post
Share on other sites
lancekt    348
toucel, you are right, that does look quite a bit better, thanks. (And yeah, the leaves are really just there to add some color for the demo. Probably not something I'd do if actually using this for something serious.)

I have thought about animating the grass, although it seems to hammer the vertex shader hardware pretty hard as is. I will definitely experiment with animation at some point though.

I will have a video eventually--I'll get back to work on this in a week or so once I'm settled into my new job.

Thanks for the input everyone!

Share this post


Link to post
Share on other sites
pathogen    140
I have been inspired; I decided to make up my own implementation

here are the results:

Free Image Hosting at www.ImageShack.us
Free Image Hosting at www.ImageShack.us
Free Image Hosting at www.ImageShack.us
Free Image Hosting at www.ImageShack.us
Image Hosted by ImageShack.us

Everything is animated too thru the vertex shader and trig based "wind"

Share this post


Link to post
Share on other sites
superpig    1825
Perhaps it would help to do a couple of image-space postprocessing passes? First run an edge detection filter to pick out the edges, then feed that to a blur filter, such that you blur the edges of the geometry but leave the interiors untouched. Might improve quality a little, I'm not sure.

Share this post


Link to post
Share on other sites
duhroach    225
It's interesting you should present this.

Just 2 weeks ago i developed a similar system for our world based grass. We ended up giving the artists a little more control by providing them with a control .tga that allows them to set the type, height, grow-in phase, and an alpha mask for the generation of grass blades. On top of that, we threw in some vertex heavy processing to allow the blades move / get trampled when units are walking through the meadow.

Also, how does your system perform at large levels? Can it work in a field / forest? I'd be egar to see the performance differences

~Main

Share this post


Link to post
Share on other sites
lancekt    348
Quote:
Also, how does your system perform at large levels? Can it work in a field / forest? I'd be egar to see the performance differences


I haven't tried this yet (been really busy). But from the kind of performance I'm getting now, I suspect it will work acceptably in a relatively small area around the viewer, perhaps with some LOD scheme for further off.


pathogen, that looks great, you should definitely post your version. Your textures are way better than mine!


Quote:
Perhaps it would help to do a couple of image-space postprocessing passes? First run an edge detection filter to pick out the edges, then feed that to a blur filter, such that you blur the edges of the geometry but leave the interiors untouched. Might improve quality a little, I'm not sure.


That's an interesting idea, I'll look into it.

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