Files
loop/shader/lighting/wall.geom
T
2021-06-25 01:19:20 +02:00

51 lines
1.3 KiB
GLSL

#version 430 core
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
uniform vec3 lightPos;
uniform vec2 radLum;
out vec3 dField;
out float lum;
float isLHS (vec2 startV, vec2 testV)
{
return sign( -startV.x * testV.y + startV.y * testV.x);
}
vec4 shiftCloser (vec4 v)
{ return vec4 (v.xy , v.z-0.0001 , v.w) ; }
void main()
{
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0.1,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0.1,1);
if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0)
{
lum = radLum.y;
float rad = radLum.x;
vec4 p3 = vec4 (p1.xy,-0.3,1);
vec4 p4 = vec4 (p2.xy,-0.3,1);
vec2 d1 = p1.xy - lightPos.xy;
vec2 d2 = p2.xy - lightPos.xy;
vec4 a1 = shiftCloser( theMat * p1 );
vec4 a2 = shiftCloser( theMat * p2 );
vec4 a3 = shiftCloser( theMat * p3 );
vec4 a4 = shiftCloser( theMat * p4 );
dField = vec3( d1.x/rad, d1.y/rad, 100.0/rad);
gl_Position = a1;
EmitVertex();
dField = vec3( d1.x/rad, d1.y/rad, -300.0/rad);
gl_Position = a3;
EmitVertex();
dField = vec3( d2.x/rad, d2.y/rad, 100.0/rad);
gl_Position = a2;
EmitVertex();
dField = vec3( d2.x/rad, d2.y/rad, -300.0/rad);
gl_Position = a4;
EmitVertex();
EndPrimitive();
} else {}
}