Project wall shadows onto other walls
This commit is contained in:
+64
-9
@@ -1,26 +1,81 @@
|
||||
#version 430 core
|
||||
layout (points) in;
|
||||
layout (triangle_strip, max_vertices = 4) out;
|
||||
layout (triangle_strip, max_vertices = 12) out;
|
||||
|
||||
uniform vec2 lightPos;
|
||||
uniform mat4 worldMat;
|
||||
|
||||
vec4 shift (vec4 p)
|
||||
{ return vec4 (p.xy + (200 * (p.xy-lightPos)), 0 , 1);
|
||||
}
|
||||
float isLHS (vec2 startV, vec2 testV)
|
||||
{
|
||||
return sign( -startV.x * testV.y + startV.y * testV.x);
|
||||
}
|
||||
void emitLine (vec2 pa)
|
||||
{
|
||||
gl_Position = vec4 (pa, 0, 1);
|
||||
EmitVertex();
|
||||
gl_Position = vec4 (pa + (200 * (pa - lightPos)), 0 , 1);
|
||||
gl_Position = shift (vec4 (pa,0,1)); //vec4 (pa + (200 * (pa - lightPos)), 0 , 1);
|
||||
EmitVertex();
|
||||
}
|
||||
|
||||
mat4 perspective =
|
||||
mat4 (1,0,0,0
|
||||
,0,1,0,0
|
||||
,0,0,1,1
|
||||
,0,0,0,1
|
||||
) ;
|
||||
// construct a box with opening on bottom face
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 frontL4 = worldMat * vec4(gl_in[0].gl_Position.xy, 0 ,1);
|
||||
vec4 frontR4 = worldMat * vec4(gl_in[0].gl_Position.zw, 0 ,1);
|
||||
vec2 frontL = frontL4.xy;
|
||||
vec2 frontR = frontR4.xy;
|
||||
|
||||
emitLine (frontR);
|
||||
emitLine (frontL);
|
||||
vec4 p1 = worldMat * vec4 (gl_in[0].gl_Position.xy,0,1);
|
||||
vec4 p2 = worldMat * vec4 (gl_in[0].gl_Position.zw,0,1);
|
||||
if (isLHS (p1.xy - lightPos, p2.xy - lightPos) < 0)
|
||||
{
|
||||
vec4 p3 = vec4 (p1.xy,-0.5,1);
|
||||
vec4 p4 = vec4 (p2.xy,-0.5,1);
|
||||
vec4 p5 = shift(p1);
|
||||
vec4 p6 = shift(p2);
|
||||
vec4 p7 = vec4 (p6.xy,-0.5,1);
|
||||
vec4 p8 = vec4 (p5.xy,-0.5,1);
|
||||
gl_Position = perspective * p4; EmitVertex();
|
||||
gl_Position = perspective * p3; EmitVertex();
|
||||
gl_Position = perspective * p7; EmitVertex();
|
||||
gl_Position = perspective * p8; EmitVertex();
|
||||
gl_Position = perspective * p5; EmitVertex();
|
||||
gl_Position = perspective * p3; EmitVertex();
|
||||
gl_Position = perspective * p1; EmitVertex();
|
||||
gl_Position = perspective * p4; EmitVertex();
|
||||
gl_Position = perspective * p2; EmitVertex();
|
||||
gl_Position = perspective * p7; EmitVertex();
|
||||
gl_Position = perspective * p6; EmitVertex();
|
||||
gl_Position = perspective * p5; EmitVertex();
|
||||
EndPrimitive();
|
||||
} else {}
|
||||
}
|
||||
|
||||
// // void main()
|
||||
// // {
|
||||
// // vec4 frontL4 = worldMat * vec4(gl_in[0].gl_Position.xy, 0 ,1);
|
||||
// // vec4 frontR4 = worldMat * vec4(gl_in[0].gl_Position.zw, 0 ,1);
|
||||
// // vec2 frontL = frontL4.xy;
|
||||
// // vec2 frontR = frontR4.xy;
|
||||
// //
|
||||
// // emitLine (frontR);
|
||||
// // emitLine (frontL);
|
||||
// // EndPrimitive();
|
||||
// // }
|
||||
// gl_Position = perspective * worldMat * p4; EmitVertex();
|
||||
// gl_Position = perspective * worldMat * p3; EmitVertex();
|
||||
// gl_Position = perspective * worldMat * p7; EmitVertex();
|
||||
// gl_Position = perspective * worldMat * p8; EmitVertex();
|
||||
// gl_Position = perspective * worldMat * p5; EmitVertex();
|
||||
// gl_Position = perspective * worldMat * p3; EmitVertex();
|
||||
// gl_Position = perspective * worldMat * p1; EmitVertex();
|
||||
// gl_Position = perspective * worldMat * p4; EmitVertex();
|
||||
// gl_Position = perspective * worldMat * p2; EmitVertex();
|
||||
// gl_Position = perspective * worldMat * p7; EmitVertex();
|
||||
// gl_Position = perspective * worldMat * p6; EmitVertex();
|
||||
// gl_Position = perspective * worldMat * p5; EmitVertex();
|
||||
|
||||
Reference in New Issue
Block a user