I need to debug a GLSL program but I don't know how to output intermediate result.
Is it possible to make some debug traces (like with printf) with GLSL ?
I wondering if there is a way to optimize this vertex shader.
This vertex shader projects (in the light direction) a vertex to the far plane if it is in the shadow.
void main(void) {
vec3 lightDir = (gl_ModelViewMatrix * gl_Vertex
- gl_LightSource[0].position).xyz;
// if the vertex is lit
if ( dot(lightDir, gl_NormalMatrix * gl_Normal) < 0.01 ) {
// don't move it
gl_Position = ftransform();
} else {
// move it far, is the light direction
vec4 fin = gl_ProjectionMatrix * (
gl_ModelViewMatrix * gl_Vertex
+ vec4(normalize(lightDir) * 100000.0, 0.0)
);
if ( fin.z > fin.w ) // if fin is behind the far plane
fin.z = fin.w; // move to the far plane (needed for z-fail algo.)
gl_Position = fin;
}
}
Is it possible to set the color of a single vertex using a GLSL vertex shader program, in the same way that gl_Position changes the position of a vertex ?
I wondering if there is a faster way to draw a full-screen quad in OpenGL:
NewList();
PushMatrix();
LoadIdentity();
MatrixMode(PROJECTION);
PushMatrix();
LoadIdentity();
Begin(QUADS);
Vertex(-1,-1,0); Vertex(1,-1,0); Vertex(1,1,0); Vertex(-1,1,0);
End();
PopMatrix();
MatrixMode(MODELVIEW);
PopMatrix();
EndList();
How to create the transformation matrix (4x4) that transforms a cylinder (of height 1 and diameter 1) into a cone that represents my spotlight (position, direction and cutoff angle) ?
--edit--
In other words: how to draw the cone that represents my spotlight by drawing a cylinder through a suitable transformation matrix.