This is an entirely procedural grass shader that generates grass from information passed from a ground mesh. It takes a stencil map to determine grass placement, and 3 grass textures to create various grass objects. It does not render the ground, I was unable to solve problems with the grass objects clipping through the ground. However, it is trivial to duplicate the ground mesh, and separating the materials is probably a good idea anyway.
The above video starts at dark and runs through the dawn transition to daytime.
The shader is setup to run 9 instances of the geo shader. That means that for every grass object created, 8 more will be created also (each instance is randomized - placement and rotation).
The grass moves in the wind using an almost identical function as in my previous shader; however, the strength of the wind has been exposed so that it can be easily changed.
I have added a lighting model, the lighting is done per grass object, not per-fragment or per-vertex. It supports up to 8 lights; directional or point, and you can mix and match them however you like. There is no limit (as I thought I was going to have) on directional lights. If you want all 8 lights to be directional, you can (and vice versa).
The info for the lighting comes straight from the lights. For directional lights; the color and strength can both be adjusted, and for point lights; the color, strength, and distance (radius) is adjustable.
There is a built-in multi-level LOD system. The initial LOD levels are two-tiered, the first level is at 24 meter by default. The second is at 2x the first, each instance changes this by a certain amount. Total (default) - there are 12 different LODs; 6 per tier, hopefully erasing any ‘lines’ showing grass poping in and out. (edited for v2)
I wrote a decent readme that contains much more info, including how to customize the shader. And I’ll echo here what I ended it with:
I am sure that there are a million things that I am forgetting. If you have any questions, feel free to send me a PM. Also, if anyone has a feature request that the community would find useful, feel free to ask. I am still working on this thing. For some reason, I just cant put it down…
There are plenty more things that I want to add to it || change about it:
- move lighting to the fragment shader
- add spotlights
- more user friendly
- version for GLSL 1.5
- auto-detect GLSL version
- a lot of tweaking
There are some requirements for this one:
GPU compatible with GLSL 4.0 (OpenGL 4.0)
Better GPU = Better performance
Less Lights = Better performance
Less Grass = Better performance
Smaller Grass Size = Better performance
Lights are a killer for performance, on my system disabling them yield 30+ fps increase.
- more grass, better performance
- fixed an issue with a grass height equation that was causing massive slowdowns
- switched all of the lighting info to the geometry shader - performance increase
- exposed the LOD distance float
- created a lighting factor property
- created a material intensity factor property
- other small tweaks
- same as v2
- more performance optimizations
- better user access to vars
- more detail in the readme
- AMD support
Full version - requires GLSL 4.0
Lite version for GLSL 1.5