#version 120 #extension GL_EXT_geometry_shader4 : enable
varying in float[] vRadius;
varying out vec2 vLocalCoord;
vec2[3] cLocalCoords = vec2[3](vec2(0, 2), vec2(sqrt(3), -1), vec2(-sqrt(3), -1)); //how many times initialized?
void main() {
for(int i = 0; i < 3; ++i) {
gl_FrontColor = gl_FrontColorIn[0];
gl_Position = gl_PositionIn[0] + gl_ModelViewProjectionMatrix * vec4(vRadius[0] *cLocalCoords[i], 0.0, 0.0);
vLocalCoord = cLocalCoords[i];
EmitVertex();
}
EndPrimitive();
}
[/b][/QUOTE]
Fragment shader
[b]
#version 120
varying vec2 vLocalCoord;
void main () {
float distanceFromLocalOrigin2 = vLocalCoord.x * vLocalCoord.x + vLocalCoord.y * vLocalCoord.y;
if (distanceFromLocalOrigin2 > 1.0)
discard;
gl_FragColor = gl_Color * (1.0 - distanceFromLocalOrigin2);
}
[/b]
[/b][/QUOTE]
Program (Note I am converting a GL_POINT into a GL_TRIANGLE)
> [b]
> program = new Program(vertexShader, geometryShader, fragmentShader);
> program.setProgramParameteriEXT(GL.GL_GEOMETRY_INPUT_TYPE_EXT, GL.GL_POINTS);
> program.setProgramParameteriEXT(GL.GL_GEOMETRY_OUTPUT_TYPE_EXT, GL.GL_TRIANGLE_STRIP);
> program.setProgramParameteriEXT(GL.GL_GEOMETRY_VERTICES_OUT_EXT, 3);
> [/b]
> [/b]
I would have liked to make the cLocalCoords array constant but "error C7516: OpenGL does not allow constant arrays"...
Don’t worry about not using “const”. The compiler will make it const.
(it’s very eye-opening to see the asm listing that cgc.exe or your nVidia drivers produce [with nVemulate])
I’d probably do something foolish like send the center to the shader and take a direct reading from there, but then I’m a fool.
I cant see how thats follish, that like the method I suggested should both work + IMO are simpler than the geometry shader method.
I must of misunderstood the question?
Well, he wants to avoid "VBO of 3N texture coordinates", so that’s why the only solution is geom.shader ; or slower tricks with boundable-uniforms/VTF.
Still, considering how much geometry needs to be “flat”-shaded (edgy stairs, walls etc) and thus go with NumVerts=3NumTris, your approach of just adding one float/vertex is the optimal solution in those cases.