Geometry Shader using OpenGL Wrapper (bgl) [fix for Intel]

By using the OpenGL wrapper (bgl) I get managed to add a geometry shader to the custom material shader.


I hopefully fixed the Intel bug. I have tested it with an Intel HD Graphics 4000. But sometime it will crash. I seems that Intel attach the shades randomly.
It is very important for Intel and ATI/AMD that are the latests drivers are installed. Legacy drivers will not work (no geometry extension).
I also added some new basic examples.
GeometryShaderExample V1.2.blend (112 KB)

Small improvement. Using GL_CURRENT_PROGRAM to get shader program, which should be faster to get the actual shader program.
Added a new example.
GeometryShaderExample_V1.3.blend (116 KB)

Add four new examples (tessellation, wireframe).

HG1

1 Like

Very smart hack, congratulations !

Could you replace a plane with waving grass?

Possible, but actually I don’t want spend time to do that.

i’m with blueprintrandom i need this too. Also for grass, but can this produce somehthing like a VBO? can it and copies of itself?

i could so a lot with this if it works like i need. saw the file it really works first time seeing a working gs file. great work.

hey i put this in the gs but dont know how to send a different color to the frag shader. i just put some values anywhere to mess with it and i got some cool results

gs = “”"
#version 150

uniform float time;

layout(triangles) in;
layout(triangle_strip, max_vertices= 153) out;

void main()
{
for(int i=0; i<53; i++)
{
float new_time = time + i * .51;
for(int i=0; i<3; i++)
{
gl_Position = gl_in[i].gl_Position+ new_time;
EmitVertex();
}
EndPrimitive();
}

}
“”"

how would u send data to the frag shader. i tried messing with a varring var but its not compatible. can u show an example of different colors to the fragshader with the idea behind that code i posted? I was told by someone that this did work, but i now am very intrested again. if this works oh man… plz get back to me

I have tested it is working with varying.

gs = """
#version 150

varying float r;
uniform float time;

layout(triangles) in;
layout(triangle_strip, max_vertices=3) out;

void main()
{   
    for(int i=0; i&lt;3; i++)
    {
        gl_Position = gl_in[i].gl_Position+time;
        r = gl_Position.y/15.0;
        EmitVertex();
    }
EndPrimitive();
}  
""" 

fs = """
varying float r;

void main()
{   
    gl_FragColor = vec4(r, 0.0, 0.0, 1.0);
}
"""

If you use shader version 3.30 or higher you have to use in and out instead of varying.

so i was able to get this. pretty cool. just messing with it still. but i cant get uv textures on


here is the file
i hope some one can help with this. its very useful to me. i need texutre uvs on there.

Attachments

geo_grass.blend (1.01 MB)

You don’t pass the texture coordinates trough the geometry shader.

Tcoord1 = Texcoord1[i];

You have to do this for any value that you want to use and is assigned to an vertex like texture coordinates, normals and so on.

Edit:
Correct example. Delete wrong blend file.

how would u add more objects with the texture? like my file had. i notice when u take out those two lines it works again.

the file has a few errors. it anyone can do this i would greatly apprieciate it. I just need someone to guide me. a simple straight though shader isnt the best example. I know i can read on the net how to do geo shaders, but i need a primer to see how blender handles the calls correctly. so i cant easily take off with it. in one night i got it to add a slew of objects, so i’m sure someone here knows how to do this. plz plz. this is an amazing work thanks HG1.

what are ur plans with it by the way? u working on a game?

can anyone test this. i am going crazy trying to get it.

Sorry I made a fault. I don’t realized that there is an compile error.
I have updated the example.

what are ur plans with it by the way? u working on a game?

I don’t plans anything with it. I also don’t working on a game (I also nerve have made one). I have done this only because there always peoples who want geometry shader for the BGE. So I searched and found way to add them.

P.S. Don’t make double posts. Please use the edit function.

Attachments

geo_grass.blend (613 KB)

What is geometry shaders used for? I don’t see anything special in theese blends… The meshes looks shadeless…

With geometry shades you can add or remove geometry objects (vertices). Which is not possible with the vertex shader, which can only modify the vertices. Look at the third shader where the objects are replaced with circles.
So it is possible to draw face or vertex normals, duplicate objects (e.g. grass ), adding particles, generate a single outline stroke, tessellate objects, dynamic LOD, draw a wireframe over an object and so on.

When I test v1.1, I get red triangles…

this opens up an untapped resource in blender. this file is sweet!! thanks this is just what i needed. i did that same thing but i used a varing vec2 texcoord[3] didnt think you could mix those. thanks again HG1.

is there anyway to make this easy for newbs to use?

like by adding empties with properties for where the instances are to be placed?

Yeah, apparently the files aren’t working for me too, I get red triangles, as if the fragment and vertex shaders work, but not the geometry shader.

I get “Geometry shader fault” on the console:


When I test v1.1, I get red triangles…

  1. Did you changed the script to geometry3?
  2. Your graphic card support at least geometry shader V1.50.

this opens up an untapped resource in blender. this file is sweet!! thanks this is just what i needed. i did that same thing but i used a varing vec2 texcoord[3] didnt think you could mix those. thanks again HG1.

Yes you can mix varying and in/out. But above GLSL 1.20 varying is deprecated and if you want to use the GLSL 3.30 features you have to use in/out for the fragment shader.

is there anyway to make this easy for newbs to use?
like by adding empties with properties for where the instances are to be placed?

I am not sure what you mean by that. But I think you mean you want to use empties to define where the grass will be placed.
If you use a geometry sander it is easier to use an extra mesh to define it. On each vertex the grass will be generated.
Or more advanced you can use a stencil map to define where the grass should be placed.

Edit:
@carlo697
Try one other scripts.
Your graphic card must support geometry shader 1.50 to get it working. Please check if your graphic card are supporting it. If yes try to update your graphic card driver.