From f797530cbce137c1573919684fa8c9a99c228719 Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 30 Aug 2021 21:47:01 +0100 Subject: [PATCH] Use depth fail and front cap for geometry shadows (TODO back cap) --- shader/lighting/cap.geom | 2 +- src/Dodge/Default/World.hs | 3 ++- src/Render.hs | 14 +++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/shader/lighting/cap.geom b/shader/lighting/cap.geom index e808b3998..e7e4f1315 100644 --- a/shader/lighting/cap.geom +++ b/shader/lighting/cap.geom @@ -8,7 +8,7 @@ void main() vec4 p0 = gl_in[0].gl_Position ; vec4 p1 = gl_in[1].gl_Position ; vec4 p2 = gl_in[2].gl_Position ; - if ( dot( lightPos, cross( p0.xyz - p1.xyz, p1.xyz - p2.xyz)) < 0) + if ( dot( p0.xyz - lightPos, cross( p0.xyz - p1.xyz, p1.xyz - p2.xyz)) < 0) { gl_Position = theMat * p0; EmitVertex(); gl_Position = theMat * p1; EmitVertex(); diff --git a/src/Dodge/Default/World.hs b/src/Dodge/Default/World.hs index 9fdafbe2e..84e099262 100644 --- a/src/Dodge/Default/World.hs +++ b/src/Dodge/Default/World.hs @@ -93,7 +93,8 @@ youLight = TLS { _tlsPos = V3 0 0 0 ,_tlsRad = 300 ,_tlsIntensity = 0.1 - ,_tlsUpdate = \w _ -> (w, Just (youLight {_tlsPos = f $ _crPos (you w)})) + ,_tlsUpdate = \w _ -> (w, Nothing) + --,_tlsUpdate = \w _ -> (w, Just (youLight {_tlsPos = f $ _crPos (you w)})) ,_tlsTime = 0 } where diff --git a/src/Render.hs b/src/Render.hs index 778364223..913e6aacd 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -38,6 +38,7 @@ createLightMap pdata lightPoints nWalls nSils nsurfVs = do clear [ColorBuffer,DepthBuffer] --colorMask $= Color4 Disabled Disabled Disabled Disabled cullFace $= Just Back + cullFace $= Nothing -- we assume that the camera position uniforms have been correctly set elsewhere -- draw wall surfaces from the camera's point of view in order to set z buffer drawShader (_lightingWallShader pdata) nWalls @@ -59,6 +60,7 @@ createLightMap pdata lightPoints nWalls nSils nsurfVs = do depthFunc $= Just Lequal flip VS.mapM_ (VS.fromList lightPoints) $ \(V3 x y z,rad,V3 r g b) -> do --forM_ lightPoints $ \(V3 x y z,r,lum) -> do + depthFunc $= Just Less -- stencil out shadows colorMask $= Color4 Disabled Disabled Disabled Disabled clear [StencilBuffer] @@ -72,6 +74,8 @@ createLightMap pdata lightPoints nWalls nSils nsurfVs = do drawShader (_lightingOccludeShader pdata) nWalls --stencilOp $= (OpKeep,OpDecr,OpKeep) + stencilOpSeparate Front $= (OpKeep,OpDecrWrap,OpKeep) + stencilOpSeparate Back $= (OpKeep,OpIncrWrap,OpKeep) currentProgram $= Just (_shaderProgram $ _lightingLineShadowShader pdata) uniform (head $ _shaderCustomUnis $ _lightingLineShadowShader pdata) $= Vector3 x y z @@ -79,8 +83,16 @@ createLightMap pdata lightPoints nWalls nSils nsurfVs = do drawShader (_lightingLineShadowShader pdata) nSils depthClamp $= Disabled + --stencilOp $= (OpKeep,OpDecrWrap,OpKeep) + currentProgram $= Just (_shaderProgram $ _lightingCapShader pdata) + uniform (head $ _shaderCustomUnis $ _lightingCapShader pdata) + $= Vector3 x y z + drawShader (_lightingCapShader pdata) (nSils - 6) + + depthFunc $= Just Lequal -- draw geometry surfaces - cullFace $= Just Back + --cullFace $= Just Back + cullFace $= Nothing --colorMask $= Color4 Disabled Disabled Disabled Enabled colorMask $= Color4 Enabled Enabled Enabled Enabled stencilOp $= (OpKeep,OpKeep,OpKeep)