Use vertex pulling for wall shadows

This commit is contained in:
2025-11-10 21:33:56 +00:00
parent 1a85d9d562
commit 36d5edc0a6
5 changed files with 47 additions and 10 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ void main()
{
vec4 pp = data[gl_VertexID / 6].pospos;
int j = indices[gl_VertexID % 6];
float z = (j > 1.5 ? 5000 : 100);
float z = (j / 2 > 0.5 ? 5000 : 100);
vec2 xy = (j % 2 > 0 ? pp.xy : pp.zw);
gl_Position = theMat * vec4(xy,z,1);
}
+37 -4
View File
@@ -1,6 +1,39 @@
#version 450 core
layout (location = 0) in vec4 poss;
void main()
{
gl_Position = poss;
//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));
}