Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Grass and what to do


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
23 replies to this topic

#1 riuthamus   Moderators   -  Reputation: 5628

Like
0Likes
Like

Posted 12 January 2013 - 10:15 AM

Let me begin by saying, i know that grass is not a majorly important thing since most of the players will simply pass by it without caring too much, but the concept is to make something that is appealing to the eye and non-resource intensive. Before you go saying "that is impossible" i would argue that by using art and optical illusions you can very much do this. The question is how does it translate into code or what are the best practices.

 

Many games today render grass as a flat plane with a simplified texture over it. This process is not bad but one must ask the question of how to add depth. More planes? Assuming you do figure out a proper method what type of lighting should be applied, how do shadows work?

 

I have seem some games that add an ambient shadow to the base, where as others do not care about shadows at all and simply ensure the grass matches the tone of the mesh it is attached with.

 

My overall question is, how would you, fellow coders, do your grass?



Sponsor:

#2 Waterlimon   Crossbones+   -  Reputation: 2601

Like
1Likes
Like

Posted 12 January 2013 - 10:50 AM

1) Many polygons

 

or

 

2) Crazy idea where you render the grass on a texture, apply a fancy directional blur-line-drawer shader to pull grass lines from the flat ground pixels and then render that with depth. Or something. :D


o3o


#3 quiSHADgho   Members   -  Reputation: 325

Like
1Likes
Like

Posted 12 January 2013 - 12:51 PM

When I started developing the terrain system of my engine I thought long about that and read some articles. In most of todays games or let me say yesterdays games because I dont own many that where released in the past 1-2 years I hate the grass. Often its looking very bad from above or its always rotating to face the camera. I ended up implenting some techniques.

Only one had sufficient quality but it would not win a ressource-saver-price. The basic idea was to render each blade of grass, divide into into slices to get the possibility to animate it and fill it with a gradient color in the shader. It was possible to scale the quality with the number of slices but since it required a lot of them to look good I decided to put the geometry into the object and not into the grass. There was a name for it but I cannot remember it...

Next technique was only a experiment i did out of interest. It was still rendering each blade of grass but this time without the slices. So I got 4 verts for each blade and did the animation in the pixelshader. Basically the gradient color shifted from left to right and back but it looked kinda disturbing and I wanted a technique capable of rendering different types of grass. So I'm going with the basic method of rendering 4 verts with a texture. I can put many textures in one and select the relevant one randomly when creating the vertexbuffer. The alpha channel of the texture contains a noise to control fading in the distance...Thats it and best part is it dont look like sheets of paper from above. There is still some optimization potential but I'm happy with it for now.

I also read about using Parallax Occlusion Mapping to get a grass effect but that would not be very performant either.



#4 web383   Members   -  Reputation: 788

Like
1Likes
Like

Posted 12 January 2013 - 01:03 PM

I would probably start by creating many textured quads, giving them a sway (via shear matrix), and then batching all of them on the CPU.  Then send them all to the GPU in a single (or minimal) render calls. 

 

The problem here will probably be depth sorting (since the grass textures will have alpha):  You could either turn off depth writes and just let the pixels clash together, or spend the time sorting them if you have enough CPU resources.  I'm sure there are papers on the subject if you want to get more advanced.

 

If you want the grass to cast shadows, you can still use standard shadow mapping.  During the shadow pass, draw the grass with alpha-testing enabled. 



#5 rocklobster   Members   -  Reputation: 415

Like
1Likes
Like

Posted 12 January 2013 - 03:45 PM

http://illogictree.com/upload/site/LeeRealtimeGrassThesis.pdf

 

This might help you. I think there is a youtube vid showing it off also.


Edited by rocklobster, 12 January 2013 - 03:46 PM.


#6 riuthamus   Moderators   -  Reputation: 5628

Like
0Likes
Like

Posted 13 January 2013 - 06:15 AM

that article is great, assuming you are a math genius and want a very complex system. Not sure we need that since our game is not that complex. Could be adapted at some point though. Thanks so far guys.



#7 irreversible   Crossbones+   -  Reputation: 1380

Like
1Likes
Like

Posted 13 January 2013 - 11:51 PM

What I did a long time ago was create a couple of tiling grass texture patches as side views (along the lines of this) and simply skew the top end to emulate really rudimentary wind. It's cheap, pretty angle sensitive and only works with well tuned skew parameters, but definitely passes as a 90s style game grass.



#8 Krohm   Crossbones+   -  Reputation: 3175

Like
1Likes
Like

Posted 14 January 2013 - 02:04 AM

Umh, the illogictree link is dead for me. I'll try again later.

In the meanwhile, consider Towards Photorealism in Virtual Botany.

It's my gold standard.

In the meanwhile my current target would be something like the XRay engine: stupid particles spawned on special planes.

 

In the past I also tried experimenting a bit with POM-based techniques: the performance was terrible and I'm inclined to think polygon-based techniques might actually be the best option for another couple of years.



#9 riuthamus   Moderators   -  Reputation: 5628

Like
0Likes
Like

Posted 14 January 2013 - 02:55 AM

I think the best solution for our engine, and for optimization is the flat plane option with a bit of curve. My question now is... how do we make the shadowing of it like you see in games such as Saints Row 3 and Firefall? It seems like its just a small texture of black that is applied below the upper mesh parts or it is some form of basic shadowing... not sure. I love all of the suggestions so far. Have been looking at them all and reading up. So much wealth of information



#10 Hodgman   Moderators   -  Reputation: 31112

Like
2Likes
Like

Posted 14 January 2013 - 05:32 AM

I worked on a project with digital (I hope he doesn't mind me giving away the technique) where he came up with a neat trick that I like to call "texture-space parallax".

 

Say you've got a 3D model of a bunch of grass blades (please excuse my mspaint art):

Wr1M3.png

 

If you tiled it in the world and rendered it, the camera rays would look something like below, but your triangle-count would be huge:

nF50c.png

 

So instead, in this technique you just pick the direction that the camera is looking in (or some other arbitrary choice of direction that looks good), and render a single "tile" of grass to a texture, using an orthographic projection in that direction.

e.g. when looking down/right, or down/left, your ortho renderings would look like this (colours on the line at the top are the resulting 2d "grass" texture from the 3d model):

4LPXn.png nnxQo.png

 

You then just use that 2D texture as usual on your ground, but as the camera rotates, the parallax effect of the grass blades changes.

 

This is incorrect, because as you can see, the rays in our ortho view are all parallel, where in the reference image above, the rays all diverge and cause different parallax in the foreground than in the background... but it's ridiculously cheap and worked well enough for us at the time.

 

When rendering the ortho view, we also rendered height data into the alpha channel, so that we had the option of doing extra effects later when using the texture, like parallax mapping, or outputting modified depth values so that the grass would seem to rise out of the ground and clip with player's feet, or modified lighting based on height, etc...

 

You've also got to take a lot of care when creating your 3D grass model so that the resulting 2D texture tiles correctly -- e.g. if a bit of grass is near the edge of the "tile", then you've got to duplicate it and move it over, just outside the opposite edge.

 

This isn't the best example, but here's a flat plane that's been textured with this technique -- http://i.imgur.com/6WEHC.png -- obviously only useful for quite short grass, not fields of wheat, etc wink.png


Edited by Hodgman, 14 January 2013 - 05:44 AM.


#11 riuthamus   Moderators   -  Reputation: 5628

Like
0Likes
Like

Posted 14 January 2013 - 05:41 AM

very interesting.... hm... so you are saying making a 3d model that is looked at via the viewport and then uses that model to project the 2d textures into the planes based off of the direction the player is? very generalized version of what you said... but... trying to understand it.



#12 CC Ricers   Members   -  Reputation: 649

Like
1Likes
Like

Posted 14 January 2013 - 01:50 PM

The simplest way I can think of is adapting a fur shader to draw grass. Here's a pretty intuitive tutorial (I think) on how to make one. A fur shader uses a texture of dots (or other small particles) and layers them in many slices to create the height of each blade or hair. All these slices can be drawn on the vertex shader and adjustable by height. A nice effect is that you can blend in another texture to make the patches of grass vary more by color, or tell the shader to tint the base color so as to make the blades apppear self-shadowed. To reduce uniformity and repetition, you may want to generate the textures procedurally, randomizing the particles for a given slice. Applying real-time deformations becomes just as easy if you want grass to move to simulated wind.


My development blog: Electronic Meteor

#13 tool_2046   Members   -  Reputation: 1096

Like
2Likes
Like

Posted 14 January 2013 - 09:18 PM

Let me begin by saying, i know that grass is not a majorly important thing since most of the players will simply pass by it without caring too much, but the concept is to make something that is appealing to the eye and non-resource intensive. Before you go saying "that is impossible" i would argue that by using art and optical illusions you can very much do this. The question is how does it translate into code or what are the best practices.

 

Many games today render grass as a flat plane with a simplified texture over it. This process is not bad but one must ask the question of how to add depth. More planes? Assuming you do figure out a proper method what type of lighting should be applied, how do shadows work?

 

I have seem some games that add an ambient shadow to the base, where as others do not care about shadows at all and simply ensure the grass matches the tone of the mesh it is attached with.

 

My overall question is, how would you, fellow coders, do your grass?

 

I've yet to see a better looking technique than Kevin Boulanger's implementation



#14 riuthamus   Moderators   -  Reputation: 5628

Like
0Likes
Like

Posted 14 January 2013 - 10:10 PM

tool_2046, that is a great link, will look into that further.

 

CC Ricers, another great link worth looking into. You have all been more than helpful.



#15 Hodgman   Moderators   -  Reputation: 31112

Like
1Likes
Like

Posted 14 January 2013 - 10:32 PM

very interesting.... hm... so you are saying making a 3d model that is looked at via the viewport and then uses that model to project the 2d textures into the planes based off of the direction the player is? very generalized version of what you said... but... trying to understand it.

You make a second camera/scene, which just has the 3D grass model in it, and a second camera that is 'ortho' instead of 'perspective'.

 

Before each frame, you rotate this 2nd ortho camera to point in the same direction that your regular camera is pointing (but you don't translate/move it), and you render the 3d-grass-scene to a texture. That gives you a new grass texture to be used this frame, where the grass appears to have the (approximately) correct parallax for your main camera's viewing angle. You then use this grass-texture on the ground as usual when drawing your real 3D scene with your real camera -- it's just a regular 2D texture at this point, like an artist would usually draw for you.

 

e.g. the ortho frustum for two different viewing-angles are below -- top left is the 'regular' camera in the scene, it's rotation is used to make the ortho frustum, the grass model is then rendered using that ortho frustum (bottom), and then the resulting image is used as a texture on the regular scene (top right).

Take your 3d camera, copy it's rotation, draw the grass scene using an ortho camera using that rotation, then draw the 3d scene using your new grass texture.

 

7mP0h.png


Edited by Hodgman, 14 January 2013 - 10:34 PM.


#16 riuthamus   Moderators   -  Reputation: 5628

Like
0Likes
Like

Posted 14 January 2013 - 10:35 PM

AH, this makes way more sense. Thank you for your help. I will speak with telanor shortly and see if we cant get something working.



#17 quiSHADgho   Members   -  Reputation: 325

Like
1Likes
Like

Posted 15 January 2013 - 06:16 PM

It is too bad that there are no recent papers or I just cannot find them. I think with todays hardware there is enough power to introduce a geometry based grass method in addition to a more "lower-end" technique for older systems. For me the question is, do you want some good looking grass or do you want some expensive effects like bokeh etc that are not worth it in my opinion. I dug out an early version from my engine where everything was unoptimized and reimplemented the geometry approach I mentioned in my last post.

While it's not perfect yet it improves the quality of the scenes alot although I'm satisfied with the look of my textured quads method I will optimize it bit more and leave as a feature for mid to high-end systems. And since you are working with DirectX11 you can use things like geometry shader and tesselation which should give you a decent performance boost.

 

The pic was made with mid density

screencap1.png



#18 riuthamus   Moderators   -  Reputation: 5628

Like
0Likes
Like

Posted 15 January 2013 - 07:02 PM

very interesting stuff, You have been more than helpful. Too bad you have your own project you are working on! :P



#19 riuthamus   Moderators   -  Reputation: 5628

Like
0Likes
Like

Posted 18 January 2013 - 08:37 PM

It is too bad that there are no recent papers or I just cannot find them. I think with todays hardware there is enough power to introduce a geometry based grass method in addition to a more "lower-end" technique for older systems. For me the question is, do you want some good looking grass or do you want some expensive effects like bokeh etc that are not worth it in my opinion. I dug out an early version from my engine where everything was unoptimized and reimplemented the geometry approach I mentioned in my last post.

While it's not perfect yet it improves the quality of the scenes alot although I'm satisfied with the look of my textured quads method I will optimize it bit more and leave as a feature for mid to high-end systems. And since you are working with DirectX11 you can use things like geometry shader and tesselation which should give you a decent performance boost.

 

The pic was made with mid density

attachicon.gifscreencap1.png

 

We do not need anything epic, in fact i dont mind going with a 5/6 polygon model of planes that are slightly bent. Like i said my goal is to make something like firefall. The major question is how to put a shadow under them ( doesnt need to reflect the texture just an ambient blur ) and how to render light on them. And if there are methods to render it better that would help as well. Your engine looks impressive.



#20 wodinoneeye   Members   -  Reputation: 861

Like
1Likes
Like

Posted 21 January 2013 - 09:01 AM

Dont forget some kind of LOD level of detail mechanism that cuts down an  then ends any high/med/low detailed grass at varying ranges  (instead of a monolithic grass everywhere rendering).    Even with many of the methods mentioned, there still is a significant cost to drawing,  and any time you DONT have to draw areas of grass frees up resources for other things (or really nice looking super-duper detailed grass at your feet)


--------------------------------------------Ratings are Opinion, not Fact




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS