HELP : glsl 120 geometry shader, send info within vertex

Hello !

I’m discovering geometry shader.
I know that a point sends its position, color, normal, tex Coord …
Id like to send custom infos for each sent points to the geometry shader, for exemple a weight or an ID.

How to send a such info from my c++ programm and how to receive it in my shader ?

For the moment I thought about using the Z coordinate or the unused alpha channel to send a custom variable, but this solution is limited if i work in 3D of if the alpha channel is used.

Thanks.

I do not know if this may be relevant but as the geometry shader vertex shader works for single vertex. information as texture coordinates, normal, color,
It is decided during the primitive creation.

if I understand correctly you want to pass more information to its geometry shader, this can be done in many mode… more simple way and use a new:

uniform sampler2D info;

void main() {
    for(i = 0; i < gl_VerticesIn; i++) {
         vec4 vertex = gl_PositionIn[i];
         vertex.x += info.r;
         vertex.y += info.g;
         vertex.z += info.b;
         vertex.w += info.a;
    }
}

this is just an example to explain the concept.

however I encourage you to give a look at the most recent versions of OpenGL (GLSL 330 440) now the pipeline has become something extremely malleable and with the addition of " Tessellation Evaluation and Tessellation control" you can access even to small primitives that make up the primitive final.

Here you can find an example of a tessellation GLSL 440:

Thanks a lot,

The problem is that my computer (imac) doesn’t support higher versions of glsl than 120. Indeed in higher versions of glsl, I can get the ID of the vertex and refer this ID the somewhere in a given texture where a, r, g, b are four individual infos.

In your exemple, I don’t understand how you cas add the layer of a whole texure to a dimention of a vertex “vertex.x += info.r;”

In my case I want to make complex lines out of a single input point and send with this point au few individual rules of physics. So maybe I can send 2 points where the first contains the position, and the second only infos.

I’m sorry but my English does not allow me to best express what I mean.

now I have no example for this in version 120.
but if you want to take a look here (this version 150 easy to be converted into 120):

Perhaps you find what you need.

if you dig on the forum some time ago ahahkid public some of his lectures about this topic in version 120

Thanks I’ll look a bit closer to this.
To make it simple, I simply want to set the force or radius value within the point.

#version 120
#extension GL_ARB_texture_rectangle : enable
#extension GL_EXT_gpu_shader4 : enable
#extension GL_EXT_geometry_shader4 : enable
    uniform vec2 mouse;
    float force = 120;
    float radius = 10;
    float snoise(vec4 v);
    float curentNoise = 50;

    uniform sampler2DRect texture;//

    vec2 ptIn = gl_PositionIn[0].xy;

    vec2 applyForce(vec2 v, vec2 Pos)
    {
        vec2 distVec = v + Pos - mouse;
        float dist = length(distVec);
        //vec2 appForce = normalize(distVec) * force * (1+snoise(vec4(curentNoise, 50, ptIn))*2);
        vec2 appForce = normalize(distVec) * force;
        curentNoise += 0.071451;
        appForce /=  pow(dist/50, 2);
        v += appForce;
        return v;
    }


    void main(void){
        int nLines = 10;

        for(int i = 0 ; i < nLines ; i++)
        {
            gl_Position = gl_ModelViewProjectionMatrix * vec4(ptIn, 0, 1);
            //gl_FrontColor = gl_FrontColorIn[0];
            gl_FrontColor = texture2DRect( texture, ptIn);
            EmitVertex();
            
            vec2 prevVec = ptIn;
            vec2 nowVec;
            for(int j = 1 ; j < 12 ; j ++)
            {
                nowVec = vec2(cos(2 * 3.14 * i / nLines), sin(2 * 3.14 * i / nLines)) * radius * j;
                gl_FrontColor = texture2DRect( texture, nowVec + ptIn);//
                nowVec = applyForce(nowVec, prevVec);
                nowVec = normalize(nowVec)*radius + prevVec;
                gl_Position = gl_ModelViewProjectionMatrix * vec4(nowVec, 0, 1);
               
                //gl_FrontColor = gl_FrontColorIn[0];
                EmitVertex();
                prevVec = nowVec;
            }
            
            EndPrimitive();
        }
    }

I found a way to solve this problem based on the GPU particule system in the examples.

There is the Idea

  1. when creating the points with ofMesh, I can give coordiates that actually are ID with the addTexCoord(ofVec2f(x, y)) function.

  2. In my shader I use gl_MultiTexCoord0.xy to get the index on the processed vertex

  3. Use an Image where the custom value (force, noise seed…) should be and use the ID to match the values by using the function texture2DRect( Data_Image, ID).