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

I still get a framerate of 30.

Yes i help him degug the shader for AMD

i still get 30 fps

This is due to your hardware, but 30 fps with and without the lighting in it is not a bad thing.

Also if you think you get some option right other things go wrong, the final version needs a lot of work, and i have a feeling that this shader can run way faster, but what do i know.

Here is the latest debug info, as you can see, i get 600 fps, but its doing crazy stuff and it’s only working half way.
http://youtu.be/BgAOjDDMnro but it looks verry promising.

Amd users can make a lil smile, it will come for you guys :slight_smile:
for now take the blend from post #40.

Update:

I have updated the ‘Full’ version to support AMD systems. I want to also note that the previous ‘Full’ update did not link properly due to an error with Google Drive. Because of this, there will probably be a pretty good performance increase for most.

There are several changes over the version that Google Drive was linked to, all of which can be seen in the readme. I am sorry for the inconvenience that it might have caused some of you, but for some reason blenderartists will not take the file (even though it meets the requirements). I reported the post and asked why, but I have not heard back. Until I do, I will keep linking to the Google Drive files.

With this new version, and ‘use frame rate’ off, I get about 85 fps on a NVidia GT 640 (with 6 lights - 2 sun, 4 point).

ProceduralGrassShader_v3.blend

I put blueprintrandom new car in your procedural grass blend
http://www.pasteall.org/blend/36069

I enlarge the ground plane.That made the grass only in the center.I am having the same problem.So i used pasteall.org.

I get an error with your new procedural grass blend. That is probably why the grass is not moving.

File "ProceduralGeometry.py", line 586, in <module>
NameError: name 'Radius1' is not defined
Python script error - object 'GroundGrass', controller 'Python':
Traceback (most recent call last):

The reason why the grass is only in the center, is because you have scaled up the ground render mesh, but not the ground grass mesh. You have kept the grass the same size and only scaled the ground render up by *4.717304. The ground and the grass are 2 different meshes as noted in my original post.

If you are getting a Radius1 is not defined error (I thought that this error had disappeared with the new version), you can try adding this into ProceduralGeometry.py above “if ‘init’ not in own”:

if 'Radius1' not in own:
 Radius1 = [0.0,0.0,0.0,0.0]
 Radius2 = [0.0,0.0,0.0,0.0]
 Type1 = [3,3,3,3]   # 0 = Spot, 1 = Sun/Directional, 2 = Point, so 3 = no light
 Type2 = [3,3,3,3]   # 0 = Spot, 1 = Sun/Directional, 2 = Point, so 3 = no light
 getLightingInfo()

EDIT: Make sure you apply scale if the grass is too large for what you are wanting; and if you copy the code make sure you convert the whitespace.

That fixed the error.I replaced if init not in own": with if ‘Radius1’ not in own: and i did not get the error.

Do you have deactivated the wind in v3 (maybe for optimizing) or is that a mistake because when I test it the grass have no wind motion but in the other versions it have?

Well I’m not sure why that error is being thrown, the variable is definitely being defined (and nothing calls it before it is defined). Running a check every logic tick should not be needed to update the falloff radius for only point lights (and is wastful IMHO).

However, if you make the variables ‘Radius1’ and ‘Radius2’ global it removes the error, and you only need to call ‘getLightingInfo()’ when you expect it to change.

EDIT: I will include this change in the next update. On my system this is just a warning, the lights still display properly. Is it a 100% problem for other systems, or is it just a warning there to?

EDIT:
Here is the changed code for those that might need it: LINK

Wow… v.3 optimizations puts up framerate to 45:)

I thought so aswell, i downloaded the v3, and indeed the error is there.
probally removing all comment marks is not a good thing (i tried one by one).

To fix the error: just go to line 586 and 587 and place a # in front.

Do not do this.

Lines 586 and 587 feed the falloff distance of point lights into the shader. (Radius1, Radius2 = spherical distance from light)
If you comment those lines out, the graphics card will generate 0.0’s for every point light.

The equation I use to calculate point lighting is:
Attenuation = 1.0 / (Distance2Light / Radius + 1.0)[SUP]2

[/SUP]Attenuation is multiplied by the lighting. This means that no light will be emitted from point lights. (cannot divide by 0)

The error should only be a warning. If it is causing an issue on your hardware I have posted a fix above for it until I update the blend.

Could you add some animated clouds to the skybox that move?

The skybox is not really the point of this blend, I’ve only included it to beautify the scene. The skybox code comes from martinsh, I’ve only cut out some of the unused parts. Clouds and a night sky are something I want to look into, but I would like to talk to martinsh about it before I just take over his code. However, it will probably not be released with this grass shader…

Would it be possible to change the invocations value by an object property?
I try to do it with uniform insteat of “const float invo = 6;” and in this case it works but I don’t know how to handle this line

layout(triangles, invocations = 6) in;

Can you help me, please?

By the way, I played around with videotexture and figure out how to place or delete grass in realtime by changing the stencil map, this can also be use to change the ground textures, maybe this is usefull for some people(?) I can upload a demo file in the next days…

Maybe it could be used to make snow.I was thinking snow would be nice with grass in the blend.Maybe some slider to add snow to the ground.

Unfortunately, no… The number of invocations needs to be a compile-time constant. I am looking into making a version that can increase and decrease dynamically though (along with a few other things like number of lights). The updated version will provide access to changes in a settings menu (such as the # of invocations and lights). This version will change between different shader code by calling delSource(), changing the code, and resetting the shader.

I try to do it with uniform insteat of “const float invo = 6;” and in this case it works but I don’t know how to handle this line

layout(triangles, invocations = 6) in;

Can you help me, please?

Both of those lines need to match.


invocations = 6    //integer - compile-time constant (doesn't change)
invo = 6.0    //floating point number - value needs to match invocations

//invo scales the randomizations 
//For example:    (Current_Invocation / invo) <= 1.0
//Without the scaling, randomization becomes
//chaotic as the invocation number increases.

By the way, I played around with videotexture and figure out how to place or delete grass in realtime by changing the stencil map, this can also be use to change the ground textures, maybe this is usefull for some people(?) I can upload a demo file in the next days…

You can also do this in code as well; since a timer is already imported into the shader, you can add a sine wave to the stencil map. Although, an animated texture would probably provide more control over the transformations.


Dynamic procedural snow would be nice; however, since I’m not rendering the ground though this shader it would prove difficult to implement. I might look into snow in a separate shader, and then adapt a version of the procedural grass for that. However, I cannot not promise anything - it might take me a while to get around to it…

You can also do this in code as well; since a timer is already imported into the shader, you can add a sine wave to the stencil map. Although, an animated texture would probably provide more control over the transformations.

Yes I could if I would know how it works, but at the moment I don’t know how to do it and videotexture works for me and I can use the mouse or an object to paint/delete grass or textures on the ground.

Furthermore I try to change the grass textures via videotexture but It only works when the texture is changed before the shader is running.

Anyway I’m sorry that I ask something once again because I know it takes time and work, but would it possible to make to use more complexe objects in this shader or alternative integrate the lightsystem in the GLSL Grass Geomitry Shader in the future thats could be usefull for bushes or modeled plants which have more than a simple plane with Alpha texture.

The shader is not currently set to update the texture every logic tick. To make it update, remove one tab level in front of every instance of shader.setSampler() at the bottom of the code. It should line up with the shader.setUniform4f() directly beneath it. Make sure you convert whitespace after and it should update with no problems.

Anyway I’m sorry that I ask something once again because I know it takes time and work, but would it possible to make to use more complexe objects in this shader or alternative integrate the lightsystem in the GLSL Grass Geomitry Shader in the future thats could be usefull for bushes or modeled plants which have more than a simple plane with Alpha texture.

I am investigating being able to use more complex objects in a geo shader; however, I keep reaching the conclusion that the only practical way to send a pre-modeled object into the shader would be with a vbo (which Blender does not let us use in the game engine). I will add the lighting model to the GLSL Grass Geo Shader, but I am currently making changes to the lighting model to add more flexibility (i.e. per-object, per-vertexGroup, per-vertex, per-fragment - also spot lights).

I hate to say this, but it looks like your shader doesn’t work on my system, which is strange.

The Blender console gives this output when I run either .blend file:

---- Fragment Shader Error ----
0:91(18): error: `C' undeclared
0:91(20): error: `B' undeclared
0:91(18): error: operands to arithmetic operators must be numeric
0:91(14): error: operands to arithmetic operators must be numeric
0:91(11): error: operands to arithmetic operators must be numeric
0:91(11): error: operands to arithmetic operators must be numeric
0:91(38): error: `B' undeclared
0:91(34): error: operands to arithmetic operators must be numeric
0:91(31): error: operands to arithmetic operators must be numeric
0:91(31): error: operands to arithmetic operators must be numeric
0:91(10): error: operands to arithmetic operators must be numeric
0:91(9): error: operands to arithmetic operators must be numeric
0:91(2): error: `return' with wrong type error, in function `Uncharted2Tonemap' returning vec3

---- Fragment shader failed to compile ----
* Found GLSL 1.30 graphic card and driver support.                              * This shader need at least GLSL 1.5

I find this especially strange because I do have a device that supports GLSL 1.5, in fact version 3.0 according to my system info.
If anyone can help, that would be much appreciated.