From b012d3c41e791cccdbdd58feb04abd734ead298e Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 12 Nov 2025 23:10:33 +0000 Subject: [PATCH] Cleanup, correcly filter unimportant shadow silhouettes --- shader/lighting/cap.vert | 17 ++++------------- shader/lighting/lineShadow.vert | 8 ++++---- src/Render.hs | 4 ++-- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/shader/lighting/cap.vert b/shader/lighting/cap.vert index 8b25370a1..c8440a6a1 100644 --- a/shader/lighting/cap.vert +++ b/shader/lighting/cap.vert @@ -1,15 +1,16 @@ #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[]; }; -layout(location=0)uniform vec3 lightPos; -layout(location=1)uniform vec4 lumRad; +//layout(location=0)uniform vec3 lightPos; +//layout(location=1)uniform vec4 lumRad; 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) ; @@ -27,13 +28,3 @@ void main() { : vec4(1,1,1,0) ); } -//layout (location = 0) in vec4 position; -//layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; -//uniform vec3 lightPos; -//uniform vec4 lumRad; -//out float drawbit; -//void main() -//{ -// gl_Position = vec4(position.xyz,1); -// drawbit = position.w; -//} diff --git a/shader/lighting/lineShadow.vert b/shader/lighting/lineShadow.vert index 7562f9474..c7d984be8 100644 --- a/shader/lighting/lineShadow.vert +++ b/shader/lighting/lineShadow.vert @@ -54,16 +54,16 @@ void main() vec3 n1 = cross(p0.xyz - p1.xyz, n1a - p1.xyz); vec3 lightDir = p0.xyz - lightPos.xyz; vec3 lightDir2 = p1.xyz - lightPos.xyz; - vec4 p2 = shiftNear(p0); - vec4 p3 = shiftNear(p1); // test if the edge is part of the silhouette - // that is, if the slopes of the faces connected to the edge are in + // that is, if the normals of the faces connected to the edge are in // "different directions" wrt the light direction - if (dot(n0, lightDir) * dot(n1, lightDir) <= 0 && + if (p0.w==1 && 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) { vec4 sp[4] = {p1,p0,p3,p2}; diff --git a/src/Render.hs b/src/Render.hs index 22a15b10d..027650a13 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -188,8 +188,8 @@ renderShadows shadrendertype nWalls nSils nCaps positiontexture normaltexture li glEnable GL_CULL_FACE glCullFace GL_BACK glUseProgram (_shaderUINT lcapShad) - glUniform3f 0 x y z - glUniform4f 1 r g b rad +-- glUniform3f 0 x y z +-- glUniform4f 1 r g b rad -- glFrontFace(GL_CW) glDrawArrays GL_TRIANGLES 0 (fromIntegral nCaps) -- glFrontFace(GL_CCW)