Simplify ceiling oclusions

This commit is contained in:
2025-11-02 19:20:57 +00:00
parent 0d0c1a72e0
commit 2f0487a424
8 changed files with 178 additions and 171 deletions
+39 -51
View File
@@ -48,13 +48,9 @@ doDrawing' win pdata u = do
checkGLError "during drawing"
let w = _uvWorld u
cfig = _uvConfig u
rot = w ^. wCam . camRot
camzoom = w ^. wCam . camZoom
trans = w ^. wCam . camCenter
wins = V2 (windowXFloat cfig) (windowYFloat cfig)
(windowPoints, wallSPics, wallsToPoke) = wallsToDraw w
lightPoints = lightsToRender cfig (w ^. wCam) (w ^. cWorld . lWorld)
viewFroms@(V2 vfx vfy) = w ^. wCam . camViewFrom
--(V2 vfx vfy) = w ^. wCam . camViewFrom
shadV = _pictureShaders pdata
nFls = w ^. cWorld . numberFloorVerxs
nchs = w ^. cWorld . numberChasmVerxs
@@ -98,7 +94,6 @@ doDrawing' win pdata u = do
(pokeDust (pdata ^. cloudVBO . vboPtr) (pdata ^. cloudEBO . eboPtr))
(nCloudVs', nCloudIs')
(V.fromList $ w ^. cWorld . lWorld . dusts)
-- bind wall points, silhouette data, surface geometry
bufferShaderLayers shadV pokeCounts
mapM_
@@ -115,8 +110,7 @@ doDrawing' win pdata u = do
, (_silhouetteEBO pdata, nSilIndices)
]
-- set the coordinate uniform ready for drawing elements using world coordinates
withArray (perspectiveMatrixb rot camzoom trans wins viewFroms) $
glNamedBufferSubData (pdata ^. matUBO) 0 64
bufferPerspectiveMatrixUBO cfig (w ^. wCam) (pdata ^. matUBO)
setViewport _graphics_world_resolution cfig
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase . _1 . unFBO)
glDepthMask GL_TRUE
@@ -131,27 +125,29 @@ doDrawing' win pdata u = do
1
0
-- draw wall occlusions from the camera's point of view
glDisable GL_CULL_FACE
glEnable GL_STENCIL_TEST
glStencilFunc GL_NOTEQUAL 128 255
glStencilOp GL_KEEP GL_KEEP GL_REPLACE
glEnable GL_CULL_FACE
glCullFace GL_BACK
unless (debugOn Remove_LOS cfig) $ do
glUseProgram (pdata ^. ceilingStencilShader . shaderUINT)
glProgramUniform3f
(pdata ^. ceilingStencilShader . shaderUINT)
0
vfx
vfy
20
glProgramUniform1f
(pdata ^. ceilingStencilShader . shaderUINT)
1
1000 -- this should be the furthest on screen distance from the viewpoint
-- glProgramUniform3f
-- (pdata ^. ceilingStencilShader . shaderUINT)
-- 0
-- vfx
-- vfy
-- 20
-- glProgramUniform1f
-- (pdata ^. ceilingStencilShader . shaderUINT)
-- 1
-- 1000 -- this should be the furthest on screen distance from the viewpoint
glBindVertexArray $ pdata ^. ceilingStencilShader . shaderVAO . vaoName
glEnable GL_DEPTH_CLAMP
glDrawArrays
(_unPrimitiveMode $ pdata ^. ceilingStencilShader . shaderPrimitive)
0
(fromIntegral trueNWalls)
glDisable GL_DEPTH_CLAMP
glStencilMask 127 -- to alter last seven bits
glStencilOp GL_KEEP GL_KEEP GL_KEEP
-- clear color and normals
@@ -162,7 +158,6 @@ doDrawing' win pdata u = do
withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $
glNamedFramebufferDrawBuffers (pdata ^. fboBase . _1 . unFBO) 3
--draw walls onto base buffer
-- maybe cull faces? maybe do this before?
glEnable GL_CULL_FACE
glCullFace GL_BACK
glUseProgram (pdata ^. wallShader . shaderUINT)
@@ -185,7 +180,7 @@ doDrawing' win pdata u = do
glBindVertexArray $ pdata ^. chasmShader . shaderVAO . vaoName
glDepthMask GL_FALSE
glDrawBuffer GL_NONE
glStencilOp GL_INCR GL_INCR GL_INCR
glStencilOp GL_KEEP GL_KEEP GL_INCR
with 0 $
glClearNamedFramebufferiv
(pdata ^. fboBase . _1 . unFBO)
@@ -206,11 +201,9 @@ doDrawing' win pdata u = do
(_unPrimitiveMode $ pdata ^. floorShader . shaderPrimitive)
0
(fromIntegral nFls)
glDisable GL_STENCIL_TEST
--glDisable GL_STENCIL_TEST
glDisable GL_CULL_FACE
glEnable GL_BLEND
-- reset stencil to not draw on ceilings
glStencilFunc GL_NOTEQUAL 128 255
--draw lightmap into its own buffer
createLightMap
cfig
@@ -232,16 +225,11 @@ doDrawing' win pdata u = do
glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR
drawShader (_fullscreenShader pdata) 4
with GL_COLOR_ATTACHMENT0 $
glInvalidateNamedFramebufferData
(pdata ^. fboLighting . _1 . unFBO)
1
glInvalidateNamedFramebufferData (pdata ^. fboLighting . _1 . unFBO) 1
--draw bloom onto bloom buffer
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBloom . _1 . unFBO)
withArray [0, 0, 0, 0] $
glClearNamedFramebufferfv
(pdata ^. fboBloom . _1 . unFBO)
GL_COLOR
0
glClearNamedFramebufferfv (pdata ^. fboBloom . _1 . unFBO) GL_COLOR 0
glDepthFunc GL_LESS
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
glDepthMask GL_FALSE
@@ -251,7 +239,10 @@ doDrawing' win pdata u = do
-- draw clouds to block bloom particles, transparency blocks some alpha
glDepthMask GL_FALSE
glBlendColor 0 0 0 0.1 -- using this and GL_CONSTANT_ALPHA below
-- can allow for some underlighting of the clouds
-- can allow for some bloom to bleed through underneath the clouds
-- note that BloomNoZWrite will always be under the clouds, this should be
-- rethought, either do another pass and write just the depth or even remove
-- the layer entirely
glBlendFuncSeparate GL_ZERO GL_ONE GL_CONSTANT_ALPHA GL_ONE_MINUS_SRC_ALPHA
glUseProgram (pdata ^. cloudShader . shaderUINT)
glBindVertexArray $ pdata ^. cloudShader . shaderVAO . vaoName
@@ -271,7 +262,8 @@ doDrawing' win pdata u = do
glDisable GL_BLEND
drawShader (_bloomBlurShader pdata) 4
when (cfig ^. graphics_bloom) $ do
replicateM_ 2 $ pingPongBetween (_fboHalf1 pdata) (_fboHalf2 pdata) (_bloomBlurShader pdata)
replicateM_ 2 $ pingPongBetween
(_fboHalf1 pdata) (_fboHalf2 pdata) (_bloomBlurShader pdata)
glEnable GL_BLEND
setViewport _graphics_world_resolution cfig
--draw clouds onto cloud buffer
@@ -282,12 +274,11 @@ doDrawing' win pdata u = do
--withArray [GL_COLOR_ATTACHMENT0, GL_NONE] $
withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1] $
glNamedFramebufferDrawBuffers (pdata ^. fboCloud . _1 . unFBO) 2
withArray [0.5, 0.5, 0.5, 0] $ \ptr ->
withArray [0.5, 0.5, 0.5, 0] $
glClearNamedFramebufferfv
(pdata ^. fboCloud . _1 . unFBO)
GL_COLOR
0
ptr
glUseProgram (pdata ^. cloudShader . shaderUINT)
glBindVertexArray $ pdata ^. cloudShader . shaderVAO . vaoName
glDrawElements
@@ -307,20 +298,11 @@ doDrawing' win pdata u = do
glDepthFunc GL_ALWAYS
glDisable GL_BLEND
withArray [GL_NONE, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $
-- \ptr -> glDrawBuffers 3 ptr
glNamedFramebufferDrawBuffers (pdata ^. fboCloud . _1 . unFBO) 3
withArray [0, 0, 0, 0] $ \ptr ->
glClearNamedFramebufferfv
(pdata ^. fboCloud . _1 . unFBO)
GL_COLOR
1
ptr
withArray [0, 0, 0, 0] $ \ptr ->
glClearNamedFramebufferfv
(pdata ^. fboCloud . _1 . unFBO)
GL_COLOR
2
ptr
withArray [0, 0, 0, 0] $
glClearNamedFramebufferfv (pdata ^. fboCloud . _1 . unFBO) GL_COLOR 1
withArray [0, 0, 0, 0] $
glClearNamedFramebufferfv (pdata ^. fboCloud . _1 . unFBO) GL_COLOR 2
glEnable GL_BLEND
-- we sum the positions weighted by alpha, and sum the alpha
glBlendFuncSeparatei 1 GL_SRC_ALPHA GL_ONE GL_ONE GL_ONE
@@ -430,13 +412,19 @@ doDrawing' win pdata u = do
renderLayer DebugLayer shadV pokeCounts
glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. matUBO)
withArray (scaleMatrix (2 / windowXFloat cfig) (2 / windowYFloat cfig)) $
\ptr -> glNamedBufferSubData (pdata ^. matUBO) 0 64 ptr
glNamedBufferSubData (pdata ^. matUBO) 0 64
glDepthFunc GL_GEQUAL
glDepthMask GL_TRUE
with (-1) $ \ptr -> glClearNamedFramebufferfv 0 GL_DEPTH 0 ptr
with (-1) $ glClearNamedFramebufferfv 0 GL_DEPTH 0
renderLayer FixedCoordLayer shadV pokeCounts
SDL.glSwapWindow win
bufferPerspectiveMatrixUBO :: Config -> Camera -> GLuint -> IO ()
bufferPerspectiveMatrixUBO cfig cam uboid = withArray
(perspectiveMatrixb (cam ^. camRot) (cam ^. camZoom) (cam ^. camCenter)
(V2 (windowXFloat cfig) (windowYFloat cfig)) (cam ^. camViewFrom))
$ glNamedBufferSubData uboid 0 64
getDistortions :: Config -> World -> [Distortion]
getDistortions cfig w
| cfig ^. graphics_distortions = w ^. cWorld . lWorld . distortions