Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GLSL Geom shader billboard
    vec2 offSet[4];
 	offSet[0] = vec2(0.,0.);
    offSet[1] = vec2(0.,1.);
    offSet[2] = vec2(1.,0.);
    offSet[3] = vec2(1.,1.);

	vec3 zAxis = normalize( vNormal[0] );
    vec3 yAxis = vec3( 0.0, 1.0, 0.0 );
    vec3 xAxis = normalize( cross(zAxis, yAxis) );
    yAxis = normalize( cross(xAxis, zAxis) );

    xAxis *= pointSize;
    yAxis *= pointSize;

    for(int i = 0; i < 4; i++){
        vec3 dir = ((offSet[i].x*2.-1.)*xAxis) + ((offSet[i].y*2.-1.)*yAxis);
        gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_PositionIn[0].xyz+dir,1.0);
        gl_TexCoord[0].xy = offSet[i].xy;
        gl_FrontColor = gl_FrontColorIn[0];
        EmitVertex();
    }
    EndPrimitive();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment