Shadow volume shader optimization (GLSL)
Posted
by Soubok
on Stack Overflow
See other posts from Stack Overflow
or by Soubok
Published on 2010-03-25T18:30:55Z
Indexed on
2010/03/25
18:33 UTC
Read the original article
Hit count: 675
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;
}
}
© Stack Overflow or respective owner