Continue work on shadow rendering
This commit is contained in:
+21
-27
@@ -50,6 +50,7 @@ createLightMap ::
|
||||
createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos drawCPUShadows = case shadsdrawtype of
|
||||
InstancingShads -> instanceLightMap cfig pdata lightPoints nWalls nSils nCaps toPos
|
||||
NoShadows -> do
|
||||
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata)))
|
||||
let ltextShad = _lightingTextureShader pdata
|
||||
-- we assume that the renderbuffer's depth has been correctly set elsewhere
|
||||
-- we will not be changing that here
|
||||
@@ -64,10 +65,7 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
|
||||
-- to consider: adding normals/a "material" for each fragment
|
||||
glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR
|
||||
glEnable GL_STENCIL_TEST
|
||||
--stencilTest $= Enabled
|
||||
glStencilOpSeparate GL_FRONT GL_KEEP GL_KEEP GL_INCR_WRAP
|
||||
--stencilOpSeparate Front $= (OpKeep, OpKeep, OpIncrWrap)
|
||||
--stencilOpSeparate Back $= (OpKeep, OpKeep, OpDecrWrap)
|
||||
glStencilOpSeparate GL_BACK GL_KEEP GL_KEEP GL_DECR_WRAP
|
||||
flip VFSM.mapM_ (VFSM.fromList lightPoints) $ \(V3 x y z, rad, V3 r g b) -> do
|
||||
glDepthFunc GL_LESS
|
||||
@@ -75,7 +73,6 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
|
||||
glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE
|
||||
glClear GL_STENCIL_BUFFER_BIT
|
||||
glDisable GL_CULL_FACE
|
||||
--cullFace $= Nothing
|
||||
glStencilFunc GL_ALWAYS 0 255
|
||||
--draw lightmap itself
|
||||
glDepthFunc GL_ALWAYS
|
||||
@@ -83,7 +80,7 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
|
||||
bindTO toPos
|
||||
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
|
||||
glStencilFunc GL_EQUAL 0 255
|
||||
glUseProgram (ltextShad ^. shadProg') --Just (_shadProg ltextShad)
|
||||
glUseProgram (ltextShad ^. shadName) --Just (_shadProg ltextShad)
|
||||
glUniform3f (_shadUnis' ltextShad V.! 0) x y z
|
||||
glUniform4f (_shadUnis' ltextShad V.! 1) r g b rad
|
||||
--bindVertexArrayObject $= ltextShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO ltextShad)
|
||||
@@ -107,6 +104,7 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
|
||||
glDepthFunc GL_ALWAYS
|
||||
glDepthMask GL_FALSE
|
||||
_ -> do
|
||||
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata)))
|
||||
let llinesShad = _lightingLineShadowShader pdata
|
||||
lcapShad = _lightingCapShader pdata
|
||||
lwallShad = _lightingWallShadShader pdata
|
||||
@@ -124,10 +122,7 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
|
||||
-- to consider: adding normals/a "material" for each fragment
|
||||
glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR
|
||||
glEnable GL_STENCIL_TEST
|
||||
--stencilTest $= Enabled
|
||||
glStencilOpSeparate GL_FRONT GL_KEEP GL_KEEP GL_INCR_WRAP
|
||||
--stencilOpSeparate Front $= (OpKeep, OpKeep, OpIncrWrap)
|
||||
--stencilOpSeparate Back $= (OpKeep, OpKeep, OpDecrWrap)
|
||||
glStencilOpSeparate GL_BACK GL_KEEP GL_KEEP GL_DECR_WRAP
|
||||
flip VFSM.mapM_ (VFSM.fromList lightPoints) $ \(V3 x y z, rad, V3 r g b) -> do
|
||||
glDepthFunc GL_LESS
|
||||
@@ -135,15 +130,11 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
|
||||
glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE
|
||||
glClear GL_STENCIL_BUFFER_BIT
|
||||
glDisable GL_CULL_FACE
|
||||
--cullFace $= Nothing
|
||||
glStencilFunc GL_ALWAYS 0 255
|
||||
--draw wall shadows
|
||||
--currentProgram $= Just (_shadProg lwallShad)
|
||||
glUseProgram (_shadProg' lwallShad)
|
||||
--uniform (_shadUnis lwallShad V.! 0)
|
||||
-- $= Vector3 x y z
|
||||
glUseProgram (_shadName lwallShad)
|
||||
glUniform3f (_shadUnis' lwallShad V.! 0) x y z
|
||||
--bindVertexArrayObject $= lwallShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad)
|
||||
glUniform1f (_shadUnis' lwallShad V.! 1) rad
|
||||
glBindVertexArray $ lwallShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad)
|
||||
glDrawArrays
|
||||
(marshalEPrimitiveMode $ _shadPrim' lwallShad)
|
||||
@@ -152,7 +143,8 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
|
||||
case shadsdrawtype of
|
||||
GeoObjShads -> do
|
||||
--draw silhouette shadows
|
||||
glUseProgram (_shadProg' llinesShad)
|
||||
glEnable GL_DEPTH_CLAMP
|
||||
glUseProgram (_shadName llinesShad)
|
||||
glUniform3f (_shadUnis' llinesShad V.! 0) x y z
|
||||
glUniform1f (_shadUnis' llinesShad V.! 1) rad
|
||||
glBindVertexArray (_vaoName $ _shadVAO' llinesShad)
|
||||
@@ -164,7 +156,8 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
|
||||
--draw caps on the near plane as required
|
||||
glEnable GL_CULL_FACE
|
||||
glCullFace GL_BACK
|
||||
glUseProgram (_shadProg' lcapShad)
|
||||
glCullFace GL_FRONT
|
||||
glUseProgram (_shadName lcapShad)
|
||||
glUniform3f (_shadUnis' lcapShad V.! 0) x y z
|
||||
glBindVertexArray $ lcapShad ^. shadVAO' . vaoName --Just (_vao $ _shadVAO lcapShad)
|
||||
glDrawElements
|
||||
@@ -172,15 +165,17 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
|
||||
(fromIntegral nCaps)
|
||||
GL_UNSIGNED_SHORT
|
||||
nullPtr
|
||||
glDisable GL_DEPTH_CLAMP
|
||||
CPUObjShads -> drawCPUShadows (V3 x y z) rad
|
||||
NoObjShads -> return ()
|
||||
--draw lightmap itself
|
||||
glDepthFunc GL_ALWAYS
|
||||
-- bind world position texture
|
||||
glDisable GL_CULL_FACE
|
||||
bindTO toPos
|
||||
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
|
||||
glStencilFunc GL_EQUAL 0 255
|
||||
glUseProgram (ltextShad ^. shadProg') --Just (_shadProg ltextShad)
|
||||
glUseProgram (ltextShad ^. shadName) --Just (_shadProg ltextShad)
|
||||
glUniform3f (_shadUnis' ltextShad V.! 0) x y z
|
||||
glUniform4f (_shadUnis' ltextShad V.! 1) r g b rad
|
||||
--bindVertexArrayObject $= ltextShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO ltextShad)
|
||||
@@ -190,7 +185,6 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
|
||||
0
|
||||
(fromIntegral (4 :: Int))
|
||||
--cleanup: may not be necessary, depending on what comes after...
|
||||
glDisable GL_CULL_FACE
|
||||
glDisable GL_STENCIL_TEST
|
||||
|
||||
lightsToArray :: [(Point3, Float, Point3)] -> [Float]
|
||||
@@ -252,14 +246,14 @@ instanceLightMap cfig pdata lightPoints nWalls nSils nCaps toPos = do
|
||||
glDisable GL_CULL_FACE
|
||||
glStencilFunc GL_ALWAYS 0 255
|
||||
--draw wall shadows
|
||||
glUseProgram $ pdata ^. shadowWallShader . shadProg'
|
||||
glBindVertexArray $ pdata ^. shadowWallShader . shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad)
|
||||
glUseProgram $ pdata ^. shadowWallShader . shadName
|
||||
glBindVertexArray $ pdata ^. shadowWallShader . shadVAO' . vaoName
|
||||
glDrawArrays
|
||||
(marshalEPrimitiveMode $ pdata ^. shadowWallShader . shadPrim')
|
||||
0
|
||||
(fromIntegral nWalls)
|
||||
--draw silhouette shadows
|
||||
glUseProgram $ pdata ^. shadowEdgeShader . shadProg'
|
||||
glUseProgram $ pdata ^. shadowEdgeShader . shadName
|
||||
glBindVertexArray $ pdata ^. shadowEdgeShader . shadVAO' . vaoName
|
||||
glDrawElements
|
||||
(marshalEPrimitiveMode $ pdata ^. shadowEdgeShader . shadPrim')
|
||||
@@ -267,9 +261,10 @@ instanceLightMap cfig pdata lightPoints nWalls nSils nCaps toPos = do
|
||||
GL_UNSIGNED_SHORT
|
||||
nullPtr
|
||||
--draw caps on the near plane as required
|
||||
glEnable GL_CULL_FACE
|
||||
--glEnable GL_CULL_FACE
|
||||
glCullFace GL_BACK
|
||||
glUseProgram (_shadProg' lcapShad)
|
||||
--glCullFace GL_FRONT
|
||||
glUseProgram (_shadName lcapShad)
|
||||
glBindVertexArray $ lcapShad ^. shadVAO' . vaoName
|
||||
glDrawElements
|
||||
(marshalEPrimitiveMode $ _shadPrim' lcapShad)
|
||||
@@ -280,15 +275,14 @@ instanceLightMap cfig pdata lightPoints nWalls nSils nCaps toPos = do
|
||||
glDepthFunc GL_ALWAYS
|
||||
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
|
||||
glStencilFunc GL_EQUAL 0 255
|
||||
glUseProgram (pdata ^. shadowLightShader . shadProg')
|
||||
glUseProgram (pdata ^. shadowLightShader . shadName)
|
||||
-- bind world position texture
|
||||
bindTO toPos
|
||||
glBindVertexArray $ pdata ^. shadowLightShader . shadVAO' . vaoName
|
||||
-- glBindVertexArray $ pdata ^. shadowLightShader . shadVAO' . vaoName
|
||||
glDrawArrays
|
||||
(marshalEPrimitiveMode $ pdata ^. shadowLightShader . shadPrim')
|
||||
0
|
||||
1
|
||||
-- this was the end of the loop
|
||||
glDisable GL_CULL_FACE
|
||||
glDisable GL_STENCIL_TEST
|
||||
--draw to the lighting framebuffer here
|
||||
@@ -298,7 +292,7 @@ instanceLightMap cfig pdata lightPoints nWalls nSils nCaps toPos = do
|
||||
glBindTexture GL_TEXTURE_2D_ARRAY (pdata ^. fboShadow . _2 . _1 . unTO)
|
||||
glEnable GL_BLEND
|
||||
glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR
|
||||
glUseProgram (pdata ^. shadowCombineShader . shadProg') --Just (_shadProg ltextShad)
|
||||
glUseProgram (pdata ^. shadowCombineShader . shadName)
|
||||
glDrawArrays
|
||||
(marshalEPrimitiveMode EPoints)
|
||||
0
|
||||
|
||||
Reference in New Issue
Block a user