Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motoishmz/003f7e76e032147e5009 to your computer and use it in GitHub Desktop.
Save motoishmz/003f7e76e032147e5009 to your computer and use it in GitHub Desktop.
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