48 lines
1.5 KiB
GLSL
48 lines
1.5 KiB
GLSL
#version 450 core
|
|
layout (triangles) in;
|
|
layout (invocations = 20) in;
|
|
layout (triangle_strip, max_vertices = 3) out;
|
|
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
|
|
layout (std140, binding = 1) uniform LightsBlock
|
|
{
|
|
vec4 posBool[20];
|
|
vec4 colRad[20];
|
|
} ;
|
|
vec3 lightPos = posBool[gl_InvocationID].xyz ;
|
|
float theBool = posBool[gl_InvocationID].w;
|
|
// this code is duplicated in shadow/edge.geom, should not be changed on its own
|
|
vec4 projNear (vec4 pos)
|
|
{
|
|
// note we project to a specific height
|
|
// this is quite brittle, not ideal
|
|
vec3 dir = pos.xyz - lightPos ;
|
|
float a = (100 - pos.z) / dir.z ;
|
|
vec2 xy = (pos.xyz + a * dir).xy ;
|
|
return vec4 ( xy, 100 , 1) ;
|
|
}
|
|
void main()
|
|
{
|
|
vec4 p0 = gl_in[0].gl_Position ;
|
|
vec4 p1 = gl_in[1].gl_Position ;
|
|
vec4 p2 = gl_in[2].gl_Position ;
|
|
if ( //if Light Source is below all vertices, draw cap
|
|
// TODO think about when LS is beside the object
|
|
( p0.z - lightPos.z > 0 )
|
|
&& ( p1.z - lightPos.z > 0 )
|
|
&& ( p2.z - lightPos.z > 0 )
|
|
&& theBool == 1
|
|
)
|
|
{
|
|
// the front cap
|
|
vec4 v1 = vec4 (0,0,1,0) ;
|
|
gl_Layer = gl_InvocationID;
|
|
gl_Position = theMat * projNear(p0); EmitVertex();
|
|
gl_Layer = gl_InvocationID;
|
|
gl_Position = theMat * projNear(p1); EmitVertex();
|
|
gl_Layer = gl_InvocationID;
|
|
gl_Position = theMat * projNear(p2); EmitVertex();
|
|
EndPrimitive();
|
|
}
|
|
else {}
|
|
}
|