I've been working in returning shadow volumes to FG via GLSL shaders. It is going OK so far, with stencil working thanks to Gijs for fixing light-cone. But I got in a problem with the vertex shaders. It works perfectly in every shader developing program I try (ShaderMaker, ShaderDesigner, Lumina and others). But it isn't in FG, where it doesn't extrude to infinity as it should be.
Here is the vertex shader:
- Code: Select all
void
main(void)
{
// Compute the light direction to vertex.
vec3 lightDir = (gl_ModelViewMatrix * gl_Vertex
- gl_LightSource[0].position).xyz;
// If vertex is not illuminated, hold position.
if (dot (lightDir, gl_NormalMatrix * gl_Normal) <= 0.0) {
gl_Position = ftransform();
} else {
// If it is, extrude in light direction.
vec4 pos = gl_ProjectionMatrix * (
gl_ModelViewMatrix * gl_Vertex
+ vec4 (normalize (lightDir) * 100000.0, 0.0));
// If the z position is higher than w, make z equal to w.
// (Similar to extruding to infinity, maybe some correction here helps??)
if (pos.z > pos.w)
pos.z = pos.w;
gl_Position = pos;
}
}
Any help is appreciated.
Cheers and thanks!