From a2183151be0580b751182d9bb3191ca8f54af885 Mon Sep 17 00:00:00 2001 From: jgk Date: Sat, 20 Mar 2021 12:28:19 +0100 Subject: [PATCH] Lower walls and performance improvement for shadows --- shader/wallShadow.geom | 24 ++++++++++++++---------- src/Dodge/Rendering.hs | 4 ++-- src/Picture/Render.hs | 6 +++--- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/shader/wallShadow.geom b/shader/wallShadow.geom index 99a7fa666..98efbb3aa 100644 --- a/shader/wallShadow.geom +++ b/shader/wallShadow.geom @@ -6,29 +6,28 @@ uniform vec2 lightPos; uniform mat4 perpMat; uniform mat4 worldMat; -vec2 lightPosa = lightPos; +vec2 lightPosa = ( perpMat * vec4(lightPos,0,1) ).xy; vec4 shift (vec4 p) -{ return vec4 (p.xy + (200 * (p.xy-lightPosa)), 0 , 1); +{ return vec4 (p.xy + (200 * (p.xy-lightPos)), 0 , 1); } float isLHS (vec2 startV, vec2 testV) { return sign( -startV.x * testV.y + startV.y * testV.x); } -// construct a box with opening on bottom face - +// 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 - lightPosa, p2.xy - lightPosa) < 0) +if (isLHS (p1.xy - lightPos, p2.xy - lightPos) < 0) { -vec4 p3 = vec4 (p1.xy,-0.5,1); -vec4 p4 = vec4 (p2.xy,-0.5,1); +vec4 p3 = vec4 (p1.xy,-0.2,1); +vec4 p4 = vec4 (p2.xy,-0.2,1); vec4 p5 = shift(p1); vec4 p6 = shift(p2); -vec4 p7 = vec4 (p6.xy,-0.5,1); -vec4 p8 = vec4 (p5.xy,-0.5,1); +vec4 p7 = vec4 (p6.xy,-0.2,1); +vec4 p8 = vec4 (p5.xy,-0.2,1); vec4 a1 = perpMat * p1; vec4 a2 = perpMat * p2; @@ -39,6 +38,11 @@ vec4 a6 = perpMat * p6; vec4 a7 = perpMat * p7; vec4 a8 = perpMat * p8; +// gl_Position = a1; EmitVertex(); +// gl_Position = a5; EmitVertex(); +// gl_Position = a2; EmitVertex(); +// gl_Position = a6; EmitVertex(); + gl_Position = a4; EmitVertex(); gl_Position = a3; EmitVertex(); gl_Position = a7; EmitVertex(); @@ -50,7 +54,7 @@ vec4 a8 = perpMat * p8; gl_Position = a2; EmitVertex(); gl_Position = a7; EmitVertex(); gl_Position = a6; EmitVertex(); -// gl_Position = a5; EmitVertex(); + EndPrimitive(); } else {} } diff --git a/src/Dodge/Rendering.hs b/src/Dodge/Rendering.hs index 6e2669140..7f9b4c689 100644 --- a/src/Dodge/Rendering.hs +++ b/src/Dodge/Rendering.hs @@ -122,8 +122,8 @@ worldPictures w where tst x y sc t = translate x y $ scale sc sc $ color white $ text t testPic :: World -> [Picture] -testPic w = --[blank] - [setLayer 1 $ onLayerL [99] $ bezierQuad white red 5 5 (00,00) (300,305) (50,000) ] +testPic w = [blank] + -- [setLayer 1 $ onLayerL [99] $ bezierQuad white red 5 5 (00,00) (300,305) (50,000) ] -- $ uncurry translate (mouseWorldPos w) diff --git a/src/Picture/Render.hs b/src/Picture/Render.hs index fe0c51b8d..157b2e7a4 100644 --- a/src/Picture/Render.hs +++ b/src/Picture/Render.hs @@ -68,9 +68,7 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints currentProgram $= Just (_shaderProgram $ _wallShadowShader pdata) uniform (head $ fromJust $ _shaderCustomUnis $ _wallShadowShader pdata) - $= Vector2 viewFromx viewFromy -- hopefully this draws as if from the center - -- it does, but this is not correct when - -- the camera center is not the player position + $= Vector2 viewFromx viewFromy pmat <- (newMatrix RowMajor $ perspectiveMatrix rot zoom (tranx,trany) (winx,winy) (viewFromx,viewFromy) ) :: IO (GLmatrix GLfloat) @@ -85,6 +83,7 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints stencilTest $= Enabled forM_ lightPoints $ \(x,y,r,lum) -> do -- depthFunc $= Just Less + colorMask $= (Color4 Disabled Disabled Disabled Disabled) clear [StencilBuffer] cullFace $= Just Back -- stencilOp $= (OpKeep,OpKeep,OpReplace) @@ -103,6 +102,7 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints cullFace $= Nothing + colorMask $= (Color4 Enabled Enabled Enabled Enabled) let lightPtr = (\(_,ptr,_) -> ptr) $ head $ _vaoBufferTargets $ _shaderVAO $ _lightSourceShader pdata (x',y') = zTran $ rotateV (0 - rot) $ (x,y) -.- (tranx,trany)