Files
loop/shader/lighting/wallShadow.vert
T

40 lines
1.1 KiB
GLSL

#version 450 core
//layout (location = 0) in vec4 poss;
//void main()
//{
// gl_Position = poss;
//}
struct PosTex { vec4 pospos; vec4 texang; };
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
layout (std430, binding = 2) readonly buffer Pos { PosTex data[]; };
layout(location=0) uniform vec3 lightPos;
layout(location=1) uniform float rad;
int indices[18] =
{5,1,7 // 6----7
,7,1,3 // /| /|
,7,3,6 // 2-+--3 |
,6,3,2 // | 4 | 5
,6,2,4 // 0 1
,4,2,0
};
vec2 shift(vec2 p) {
return vec2(lightPos.xy + (rad * normalize(p - lightPos.xy)));
}
float detV(vec2 p, vec2 q) {
return p.x*q.y - p.y*q.x;
}
float isLHS(vec2 p, vec2 q) {
return sign(-detV(p,q));
}
void main() {
vec4 pp = data[gl_VertexID / 18].pospos;
int j = indices[gl_VertexID % 18];
vec2 xy = (j % 2 > 0 ? pp.xy : pp.zw);
float z = ((j / 2) % 2 > 0.5 ? 100 : -500);
vec2 xyo = ( j > 3.5 ? shift(xy) : xy);
vec4 p = theMat * vec4(xyo,z,1);
gl_Position = (isLHS(pp.xy-lightPos.xy,pp.zw-lightPos.xy) < 0
? p
: vec4(1,1,1,0));
}