This commit is contained in:
2023-03-10 09:39:40 +00:00
parent b1750ad028
commit dc3faeed63
8 changed files with 138 additions and 46 deletions
+94 -11
View File
@@ -42,7 +42,9 @@ createLightMap ::
TO ->
(Point3 -> Float -> IO ()) -> -- attempt at drawing shadow not using geo shader
IO ()
createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUShadows = do
createLightMap pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos drawCPUShadows = case shadsdrawtype of
InstancingShads -> instanceLightMap pdata lightPoints nWalls nSils nCaps toPos
_ -> do
let llinesShad = _lightingLineShadowShader pdata
lcapShad = _lightingCapShader pdata
lwallShad = _lightingWallShadShader pdata
@@ -85,16 +87,12 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh
(marshalEPrimitiveMode $ _shadPrim' lwallShad)
0
(fromIntegral nWalls)
case drawObjShads of
case shadsdrawtype of
GeoObjShads -> do
--draw silhouette shadows
--currentProgram $= Just (_shadProg llinesShad)
--uniform (_shadUnis llinesShad V.! 0) $= Vector3 x y z
--uniform (_shadUnis llinesShad V.! 1) $= rad
glUseProgram (_shadProg' llinesShad)
glUniform3f (_shadUnis' llinesShad V.! 0) x y z
glUniform1f (_shadUnis' llinesShad V.! 1) rad
--bindVertexArrayObject $= Just (_vaoName $ _shadVAO' llinesShad)
glBindVertexArray (_vaoName $ _shadVAO' llinesShad)
glDrawElements
(marshalEPrimitiveMode $ _shadPrim' llinesShad)
@@ -104,12 +102,8 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh
--draw caps on the near plane as required
glEnable GL_CULL_FACE
glCullFace GL_BACK
--cullFace $= Just Back
--currentProgram $= Just (_shadProg lcapShad)
--uniform (_shadUnis lcapShad V.! 0) $= Vector3 x y z
glUseProgram (_shadProg' lcapShad)
glUniform3f (_shadUnis' lcapShad V.! 0) x y z
--bindVertexArrayObject $= lcapShad ^? shadVAO' . vaoName --Just (_vao $ _shadVAO lcapShad)
glBindVertexArray $ lcapShad ^. shadVAO' . vaoName --Just (_vao $ _shadVAO lcapShad)
glDrawElements
(marshalEPrimitiveMode $ _shadPrim' lcapShad)
@@ -117,7 +111,96 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh
GL_UNSIGNED_SHORT
nullPtr
CPUObjShads -> drawCPUShadows (V3 x y z) rad
_ -> return ()
NoObjShads -> return ()
--draw lightmap itself
glEnable GL_DEPTH_TEST
glDepthFunc GL_ALWAYS
--depthFunc $= Just Always
-- bind world position texture
bindTO toPos
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
--stencilOp $= (OpKeep, OpKeep, OpKeep)
glStencilFunc GL_EQUAL 0 255
--currentProgram $= ltextShad ^? shadProg --Just (_shadProg ltextShad)
--uniform (_shadUnis ltextShad V.! 0) $= Vector3 x y z
--uniform (_shadUnis ltextShad V.! 1) $= Vector4 r g b rad
glUseProgram (ltextShad ^. shadProg') --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)
glBindVertexArray $ ltextShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO ltextShad)
glDrawArrays
(marshalEPrimitiveMode (_shadPrim' ltextShad))
0
(fromIntegral (4 :: Int))
--cleanup: may not be necessary, depending on what comes after...
glDisable GL_CULL_FACE
glDisable GL_STENCIL_TEST
instanceLightMap pdata lightPoints nWalls nSils nCaps toPos = do
let llinesShad = _lightingLineShadowShader pdata
lcapShad = _lightingCapShader pdata
lwallShad = _lightingWallShadShader pdata
ltextShad = _lightingTextureShader pdata
-- we assume that the renderbuffer's depth has been correctly set elsewhere
-- we will not be changing that here
glDepthMask GL_FALSE
-- clearColor is specified differently in preloadRender
-- the colors are inverted
glClearColor 1 1 1 1
glClear GL_COLOR_BUFFER_BIT
-- for each of the lights:
-- 1. stencil out the shadows from this light's point of view
-- 2. calculate lighting based on each fragment's position
-- 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
-- setup stencil
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
glUniform3f (_shadUnis' lwallShad V.! 0) x y z
--bindVertexArrayObject $= lwallShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad)
glBindVertexArray $ lwallShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad)
glDrawArrays
(marshalEPrimitiveMode $ _shadPrim' lwallShad)
0
(fromIntegral nWalls)
--draw silhouette shadows
glUseProgram (_shadProg' llinesShad)
glUniform3f (_shadUnis' llinesShad V.! 0) x y z
glUniform1f (_shadUnis' llinesShad V.! 1) rad
glBindVertexArray (_vaoName $ _shadVAO' llinesShad)
glDrawElements
(marshalEPrimitiveMode $ _shadPrim' llinesShad)
(fromIntegral nSils)
GL_UNSIGNED_SHORT
nullPtr
--draw caps on the near plane as required
glEnable GL_CULL_FACE
glCullFace GL_BACK
glUseProgram (_shadProg' lcapShad)
glUniform3f (_shadUnis' lcapShad V.! 0) x y z
glBindVertexArray $ lcapShad ^. shadVAO' . vaoName --Just (_vao $ _shadVAO lcapShad)
glDrawElements
(marshalEPrimitiveMode $ _shadPrim' lcapShad)
(fromIntegral nCaps)
GL_UNSIGNED_SHORT
nullPtr
--draw lightmap itself
glEnable GL_DEPTH_TEST
glDepthFunc GL_ALWAYS