Implement (not fully working) alternate shadow volumes

This commit is contained in:
2023-02-24 19:51:41 +00:00
parent ed9a46a18d
commit bf1bd5bb0b
9 changed files with 136 additions and 116 deletions
+6 -2
View File
@@ -3,9 +3,10 @@ layout (lines_adjacency) in;
layout (triangle_strip, max_vertices = 4) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
uniform vec3 lightPos;
uniform vec4 lumRad;
uniform float radiusUniform;
//vec4 shift (vec4 p) { return (vec4 (p.xyz + (lumRad.a*normalize(p.xyz-lightPos)), 1));}
vec4 shift (vec4 p) { return (vec4 (p.xyz + (100000*(p.xyz-lightPos)), 1));}
vec4 shiftBy (float x,vec4 p) { return (vec4 (lightPos + (x*normalize(p.xyz-lightPos)), 1));}
//vec4 shift (vec4 p) { return (vec4 (lightPos + (lumRad.a*normalize(p.xyz-lightPos)), 1));}
// copied from lighting/cap.geom, should not be changed on its own
vec4 projNear (vec4 pos)
@@ -18,6 +19,7 @@ vec4 projNear (vec4 pos)
return vec4 ( xy, 140 , 1) ;
}
vec4 shiftNear (vec4 pos)
//{ vec4 sp = shiftBy(radiusUniform,pos);
{ vec4 sp = shift(pos);
if (sp.z > 140)
{ return projNear(pos) ; }
@@ -27,6 +29,7 @@ vec4 shiftNear (vec4 pos)
vec4 f (vec4 p) {return (theMat * p);}
void main()
{
float ru2 = radiusUniform * radiusUniform ;
vec4 p0 = gl_in[0].gl_Position;
vec4 p1 = gl_in[1].gl_Position;
vec4 mid = 0.5*(p0 + p1);
@@ -41,7 +44,8 @@ void main()
// first test if the edge is part of the silhouette
// that is, if the normals of the faces connected by the edge point are in
// "different directions" wrt the light direction
if ( dot(n0 , lightDir) * dot(n1 , lightDir) <= 0 )
if ( dot(n0 , lightDir) * dot(n1 , lightDir) <= 0 &&
(dot(lightDir,lightDir) < ru2 || dot(lightDir2,lightDir2) < ru2) )
// using <= rather than < seems to get rid of overlapping shadow
// artefacts
{