79 lines
2.2 KiB
GLSL
79 lines
2.2 KiB
GLSL
#version 450 core
|
|
layout(points) in;
|
|
layout(invocations = 20) in;
|
|
layout(triangle_strip, max_vertices = 8) 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;
|
|
vec4 shift(vec4 p) { return vec4(p.xy + (200 * (p.xy - lightPos.xy)), 0, 1); }
|
|
float isLHS(vec2 startV, vec2 testV) {
|
|
return sign(-startV.x * testV.y + startV.y * testV.x);
|
|
}
|
|
// Preprocessed to include ../functions.glsl
|
|
float closestPointOnLineParam (vec2 a, vec2 b, vec2 p) {
|
|
return dot(p - a,b-a) / dot(b-a,b-a);
|
|
}
|
|
vec2 closestPointOnSeg (vec2 a,vec2 b, vec2 p) {
|
|
float x = closestPointOnLineParam(a,b,p);
|
|
if (x < 0) {
|
|
return a;
|
|
} else{ if (x > 1) { return b; }
|
|
{ return a + (x * (b- a));}
|
|
}
|
|
}
|
|
// End include 2023-03-13 15:33:44.454374887 UTC
|
|
// construct a box with openings on bottom face and face away from wall
|
|
void main() {
|
|
vec4 p1 = vec4(gl_in[0].gl_Position.xy, 0, 1);
|
|
vec4 p2 = vec4(gl_in[0].gl_Position.zw, 0, 1);
|
|
if (theBool == 1 && isLHS(p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0) {
|
|
vec4 p3 = vec4(p1.xy, 100, 1);
|
|
vec4 p4 = vec4(p2.xy, 100, 1);
|
|
vec4 p5 = shift(p1);
|
|
vec4 p6 = shift(p2);
|
|
vec4 p7 = vec4(p6.xy, 100, 1);
|
|
vec4 p8 = vec4(p5.xy, 100, 1);
|
|
|
|
vec4 a1 = theMat * p1;
|
|
vec4 a2 = theMat * p2;
|
|
vec4 a3 = theMat * p3;
|
|
vec4 a4 = theMat * p4;
|
|
vec4 a5 = theMat * p5;
|
|
vec4 a6 = theMat * p6;
|
|
vec4 a7 = theMat * p7;
|
|
vec4 a8 = theMat * p8;
|
|
|
|
gl_Position = a1;
|
|
gl_Layer = gl_InvocationID;
|
|
EmitVertex();
|
|
gl_Position = a5;
|
|
gl_Layer = gl_InvocationID;
|
|
EmitVertex();
|
|
gl_Position = a3;
|
|
gl_Layer = gl_InvocationID;
|
|
EmitVertex();
|
|
gl_Position = a8;
|
|
gl_Layer = gl_InvocationID;
|
|
EmitVertex();
|
|
gl_Position = a4;
|
|
gl_Layer = gl_InvocationID;
|
|
EmitVertex();
|
|
gl_Position = a7;
|
|
gl_Layer = gl_InvocationID;
|
|
EmitVertex();
|
|
gl_Position = a2;
|
|
gl_Layer = gl_InvocationID;
|
|
EmitVertex();
|
|
gl_Position = a6;
|
|
gl_Layer = gl_InvocationID;
|
|
EmitVertex();
|
|
|
|
EndPrimitive();
|
|
} else {
|
|
}
|
|
}
|