Files

29 lines
1020 B
GLSL

#version 450 core
struct PosColNorm { vec4 pos; vec4 dummy; };
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
layout (std140, binding = 1) uniform TheLight { vec4 lightPos; vec4 lumRad; };
layout (std430, binding = 3) readonly buffer Data { PosColNorm data[]; };
layout (std430, binding = 4) readonly buffer Indices { uint indices[]; };
vec4 projNear (vec4 pos)
{
// note we project to a specific height
// this is quite brittle, not ideal
vec3 dir = pos.xyz - lightPos.xyz ;
float a = (100 - pos.z) / dir.z ;
vec2 xy = (pos.xyz + a * dir).xy ;
return vec4 ( xy, 100 , 1) ;
}
bool ztest (vec4 p) {return p.z - lightPos.z > 0;}
void main() {
int j = gl_VertexID/3;
int i1 = j * 3;
vec4 po = data[indices[gl_VertexID]].pos;
gl_Position = (po.w == 1
&& ztest(data[indices[i1]].pos)
&& ztest(data[indices[i1+1]].pos)
&& ztest(data[indices[i1+2]].pos)
? theMat * projNear(po)
: vec4(1,1,1,0)
);
}