Continue work on shadow rendering
This commit is contained in:
@@ -9,9 +9,9 @@ vec4 projNear (vec4 pos)
|
||||
// note we project to a specific height
|
||||
// this is quite brittle, not ideal
|
||||
vec3 dir = pos.xyz - lightPos ;
|
||||
float a = (140 - pos.z) / dir.z ;
|
||||
float a = (100 - pos.z) / dir.z ;
|
||||
vec2 xy = (pos.xyz + a * dir).xy ;
|
||||
return vec4 ( xy, 140 , 1) ;
|
||||
return vec4 ( xy, 100 , 1) ;
|
||||
}
|
||||
void main()
|
||||
{
|
||||
@@ -28,8 +28,8 @@ void main()
|
||||
// the front cap
|
||||
vec4 v1 = vec4 (0,0,1,0) ;
|
||||
gl_Position = theMat * projNear(p0); EmitVertex();
|
||||
gl_Position = theMat * projNear(p1); EmitVertex();
|
||||
gl_Position = theMat * projNear(p2); EmitVertex();
|
||||
gl_Position = theMat * projNear(p1); EmitVertex();
|
||||
EndPrimitive();
|
||||
}
|
||||
else {}
|
||||
|
||||
@@ -1,71 +1,91 @@
|
||||
#version 450 core
|
||||
layout (lines_adjacency) in;
|
||||
layout (triangle_strip, max_vertices = 4) out;
|
||||
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
|
||||
layout(lines_adjacency) in;
|
||||
layout(triangle_strip, max_vertices = 4) out;
|
||||
layout(std140, binding = 0) uniform TheMat { mat4 theMat; };
|
||||
uniform vec3 lightPos;
|
||||
uniform float radiusUniform;
|
||||
//vec4 shift (vec4 p) { return (vec4 (p.xyz + (lumRad.a*normalize(p.xyz-lightPos)), 1));}
|
||||
vec4 shift (vec4 p) { return (vec4 (p.xyz + (100000*(p.xyz-lightPos)), 1));}
|
||||
vec4 shiftBy (float x,vec4 p) { return (vec4 (lightPos + (x*normalize(p.xyz-lightPos)), 1));}
|
||||
//vec4 shift (vec4 p) { return (vec4 (lightPos + (lumRad.a*normalize(p.xyz-lightPos)), 1));}
|
||||
// vec4 shift (vec4 p) { return (vec4 (p.xyz +
|
||||
// (lumRad.a*normalize(p.xyz-lightPos)), 1));}
|
||||
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));}
|
||||
}
|
||||
}
|
||||
//vec3 closepoint =
|
||||
vec4 shift(vec4 p) { return (vec4(p.xyz + (100000 * (p.xyz - lightPos)), 1)); }
|
||||
vec4 shiftBy(float x, vec4 p) {
|
||||
return (vec4(lightPos + (x * normalize(p.xyz - lightPos)), 1));
|
||||
}
|
||||
// vec4 shift (vec4 p) { return (vec4 (lightPos +
|
||||
// (lumRad.a*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 = (140 - pos.z) / dir.z ;
|
||||
vec2 xy = (pos.xyz + a * dir).xy ;
|
||||
return vec4 ( xy, 140 , 1) ;
|
||||
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 shiftNear(vec4 pos)
|
||||
//{ vec4 sp = shiftBy(radiusUniform,pos);
|
||||
{ vec4 sp = shift(pos);
|
||||
if (sp.z > 140)
|
||||
{ return projNear(pos) ; }
|
||||
else
|
||||
{ return sp ; }
|
||||
}
|
||||
vec4 f (vec4 p) {return (theMat * p);}
|
||||
void main()
|
||||
{
|
||||
float ru2 = radiusUniform * radiusUniform ;
|
||||
vec4 p0 = gl_in[0].gl_Position;
|
||||
vec4 p1 = gl_in[1].gl_Position;
|
||||
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 n2 = n0 + n1; // assumes the summands are normalized
|
||||
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);
|
||||
if ( dot(n0 , lightDir) > 0)
|
||||
{
|
||||
gl_Position = f(p0); EmitVertex();
|
||||
gl_Position = f(p1); EmitVertex();
|
||||
gl_Position = f(p2); EmitVertex();
|
||||
gl_Position = f(p3); EmitVertex();
|
||||
}
|
||||
else
|
||||
{
|
||||
gl_Position = f(p1); EmitVertex();
|
||||
gl_Position = f(p0); EmitVertex();
|
||||
gl_Position = f(p3); EmitVertex();
|
||||
gl_Position = f(p2); EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
else { }
|
||||
vec4 sp = shift(pos);
|
||||
if (sp.z > 100) {
|
||||
return projNear(pos);
|
||||
} else {
|
||||
return sp;
|
||||
}
|
||||
}
|
||||
vec4 f(vec4 p) { return (theMat * p); }
|
||||
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 n2 = n0 + n1; // assumes the summands are normalized
|
||||
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);
|
||||
vec4 p2 = shiftNear(p0);
|
||||
vec4 p3 = shiftNear(p1);
|
||||
gl_Position = f(p0);
|
||||
EmitVertex();
|
||||
if (dot(n0, lightDir) > 0) {
|
||||
gl_Position = f(p2);
|
||||
EmitVertex();
|
||||
gl_Position = f(p1);
|
||||
EmitVertex();
|
||||
} else {
|
||||
gl_Position = f(p1);
|
||||
EmitVertex();
|
||||
gl_Position = f(p2);
|
||||
EmitVertex();
|
||||
}
|
||||
gl_Position = f(p3);
|
||||
EmitVertex();
|
||||
EndPrimitive();
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ uniform vec4 lumRad;
|
||||
uniform sampler2D screenTexture;
|
||||
in vec2 vTexPos;
|
||||
out vec4 fColor;
|
||||
void main()
|
||||
{
|
||||
vec3 distVec = texture(screenTexture,vTexPos).xyz - lightPos;
|
||||
float dist = dot(distVec,distVec);
|
||||
if (dist > lumRad.a) {discard;}
|
||||
float x = 1 - dist / lumRad.a ;
|
||||
vec3 c = (x * x * x) * lumRad.rgb ;
|
||||
fColor = vec4(c,0);
|
||||
float rad = lumRad.a;
|
||||
void main() {
|
||||
vec3 distVec = texture(screenTexture, vTexPos).xyz - lightPos;
|
||||
float dist = dot(distVec, distVec);
|
||||
if (dist > rad) {
|
||||
discard;
|
||||
}
|
||||
float x = 1 - dist / rad;
|
||||
vec3 c = (x * x * x) * lumRad.rgb;
|
||||
fColor = vec4(c, 0);
|
||||
}
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
#version 450 core
|
||||
layout (points) in;
|
||||
layout (triangle_strip, max_vertices = 8) out;
|
||||
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
|
||||
layout(points) in;
|
||||
layout(triangle_strip, max_vertices = 18) out;
|
||||
layout(std140, binding = 0) uniform TheMat { mat4 theMat; };
|
||||
uniform vec3 lightPos;
|
||||
vec4 shift (vec4 p)
|
||||
{ return vec4 (p.xy + (200 * (p.xy-lightPos.xy)), 0 , 1);
|
||||
uniform float rad;
|
||||
float rad2 = 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);
|
||||
}
|
||||
float isLHS (vec2 startV, vec2 testV)
|
||||
{
|
||||
return sign( -startV.x * testV.y + startV.y * testV.x);
|
||||
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 shift(vec2 p) {
|
||||
return vec2(lightPos.xy + (rad2 * normalize(p - lightPos.xy)));
|
||||
}
|
||||
float isLHS(vec2 startV, vec2 testV) {
|
||||
return sign(-startV.x * testV.y + startV.y * testV.x);
|
||||
}
|
||||
// construct a box with openings on bottom face and face away from wall
|
||||
void main()
|
||||
{
|
||||
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1);
|
||||
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1);
|
||||
if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0)
|
||||
{
|
||||
vec4 p3 = vec4 (p1.xy,100,1);
|
||||
vec4 p4 = vec4 (p2.xy,100,1);
|
||||
vec4 p5 = shift(p1);
|
||||
vec4 p6 = shift(p2);
|
||||
vec4 p7 = vec4 (p6.xy,100,1);
|
||||
vec4 p8 = vec4 (p5.xy,100,1);
|
||||
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) < rad2) {
|
||||
vec2 closeshift = (rad2 * normalize(closepoint - lightPos.xy)) + lightPos.xy - closepoint;
|
||||
vec2 p1cs = p1 + closeshift;
|
||||
vec2 p1o = vec2( distance(p1,lightPos.xy) > rad2 ? p1cs : shift(p1) );
|
||||
vec2 p2cs = p2 + closeshift;
|
||||
vec2 p2o = vec2( distance(p2,lightPos.xy) > rad2 ? p2cs : shift(p2) );
|
||||
|
||||
vec4 a1 = theMat * p1;
|
||||
vec4 a2 = theMat * p2;
|
||||
vec4 a3 = theMat * p3;
|
||||
vec4 a4 = theMat * p4;
|
||||
vec4 a5 = theMat * p5;
|
||||
vec4 a6 = theMat * p6;
|
||||
vec4 a7 = theMat * p7;
|
||||
vec4 a8 = theMat * p8;
|
||||
gl_Position = theMat * vec4(p1o,0,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p1,0,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p1o,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p1,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p1cs,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p2,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p2cs,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p2o,100,1); EmitVertex();
|
||||
EndPrimitive();
|
||||
|
||||
//gl_Position = a4; EmitVertex();
|
||||
//gl_Position = a3; EmitVertex();
|
||||
//gl_Position = a7; EmitVertex();
|
||||
//gl_Position = a8; EmitVertex();
|
||||
//gl_Position = a5; EmitVertex();
|
||||
//gl_Position = a3; EmitVertex();
|
||||
//gl_Position = a1; EmitVertex();
|
||||
//gl_Position = a4; EmitVertex();
|
||||
//gl_Position = a2; EmitVertex();
|
||||
//gl_Position = a7; EmitVertex();
|
||||
//gl_Position = a6; EmitVertex();
|
||||
|
||||
gl_Position = a1; EmitVertex();
|
||||
gl_Position = a5; EmitVertex();
|
||||
gl_Position = a3; EmitVertex();
|
||||
gl_Position = a8; EmitVertex();
|
||||
gl_Position = a4; EmitVertex();
|
||||
gl_Position = a7; EmitVertex();
|
||||
gl_Position = a2; EmitVertex();
|
||||
gl_Position = a6; EmitVertex();
|
||||
|
||||
//gl_Position = a5; EmitVertex();
|
||||
//gl_Position = a1; EmitVertex();
|
||||
//gl_Position = a8; EmitVertex();
|
||||
//gl_Position = a3; EmitVertex();
|
||||
//gl_Position = a7; EmitVertex();
|
||||
//gl_Position = a4; EmitVertex();
|
||||
//gl_Position = a6; EmitVertex();
|
||||
//gl_Position = a2; EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
} else {}
|
||||
// gl_Position = theMat * vec4(p2o,100,1); EmitVertex();
|
||||
// gl_Position = theMat * vec4(p2,100,1); EmitVertex();
|
||||
// gl_Position = theMat * vec4(p2o,0,1); EmitVertex();
|
||||
// gl_Position = theMat * vec4(p2,0,1); EmitVertex();
|
||||
|
||||
gl_Position = theMat * vec4(p2,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p2,0,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p2o,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p2o,0,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p2cs,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p2cs,0,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p1cs,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p1cs,0,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p1o,100,1); EmitVertex();
|
||||
gl_Position = theMat * vec4(p1o,0,1); EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,19 @@ vec4 shift(vec4 p) { return vec4(p.xy + (200 * (p.xy - lightPos.xy)), 0, 1); }
|
||||
float isLHS(vec2 startV, vec2 testV) {
|
||||
return sign(-startV.x * testV.y + startV.y * testV.x);
|
||||
}
|
||||
// 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.454374887 UTC
|
||||
// construct a box with openings on bottom face and face away from wall
|
||||
void main() {
|
||||
vec4 p1 = vec4(gl_in[0].gl_Position.xy, 0, 1);
|
||||
|
||||
Reference in New Issue
Block a user