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


(CYNIC78) #121

Sorry guys. It worked well on my AMD card. I just had to update drivers. Beautifull grass in this scene i have 60 fps.


(farhani) #122

Shader works perfectly. Is there a way to randomize the rotation of the grass? I used this shader to create trees and it looks good.


(haidme) #123

Is there a way to make fog/mist to work with this shader?
I really want to use it in my new game, but not working with fog is a deal breaker.


(HG1) #124

If you want fog on the grass (material) you need to add the fog shading into the fragment shader.
Add the code at Line 456 (ProceduralGrassShaderLite_v2 UPBGE.blend)


    //linear fog
    float fog = clamp(Dist/30.0, 0.0, 1.0);
    color.rgb = mix(color.rgb, vec3(1.0 ,1.0, 1.0), fog); //vec3 is the RGB color of the fog

If screen space fog suits your needs you can use a 2D filter.


uniform sampler2D bgl_DepthTexture;
uniform sampler2D bgl_RenderedTexture;
uniform float near;
uniform float far;
uniform float R;
uniform float G;
uniform float B;

vec2 texCoord = vec2(gl_TexCoord[0]).st;

vec4 fogcolor = vec4(R, G, B, 1.0);

void main(void)
{
    vec4 fog =(2.0 * near) / (far + near - texture2D(bgl_DepthTexture,texCoord) * (far - near));
    
    gl_FragColor.rgb = mix(texture2D(bgl_RenderedTexture,texCoord),fogcolor, fog).rgb;
    gl_FragColor.a = 1.0;
}

Mist_Shader.blend (60.7 KB)


(haidme) #125

Thank you HG1, both methods works great!


(haidme) #126

Hi HG1,
Can you expose more options for the LOD. I want to be able to control the far distance of the grass(I want to end it at certain distance) :o
also is it possible to add more grass textures? :slight_smile:

Here is my progress with the grass. I need a little bit more control over the LOD.


(haidme) #127

I have a strange problem. When I have multiple materials with multiple textures in the blend.
The grass generates but with no textures and the console says:
inavlid uniform value Texture1
inavlid uniform value Texture2
inavlid uniform value Texture3
When I decrease the number of textures and materials in the blend, the grass loads it’s textures with no problem.
Also when I libload most of the objects with materials in runtime it also works.
I’m asuming the grass shader needs to initialize and generate first, before runtime loads the materials. That’s why libload works.
Is there a solution for this?


(BluePrintRandom) #128

sounds like it’s using the load order to get a material index instead of a pointer or something or maybe it’s a naming conflct?


(haidme) #129

I guess it’s connected to materials loading somehow. Also I’m sure that on better PC config, there will be no problems. It’s somehow connected to how fast the blend loads runtime. But it is a dealbreaker. The only workaround is to load the entire level with libload after the grass shader is up and running.