Realistic tree/grass weaving shader

Posted By: IDontLikeSoccer

Realistic tree/grass weaving shader - 05/26/20 20:07

Does anyone know how to make moving grass and trees more realistic? I use animTree.fx from GS folder, but it looks more like a shader for underwater plants for moving plants in water than as for grass/tree shader which should simulate wind blowing. Did is possible put some wind effect in this shader?
Posted By: 3run

Re: Realistic tree/grass weaving shader - 05/26/20 20:19

Hey!

I'm afraid it's the only vegetation shader out there (as far as I know)... Maybe tweaking it might help?
Other than that, I remember in AUM (can't remember the number) there was an example of how to animate bushes and grass via bones.
It's not the fastest solution (since bones + their rotation for lots of grass can be slow), but it might be useful too.

Greets!

Edit: I was able to find the grass from AUM, take a look here:
AUM 76 -> Hot at the forum -> Plant effect by Mocosgames
Posted By: IDontLikeSoccer

Re: Realistic tree/grass weaving shader - 05/26/20 20:47

Hey!

I'm afraid any other solution than shaders is too slow.

I try tweaking this shader but the big problem is random() function did not work in shader fx file. I do not know how I can make some more random movements of grass.
Posted By: 3run

Re: Realistic tree/grass weaving shader - 05/26/20 20:54

What exactly you mean by 'random movements of grass', maybe I could help with that. Please, explain a little bit more in detail.
As for the vegetation shader, as far as I understood, it simply 'waves' the upper vertexes of the model in a given X, Y direction with a given speed and that's all it can do.
Posted By: IDontLikeSoccer

Re: Realistic tree/grass weaving shader - 05/26/20 21:34

This A8 game is great example, I found it on 3dgs page:

https://www.youtube.com/watch?v=_u-Av18XJ-c&t=2s

The animTree shader currently has a constant weaving rhythm. The rhythm is the same all the time.
Posted By: 3run

Re: Realistic tree/grass weaving shader - 05/26/20 23:41

This is what I came up with after playing with animTree for a while.
I was able to get proper wind direction for the grass, but it's not yet perfect.
http://www.filedropper.com/grass_1

Greets!
Posted By: IDontLikeSoccer

Re: Realistic tree/grass weaving shader - 05/27/20 10:28

Wow thanks! It looks fantastic, almost like in the video. Now I will try how it works on trees.
Posted By: 3run

Re: Realistic tree/grass weaving shader - 05/27/20 10:47

Glad that you liked it laugh
For trees I think it won't look that great, cause (as I think) for trees it's more important to move leaves on the wind, not the whole mesh.
Posted By: IDontLikeSoccer

Re: Realistic tree/grass weaving shader - 05/27/20 11:25

Yes for tress maybe we need use separate model of tree and leaves.

The only problem too many grass with while loop function killing fps in game frown. It is not clear to me how the people who made the game above solved that problem.
Posted By: 3run

Re: Realistic tree/grass weaving shader - 05/27/20 11:34

Originally Posted by IDontLikeSoccer
The only problem too many grass with while loop function killing fps in game frown
You mean while loop for each grass? It can be solved easily, just use ENABLE_FRAME and event with EVENT_FRAME.
Code
void grass_event_function()
{
	if(event_type == EVENT_FRAME)
	{
		my->skill41 = floatv(wind_x + my->skill1);
		my->skill41 = my->skill41 - 0.1 * sinv(16 * total_ticks);
		
		my->skill42 = floatv(wind_y + my->skill2);
		my->skill42 = my->skill42 - 0.1 * sinv(16 * total_ticks);
		
		my->skill43 = floatv(wind_force);
		my->skill43 = my->skill43 - 0.1 * sinv(16 * total_ticks);
		
		my->skill44 = floatv(wind_amplitude);
		my->skill44 = my->skill44 - 0.1 * sinv(16 * total_ticks);
	}
}

action fx_animTree()
{
	set(my, PASSABLE);
	my->material = mtl_animTree;
	
	// randomness for each grass
	my->skill1 = 1 + random(2);
	my->skill2 = 1 + random(2);
	
	my->emask |= ENABLE_FRAME;
	my->event = grass_event_function;
}
As for the trees, yes. It needs some solutions. Maybe we could find some shaders from unity or other engines and try to convert them.

Edit: f.e. this one
[Shader - Open Source] Polygon Wind - for Low Poly Tree Assets


Edit2: I tried to convert it, but failed... due to not being able to get vertex color (without that it looks like default animTree.fx), I tried float4 inColor : COLOR0, but that didn't work.
Posted By: IDontLikeSoccer

Re: Realistic tree/grass weaving shader - 05/27/20 13:06

The same thing to me, looks identical to the default animTree.
I wach video again and I’m sure Supercan uses a separate model of leaves and trees, and one global function for dynamic random wind blowing, to get that effect. That game looks really professional, dynamic tress shadows looks nice, i thought shade-c doesn't support this, maybe EVO?

EVENT_FRAME solved the problem with fpssmile
Posted By: 3run

Re: Realistic tree/grass weaving shader - 05/27/20 13:25

ShadeC EVO has memory leaks and I wouldn't recommend using it. As far as I know, it doesn't have vegetation shaders. As I'm new to shaders in general, I can't migrate unity shader to the acknex, maybe txesmi might help, as he is a shader guru smile

Glad to hear that ENABLE_FRAME helped out. I would also recommend to not use while loops in general, but ENABLE_FRAME for cosmetics and on_frame for game mechanics.
Posted By: IDontLikeSoccer

Re: Realistic tree/grass weaving shader - 05/27/20 13:45

Thanks for advices 3run, today I learned a very useful thing about the ENABLE_FRAME. I use Shade-C 0.91 BETA S1, it is stable and I do not plan to switch to EVO just because of dynamic shadows, but I must admit that the effect of moving the shadows of the trees is something special in video above.
© 2024 lite-C Forums