Cleanup shadows
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
#version 450 core
|
||||
layout (triangles) in;
|
||||
layout (triangle_strip, max_vertices = 3) out;
|
||||
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
|
||||
layout(location=0)uniform vec3 lightPos;
|
||||
in float drawbit[];
|
||||
// the following code is duplicated in lineShadow.geom, should not be changed on its own
|
||||
vec4 projNear (vec4 pos)
|
||||
{
|
||||
// note we project to a specific height
|
||||
// this is quite brittle, not ideal
|
||||
vec3 dir = pos.xyz - lightPos ;
|
||||
float a = (100 - pos.z) / dir.z ;
|
||||
vec2 xy = (pos.xyz + a * dir).xy ;
|
||||
return vec4 ( xy, 100 , 1) ;
|
||||
}
|
||||
void main()
|
||||
{
|
||||
vec4 p0 = gl_in[0].gl_Position ;
|
||||
vec4 p1 = gl_in[1].gl_Position ;
|
||||
vec4 p2 = gl_in[2].gl_Position ;
|
||||
if ( //if Light Source is below all vertices, draw cap
|
||||
// TODO think about when LS is beside the object
|
||||
(drawbit[0] == 1)
|
||||
&& ( p0.z - lightPos.z > 0 )
|
||||
&& ( p1.z - lightPos.z > 0 )
|
||||
&& ( p2.z - lightPos.z > 0 )
|
||||
)
|
||||
{
|
||||
// the front cap
|
||||
vec4 v1 = vec4 (0,0,1,0) ;
|
||||
gl_Position = theMat * projNear(p0); EmitVertex();
|
||||
gl_Position = theMat * projNear(p2); EmitVertex();
|
||||
gl_Position = theMat * projNear(p1); EmitVertex();
|
||||
EndPrimitive();
|
||||
}
|
||||
else {}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
#version 450 core
|
||||
// an attempt to test whether a geometry surface occludes the camera from a
|
||||
// light source
|
||||
layout (triangles) in;
|
||||
layout (triangle_strip, max_vertices = 4) out;
|
||||
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
|
||||
uniform vec3 lightPos;
|
||||
uniform vec2 camPos;
|
||||
void main()
|
||||
{
|
||||
vec3 p0 = gl_in[0].gl_Position.xyz ;
|
||||
vec3 p1 = gl_in[1].gl_Position.xyz ;
|
||||
vec3 p2 = gl_in[2].gl_Position.xyz ;
|
||||
|
||||
// first determine intersection point (if any)
|
||||
|
||||
vec3 u = p1 - p0 ;
|
||||
vec3 v = p2 - p0 ;
|
||||
vec3 n = cross (u,v) ;
|
||||
vec3 dir = vec3 (camPos, 100) - lightPos ;
|
||||
vec3 w0 = p0 - lightPos ;
|
||||
float a = dot(n, w0) ;
|
||||
float b = dot(n,dir) ;
|
||||
if (abs(b) < 0.00001) {}
|
||||
else {
|
||||
float r = a / b ;
|
||||
if (r < 0.0) {}
|
||||
else {
|
||||
vec3 ip = lightPos + r * dir ;
|
||||
float uu, uv, vv, wu, wv, D;
|
||||
uu = dot(u,u);
|
||||
uv = dot(u,v);
|
||||
vv = dot(v,v);
|
||||
vec3 w = ip - p0;
|
||||
wu = dot (w,u);
|
||||
wv = dot (w,v);
|
||||
D = uv * uv - uu * vv;
|
||||
//get and test parametric coords
|
||||
float s, t;
|
||||
s = (uv * wv - vv * wu) / D;
|
||||
if (s < 0.0 || s > 1.0) {}
|
||||
else
|
||||
{
|
||||
t = (uv * wu - uu * wv) / D;
|
||||
if (t < 0.0 || (s + t) > 1.0) {}
|
||||
else
|
||||
{
|
||||
gl_Position = vec4(-1,-1,50,1); EmitVertex();
|
||||
gl_Position = vec4(-1, 1,50,1); EmitVertex();
|
||||
gl_Position = vec4( 1,-1,50,1); EmitVertex();
|
||||
gl_Position = vec4( 1, 1,50,1); EmitVertex();
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
#version 450 core
|
||||
layout (points) in;
|
||||
layout (triangle_strip, max_vertices = 4) out;
|
||||
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
|
||||
out float lum;
|
||||
out vec2 dField;
|
||||
void main()
|
||||
{
|
||||
lum = gl_in[0].gl_Position.w;
|
||||
vec4 cenPos = vec4( gl_in[0].gl_Position.xy, 0.1 , 1);
|
||||
float gRad = gl_in[0].gl_Position.z;
|
||||
|
||||
dField = vec2 ( 1, 1);
|
||||
gl_Position = theMat * vec4 (cenPos.x + gRad, cenPos.y + gRad, 0.1 , 1);
|
||||
EmitVertex();
|
||||
dField = vec2 (-1, 1);
|
||||
gl_Position = theMat * vec4 (cenPos.x - gRad, cenPos.y + gRad, 0.1 , 1);
|
||||
EmitVertex();
|
||||
dField = vec2 ( 1,-1);
|
||||
gl_Position = theMat * vec4 (cenPos.x + gRad, cenPos.y - gRad, 0.1 , 1);
|
||||
EmitVertex();
|
||||
dField = vec2 (-1,-1);
|
||||
gl_Position = theMat * vec4 (cenPos.x - gRad, cenPos.y - gRad, 0.1 , 1);
|
||||
EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
#version 450 core
|
||||
layout(lines_adjacency) in;
|
||||
layout(triangle_strip, max_vertices = 4) out;
|
||||
layout(std140, binding = 0) uniform TheMat { mat4 theMat; };
|
||||
layout(location=0) uniform vec3 lightPos;
|
||||
layout(location=1) uniform float radiusUniform;
|
||||
float closestPointOnLineParam3 (vec3 a, vec3 b, vec3 p) {
|
||||
return dot(p - a,b-a) / dot(b-a,b-a);
|
||||
}
|
||||
vec3 closestPointOnSeg3 (vec3 a,vec3 b, vec3 p) {
|
||||
float x = closestPointOnLineParam3(a,b,p);
|
||||
if (x < 0) {
|
||||
return a;
|
||||
} else{ if (x > 1) { return b; }
|
||||
{ return a + (x * (b- a));}
|
||||
}
|
||||
}
|
||||
vec4 shift(vec4 p) { return (vec4(p.xyz + (10000 * (p.xyz - lightPos)), 1)); }
|
||||
vec4 shiftBy(float x, vec4 p) {
|
||||
return (vec4(lightPos + (x * normalize(p.xyz - lightPos)), 1));
|
||||
}
|
||||
// copied from lighting/cap.geom, should not be changed on its own
|
||||
vec4 projNear(vec4 pos) {
|
||||
// note we project to a specific height
|
||||
// this is quite brittle, not ideal
|
||||
vec3 dir = pos.xyz - lightPos;
|
||||
float a = (100 - pos.z) / dir.z;
|
||||
vec2 xy = (pos.xyz + a * dir).xy;
|
||||
return vec4(xy, 100, 1);
|
||||
}
|
||||
vec4 shiftNear(vec4 pos)
|
||||
{
|
||||
vec4 sp = shift(pos);
|
||||
if (sp.z > 100) {
|
||||
return projNear(pos);
|
||||
} else {
|
||||
return sp;
|
||||
}
|
||||
}
|
||||
void main() {
|
||||
vec4 p0 = gl_in[0].gl_Position;
|
||||
vec4 p1 = gl_in[1].gl_Position;
|
||||
vec3 closepoint = closestPointOnSeg3(p0.xyz,p1.xyz,lightPos);
|
||||
float ru2 = radiusUniform * radiusUniform;
|
||||
vec4 mid = 0.5 * (p0 + p1);
|
||||
vec3 n0a = gl_in[2].gl_Position.xyz;
|
||||
vec3 n1a = gl_in[3].gl_Position.xyz;
|
||||
vec3 n0 = cross(p1.xyz - p0.xyz, n0a - p0.xyz);
|
||||
vec3 n1 = cross(p0.xyz - p1.xyz, n1a - p1.xyz);
|
||||
vec3 lightDir = p0.xyz - lightPos.xyz;
|
||||
vec3 lightDir2 = p1.xyz - lightPos.xyz;
|
||||
// first test if the edge is part of the silhouette
|
||||
// that is, if the normals of the faces connected by the edge point are in
|
||||
// "different directions" wrt the light direction
|
||||
if (dot(n0, lightDir) * dot(n1, lightDir) <= 0 &&
|
||||
(dot(lightDir, lightDir) < ru2 || dot(lightDir2, lightDir2) < ru2))
|
||||
// using <= rather than < seems to get rid of overlapping shadow
|
||||
// artefacts
|
||||
{
|
||||
vec4 p2 = shiftNear(p0);
|
||||
vec4 p3 = shiftNear(p1);
|
||||
gl_Position = theMat * p0;
|
||||
EmitVertex();
|
||||
if (dot(n0, lightDir) > 0) {
|
||||
gl_Position = theMat * p2;
|
||||
EmitVertex();
|
||||
gl_Position = theMat * p1;
|
||||
EmitVertex();
|
||||
} else {
|
||||
gl_Position = theMat * p1;
|
||||
EmitVertex();
|
||||
gl_Position = theMat * p2;
|
||||
EmitVertex();
|
||||
}
|
||||
gl_Position = theMat * p3;
|
||||
EmitVertex();
|
||||
EndPrimitive();
|
||||
} else {
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,29 @@
|
||||
#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 colrad; };
|
||||
layout (std430, binding = 3) readonly buffer Data { PosColNorm data[]; };
|
||||
layout (std430, binding = 5) readonly buffer Indices { uint indices[]; };
|
||||
layout(location=0)uniform vec3 lightPos;
|
||||
layout(location=1)uniform float radiusUniform;
|
||||
float closestPointOnLineParam3 (vec3 a, vec3 b, vec3 p) {
|
||||
return dot(p - a,b-a) / dot(b-a,b-a);
|
||||
}
|
||||
vec3 closestPointOnSeg3 (vec3 a,vec3 b, vec3 p) {
|
||||
float x = closestPointOnLineParam3(a,b,p);
|
||||
if (x < 0) {
|
||||
return a;
|
||||
} else{ return (x > 1 ? b: a + (x * (b- a))); }
|
||||
return (x < 0
|
||||
? a
|
||||
: (x > 1
|
||||
? b
|
||||
: a + (x * (b- a)))) ;
|
||||
}
|
||||
vec4 shift(vec4 p) { return (vec4(p.xyz + (10000 * (p.xyz - lightPos)), 1)); }
|
||||
vec4 shift(vec4 p) { return (vec4(p.xyz + (10000 * (p.xyz - lightPos.xyz)), 1)); }
|
||||
vec4 shiftBy(float x, vec4 p) {
|
||||
return (vec4(lightPos + (x * normalize(p.xyz - lightPos)), 1));
|
||||
return (vec4(lightPos.xyz + (x * normalize(p.xyz - lightPos.xyz)), 1));
|
||||
}
|
||||
vec4 projNear (vec4 pos)
|
||||
{
|
||||
// note we project to a specific height
|
||||
// this is quite brittle, not ideal
|
||||
vec3 dir = pos.xyz - lightPos ;
|
||||
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) ;
|
||||
@@ -31,11 +32,13 @@ vec4 shiftNear(vec4 pos)
|
||||
{
|
||||
vec4 sp = shift(pos);
|
||||
return (sp.z > 100 ? projNear(pos) : sp);
|
||||
}
|
||||
int ks[6] =
|
||||
{0,1,2 // 2--3
|
||||
,2,1,3 // | |
|
||||
}; // 0--1
|
||||
}
|
||||
// Output 6 vertices for 4 data inputs
|
||||
int ks[6] = // Inputdata: n1a Shadow:
|
||||
{0,1,2 // 2--3 / p2--p3
|
||||
,2,1,3 // | | p0---p1 / |
|
||||
}; // 0--1 / / |
|
||||
// n0a p0----p1
|
||||
void main()
|
||||
{
|
||||
int k = ks[gl_VertexID % 6];
|
||||
@@ -44,8 +47,8 @@ void main()
|
||||
vec4 p1 = data[indices[i0+1]].pos;
|
||||
vec3 n0a = data[indices[i0+2]].pos.xyz;
|
||||
vec3 n1a = data[indices[i0+3]].pos.xyz;
|
||||
vec3 closepoint = closestPointOnSeg3(p0.xyz,p1.xyz,lightPos);
|
||||
float ru2 = radiusUniform * radiusUniform;
|
||||
vec3 closepoint = closestPointOnSeg3(p0.xyz,p1.xyz,lightPos.xyz);
|
||||
float ru2 = colrad.w * colrad.w;
|
||||
vec4 mid = 0.5 * (p0 + p1);
|
||||
vec3 n0 = cross(p1.xyz - p0.xyz, n0a - p0.xyz);
|
||||
vec3 n1 = cross(p0.xyz - p1.xyz, n1a - p1.xyz);
|
||||
@@ -53,15 +56,15 @@ void main()
|
||||
vec3 lightDir2 = p1.xyz - lightPos.xyz;
|
||||
vec4 p2 = shiftNear(p0);
|
||||
vec4 p3 = shiftNear(p1);
|
||||
// first test if the edge is part of the silhouette
|
||||
// that is, if the normals of the faces connected by the edge point are in
|
||||
// test if the edge is part of the silhouette
|
||||
// that is, if the slopes of the faces connected to the edge are in
|
||||
// "different directions" wrt the light direction
|
||||
if (dot(n0, lightDir) * dot(n1, lightDir) <= 0 &&
|
||||
(dot(lightDir, lightDir) < ru2 || dot(lightDir2, lightDir2) < ru2))
|
||||
// using <= rather than < seems to get rid of overlapping shadow
|
||||
// artefacts
|
||||
{
|
||||
if (dot(n0, lightDir) > 0)
|
||||
if (dot(n0, lightDir) < 0)
|
||||
{
|
||||
vec4 sp[4] = {p1,p0,p3,p2};
|
||||
gl_Position = theMat * sp[k];}
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
#version 450 core
|
||||
layout(points) in;
|
||||
//layout(triangle_strip, max_vertices = 18) out;
|
||||
layout(triangle_strip, max_vertices = 9) out;
|
||||
layout(std140, binding = 0) uniform TheMat { mat4 theMat; };
|
||||
layout(location=0) uniform vec3 lightPos;
|
||||
layout(location=1) uniform float rad;
|
||||
//float rad = rad;
|
||||
// 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.438312149 UTC
|
||||
vec2 closestPointOnLine (vec2 a,vec2 b, vec2 p) {
|
||||
float x = closestPointOnLineParam(a,b,p);
|
||||
return a + (x * (b- a));
|
||||
}
|
||||
vec2 invclosestPointOnLine (vec2 a,vec2 b, vec2 p) {
|
||||
float x = dot (p-a,p-a)/ dot(p-a,b-a);
|
||||
return a + x*(b- a);
|
||||
}
|
||||
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));
|
||||
}
|
||||
// the following does NOT check for division by zero: do not reuse this unless
|
||||
// you are certain this cannot happen
|
||||
vec2 intersectLL(vec2 p1,vec2 p2,vec2 q1,vec2 q2){
|
||||
float den = detV (p1-p2,q1-q2);
|
||||
float t = detV (p1-q1,q1-q2);
|
||||
return p1 + (t/den)*(p2-p1);
|
||||
}
|
||||
// constructs a "bridge" shape
|
||||
void main() {
|
||||
vec2 p1 = gl_in[0].gl_Position.xy;
|
||||
vec2 p2 = gl_in[0].gl_Position.zw;
|
||||
vec2 closepoint = closestPointOnSeg(p1,p2,lightPos.xy);
|
||||
if (isLHS(p1 - lightPos.xy, p2 - lightPos.xy) < 0 && distance(closepoint,lightPos.xy) < rad) {
|
||||
vec2 xxxy = p1 + (0.25 * (p2 -p1));
|
||||
vec2 xt = shift(xxxy);
|
||||
vec2 xo = invclosestPointOnLine(lightPos.xy,p1,xt);
|
||||
vec2 xyyy = p1 + (0.75 * (p2 -p1));
|
||||
vec2 yt = shift(xyyy);
|
||||
vec2 yo = invclosestPointOnLine(lightPos.xy,p2,yt);
|
||||
|
||||
vec2 xoo = (distance(xo, lightPos.xy) < distance(p1, lightPos.xy)
|
||||
|| distance(p1,lightPos.xy)>rad
|
||||
? p1 : xo);
|
||||
vec2 yoo = (distance(yo, lightPos.xy) < distance(p2, lightPos.xy)
|
||||
|| distance(p2,lightPos.xy)>rad
|
||||
? p2 : yo);
|
||||
|
||||
vec2 mo = intersectLL(xoo,xt,yoo,yt);
|
||||
|
||||
vec2 closeshift = (rad * normalize(closepoint - lightPos.xy)) + lightPos.xy - closepoint;
|
||||
vec2 shifto = (rad * normalize(closepoint - lightPos.xy)) + closepoint;
|
||||
vec2 p1o = vec2( distance(p1,lightPos.xy) > rad ? p1 : shift(p1) );
|
||||
//vec2 p1o = xoo;
|
||||
vec2 p2o = vec2( distance(p2,lightPos.xy) > rad ? p2 : shift(p2) );
|
||||
//vec2 p2o = yoo;
|
||||
|
||||
gl_Position = theMat * vec4(p1o,-500,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p1,-500,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p1o,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p1,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(shifto,100,1); EmitVertex();
|
||||
//gl_Position = theMat * vec4(xt,100,1); EmitVertex();
|
||||
//gl_Position = theMat * vec4(mo,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p2,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p2o,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p2,-500,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p2o,-500,1); EmitVertex();
|
||||
EndPrimitive();
|
||||
// be carefull with the winding...
|
||||
|
||||
EndPrimitive();
|
||||
} else {
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
#version 450 core
|
||||
struct PosTex { vec4 pospos; vec4 texang; };
|
||||
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
|
||||
layout (std140, binding = 1) uniform TheLight { vec4 lightPos; vec4 colrad; };
|
||||
layout (std430, binding = 2) readonly buffer Pos { PosTex data[]; };
|
||||
layout(location=0) uniform vec3 lightPos;
|
||||
layout(location=1) uniform float rad;
|
||||
float rad = colrad.w;
|
||||
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
|
||||
{5,7,1 // 6----7
|
||||
,7,3,1 // /| /|
|
||||
,7,6,3 // 2-+--3 |
|
||||
,6,2,3 // | 4 | 5
|
||||
,6,4,2 // 0 1
|
||||
,4,0,2
|
||||
};
|
||||
vec2 shift(vec2 p) {
|
||||
return vec2(lightPos.xy + (rad * normalize(p - lightPos.xy)));
|
||||
|
||||
Reference in New Issue
Block a user