How to approach Grass and large vegetation

Posted By: jumpman

How to approach Grass and large vegetation - 05/28/18 18:19

Hello friends

I was wondering which technique you would choose when it comes to rendering large fields of tall grass. Here are a list of choices I think I have, let me know what you all think:

1. Fur Shader: The shader in the wiki uses the shell method, rendering shells/triangles multiple times with offsets based off the normal, and a transparency causing a nice fuzzy fade. This method looks great, especially when looking at the surface straight on. But looking at the side of the shells will show the slices. If I wanted taller grass, I would need to add more shells/more passes.

2. Model billboards: This method can easily make tall grass if you have a good standing image of grass, you could add sway and animation, as well as pushing it out of the way when an object touches the model. The downside is that you have to manually place these tufts of grass in the level, and each tuft would require a while(). Im assuming I could also have a single while() iterate through each tuft, but once again, these are seperate objects each, which take resources. Model instancing wont be added :(, as well as the illusion breaking down if you look down at the model, which would show the cross section.

3. Sprites: Sprite instancing is possible in the current A8, but that means the grass will be facing the camera, they wont have any shading/lighting, and sprites arent really meant to stay in the world for long, how would I manage a large field of sprites? An emitter that can place sprites in an area with an infinite life?

Let me know if you all have experience with grass, and what methods you use that worked for you, and why.

Thank you!
Posted By: Superku

Re: How to approach Grass and large vegetation - 05/28/18 19:17

Sprites are normal entities and don't have a limited/ finite life (when placed with WED or just via ent_create). Might wanna have a look at the following feature as well:
Quote:
A8 If the sprite's file name ends with "_x2" or "_x3", it is rendered in the shape of 2 resp. 3 crossed planes. This is very useful for simulating vegetation. You can find an example in the infinite_terrain.c demo.


I'd probably spawn randomly scaled and oriented grass models all over the place, adjust them a little (in-engine) manually. Then have a script combine them into just one mesh or multiple meshes, depending on the vertex count or the size of the area. Another function would then write all vertices and triangles into a text (obj) file, following the very simple *.obj format, and import it into MED again.

You don't need any while loops for interaction really, just put additional code into the vertex shader which does some distortion based on character positions.
Posted By: Emre

Re: How to approach Grass and large vegetation - 05/28/18 19:22

Hi jumpman.

Fur shader is waste of time and waste of gpu power. You can forget about it. Since i'm still using A7, i can't say aything about sprite instancing.

I am using model. I don't need vertex animation and while operation. I can animate foliages&grasses with shader. it's simple. About the "pushing it out of the way when an object touches the model.": I never try that but i think you can do it with event and shader like this: (not grasses but weeds and bushes)

Code:
//Lite-c
if(event_type==EVENT_FRICTION)
my.skill41=floatv(1)
...
//shader
if(vecSkill41.x==1)
do animation


But i don't think it's necessary. Players may not pay attention to them, especially in the action games.

in a nutshell I prefer the model. Here is what and how i'm doing.

Edit:I did not see the post of superku when I wrote this. I also agree with him.

Edit2:if there is a misunderstanding, i was talking about specific object when i point to vecskill41.
Posted By: rayp

Re: How to approach Grass and large vegetation - 05/29/18 12:41

If u are using sprites ( or models ) a seed map might become handy. Check out for
Code:
ent_seed

in Manual ( include level.c ).

To keep Performance also check out the CLIP's and DYNAMIC flags
Code:
action place_grass()
{
  vec_scale(my.scale_x,0.75+random(0.5));
  my.flags |= PASSABLE | TRANSLUCENT;
  my.alpha = 70;
  my.eflags |= CLIP1; 
  wait(1);
  my.emask &= ~DYNAMIC;
}



Maybe you know those nice functions already.


Greets
Posted By: Dooley

Re: How to approach Grass and large vegetation - 05/30/18 04:11

Search for "serious vegetation" on the AUM site:
http://www.coniserver.net/coni_users/web_users/pirvu/aum/aumonline_e/
Posted By: jumpman

Re: How to approach Grass and large vegetation - 06/01/18 17:04

Thank you for your advice my friends!

@Superku

I know how to pass a vector postion to a shader, however wouldnt the grass tuft need a while() to send the vector position to the shader? Or use a startup and iterate through each tuft's skill for each of their shader, assuming each tuft is meant to have its dynamic flag off.

@RayP thank you, Ive never looked at this code at all, this is great!

Ill send some examples of my chosen method in the projects forum. Thank you all friends!
Posted By: Superku

Re: How to approach Grass and large vegetation - 06/01/18 18:56

No, don't send via (entity) vecSkill41+ but as a material skill (vecSkill1) or just as a global variable/ VECTOR (look up the *_var feature, I think to be found under *_flt or similar).
Posted By: jumpman

Re: How to approach Grass and large vegetation - 06/01/18 22:19

WOW superku, I didnt know you could pass a global vector into a shader!!! Im a dummy, which makes sense why you can change PSSM_ variables and have it change the shader. Thank you!
© 2024 lite-C Forums