Procedural Grass Geometry Shader [GLSL 4.0 v.3 && GLSL 1.5 v.2] AMD fully supported!

Yarbrough, could you please make an example of cartoony grass shader too ^^?

You are a genius!!! ItĀ“s running with 1% on the rasterizer for me! So amazing. I will for sure use this in my project.

Trampling grass and bendy grass I thought were very similar- since forces are not simulated in Blender GE (i.e. like with the emitters) I always thought wind could be simulated (as with pushing grass) with trampling. A gust of wind would be like having a moveable block move through the meadow.

But keep at it, this is really something!

A stylized version could be useful; Iā€™ll add it to my list, but I want to finish this one first.

By trampling I meant something like this:

Staying down after an object has moved through it for a certain time.

I can move the grass near the camera since the cameras position is already known in the shader. If the verts at the top of the grass object are within a certain distance of the camera, move them away til the camera is a certain distance from the base.

For a wind object, I would need the position of the emitter and direction of the wind effect. Each emitter would need to feed that information into the shader, and go through sine wave calculations that are added to the wind field calcs. It would have to be a set amount, as dynamic loops are quite expensive. It is possible (I was not trying to say otherwise), but it would be hard to implement in a cheap and efficient way. Eventually I want to redo my wind function (to provide more control over the wind), when I start on that Iā€™ll look more into the feasibility of it.

1 Like

Here is a screenshot maybe it helps you.


Those spots are in all sizes and forms, think this is the biggest one, even small black triangle shaped on it.

#edit


Those are from the mesh that the grass is generated from, if you turn the render of the groundRender mesh off, you will see it better. It will appear if there are any problems with the shader. In the updated blend, can you uncomment line 560?

print("".join(chr(infoLog[i]) for i in range(length[0])))

This allows errors from the geometry shader to print to the console. I have to leave it off for intel machines, it tends to crash for some reason if it is left onā€¦

Both things do nothing

you did triangulate the stuff that needs to be for amd?

Yes, everything is triangulatedā€¦

http://rastergrid.com/blog/2010/10/gpu-based-dynamic-geometry-lod/

this looks important, and is designed by amd I gather?

For wind you could use a channel of the texture. Set direction by intensity, by mapping the 255 color values to a 360 degree circle.
That way you could have multiple winds blowing, or shadow areas where wind doesnā€™t blow, or simulate gusts of windā€¦

I think one thing that would be nice if it could be add, would be that the grass could use mist and ambient color like the lightsystem for the light.

I created a ā€˜Liteā€™ version that is compatible with GLSL versions 1.5 and later. I also want to use this version to start debugging problems for AMD systems. It also (for now) does not include a lighting model, I will add one back after I solve the problems for AMD.

ProceduralGrassShaderLite_v150.blend

It does not include instancing. I need access to the different instances to alter them, otherwise they wind up identical to the original. gl_InvocationID tracks the different instances, unfortunately it requires GLSL 4.0. Not having multiple instances means a couple different things. To start with, less grass objects per face means that the ground mesh needs to be higher resolution. It also means that there is less randomization in the coloring of the grass. Additionally it means less randomization in the positioning, there are a couple areas in the scene where patterns can now be seen. Finally, it also means that there is less control over different grass objects. For Example; in the full version, the tall grass appears only once per-face (randomized) in only one of the instances. That same grass appears a lot more often, especially with denser mesh. However, hopefully those that do not have access to GLSL 4.0 can benefit from it. I am also hoping to solve the issues for AMD by tweaking this version.

LITE == 60FPS, no dropping.
Full == 30FPS, sometimes 35 FPS.

I created a ā€˜Liteā€™ version that is compatible with GLSL versions 1.5 and later. I also want to use this version to start debugging problems for AMD systems. It also (for now) does not include a lighting model, I will add one back after I solve the problems for AMD.

it works, its showing grass and it moves, i like it. (light version, amd)

Hello, thank you for this really good shader, your two example work great on my computer with a nvidia 740m, 60fps with the two, but your example arenā€™t really demanding compared to a real game scene with heavy active character and others objects.

The quick setting of the distance of the lod in the lite version is very useful if you have a too many polygons.
Also, in my game I set the wind strength in two x and y axis instead of just a strength and I wanted to know if I can set two x and y strength in the shader ?

I will probably wait for a version that allow spot and sun light if you make one and if I use it because itā€™s what I mostly use in my scene (2 suns and 6 spotlight).

Well, even if I finally donā€™t use it for my project good work and thank you again.

The LOD system is something I want to expand on. Right now there is no ā€˜finalā€™ LOD level, but I want to tweak some more of the performance before I worry about that. (there is plenty of room for optimization)

Also, in my game I set the wind strength in two x and y axis instead of just a strength and I wanted to know if I can set two x and y strength in the shader ?

Not right now, the wind direction is constantly changing. As I noted in a previous post, I want to rework the function that generates wind to have more control over it.

I will probably wait for a version that allow spot and sun light if you make one and if I use it because itā€™s what I mostly use in my scene (2 suns and 6 spotlight).

The full version already includes support for sun lamps (up to all 8). I have left the lighting model out of the ā€˜Liteā€™ version while I debug the problems AMD systems have been having.

EDIT: Actually, here are some teasers of spotlights:



Congratulation the grass and wind look great.It finally works for amd.I get a framerate of 30.

Yarbrough08 does a great job with debugging.

Here is a screen of a fully working lite version on AMD:



(this version is for debugging purpose only (you canā€™t download this full lite version yet))

Oh, you are one of the people working on it with him.

Yes, he has been aiding me in debugging and has been a huge help considering I only have access to NVidia hardware.

Here is the new ā€˜Liteā€™ version with the lighting model added back in (as well as a couple performance tweaks). As can be seen above it is working on AMD system too.

ProceduralGrassShaderLite_v2.blend

I have hopefully spotted the issue with AMD on the ā€˜Fullā€™ version, might see an update to that one within a day or soā€¦