Geometry Shaders?

I have recently been experimenting with a “grass” opengl vertex shader that allows the player to move smoothly though a patch of grass with the blades flowing around the player. The file seems promising but i’m not sure if its just a dead end because the fps drops significantly. I read about VBO’s and Geometry shaders. They seem to be key to opptimizing the blend. I’ve looked into other builds that have geometry shader support. Builds like Harmony, and moguri’s old gsoc build. I even found some patches some other BA users have made. I cant get a single one to work. If somone who has experience with this please help me with a most recent build of blender with a working geometry shader. Also if it isnt to much to ask a working passthough shader in order to get an idea of the setSource() api, if needed.

here is an image of my grass blend. i will post the file soon. i want to make a good example blend.

The BGE doesn’t support geometry shaders, although there were some early attempts. Technically, BGE has VBOs implemented but by default they are disabled. Keep in mind, geometry shaders are more expensive than both vertex and fragment shaders.

Since we’re talking modern OpenGL, another alternative for rendering lots of similar objects is OpenGL’s instancing extension (ARB_instanced_arrays):

You could also use imposters:

here is a link so u guys can see what i’m working on. The grass file also contains a cool catmull rom curve shader.

how would u set up the ARB_instanced_arrays extension? If u could show me how to impliment it at its basic level i would be so happy.
right now i’m reading about the ARB instancing. I had never come across this, so any other ideas good are encouraged. i’ll be studying more till then.
thanks Mahalin

Here are some tutorials:

Implementing it in the BGE would require C++ and being familiar with the Rasterizer etc. Off the top of my head, you’d need to enable VBOs, and then modify code in RAS_StorageVBO.cpp and probably other related areas.

BTW, cool blend! :eyebrowlift:

Don’t forget to enable gl_ext_MAGIC too :wink:

how does one go changing blender around? and like agoose said enable gl_ex_MAGIC. what is that and where do u get information on this? I am very intrested in doing this, but I never made a build of blender and dont know where to start.

@ Agoose i’m so lost that i cant tell if ur comment is sarcasm. lol

@Mahalin where would i find RAS_StorageVBO.cpp? also how do u change it? I do know some c++. and i’m very

What Agoose is referring to is geometry shaders are part of modern OpenGL (specifically 3.2?). Currently, BGE primarily uses legacy OpenGL (1.x/2.x) so you need to load the extensions, request the proper context, etc. I must warn you of the long and bumpy road ahead. You could wait for the Viewport FX work to make its way into the BGE.

From Blender GIT:

Compiling Blender (GIT + scons/cmake + etc.):

This is hella cool :slight_smile:
From looking at the .blend, I have a suggestion for you right off the bat: Name your scripts, objects, textures, materials and functions all according to their purpose, and comment wherever you can. This will save a hell of a lot of confusion in the future.

It looks really cool, but I only get like 17fps on my hexacore dual-gpu system, so I can see why optimization is needed here :wink:
Also, there are some strange artefacts near the cursor object:

Ah, It was a joke, but it wasn’t intended upon reading as insulting! It’s a bit of an inside-joke :wink:

As Mahalin warns, this would be quite a lot of work, and I would recommend perhaps waiting until Viewport FX projects are merged :slight_smile:


I get a really smooth, playable 25 frames per second for some reason. I’ve only got an AMD HD 7750; I’m pretty sure they’re not even manufactured anymore. Though with a little optimisation (like lowering the amount of edges in a blade of grass, I would think 2 bends ought to be fine) this could be a really nice resource. Keep it up, yo.

This is a really cool shader! I get 43 fps on my laptop if i disable vSync.

Newer GPUs are configured to be better optimized for tessellation and is very optimised in comparison to older GPUs such as mine (AMD tends to forget about older cards in their awful drivers). Since this is a pretty repetitive task for the GPU to process, your mid-range 7xxx series “value-oriented” card will handle it better. They aren’t manufactured still, but are still fairly new and available for purchase about everywhere.

I, personally, wouldn’t consider anything under 500fps in this demo to be anywhere near playable. If you think about it, in an actual completed scene there would be way more blades of grass plus additional objects, particle effects and shaders (for the rasterizer), then CPU-intensive tasks which would potentially bottleneck the GPU’s calculations further, such as logic and physics.

Either way, I’m sure that using instancing, VBOs, imposters and a tonne of LoD would certainly be enough to get this running post-60fps in a “real-world” situation.

Also, calculating each and every individual blade of grass is a bad idea. I would imagine that this is going to be done the same way that CryEngine 3 does it by using billboards with grass textures?

Here’s a pretty standard setup guide for a grass/wind implementation in UE4:
Quite interesting