Changes towards bloom

This commit is contained in:
jgk
2021-07-04 14:09:07 +02:00
parent 9df19a9e85
commit e3bd99868f
2 changed files with 66 additions and 30 deletions
+54 -27
View File
@@ -45,6 +45,7 @@ import qualified SDL
Returns a 'Word32' that should give the number of ticks it took to evaluate. -}
doDrawing :: RenderData -> World -> IO Word32
doDrawing pdata w = do
clearColor $= Color4 0 0 0 1
sTicks <- SDL.ticks
clear [ColorBuffer,DepthBuffer]
let rot = _cameraRot w
@@ -87,37 +88,12 @@ doDrawing pdata w = do
-- I believe a more apt name would be setCeilingDepth: stops drawing of objects
-- at points that are behind the extension of walls to the screen edge
_ <- setWallDepth pdata wallPoints (viewFromx,viewFromy)
_ <- renderFoldable pdata $ picToLTree (Just 0) (polysToPic $ foregroundPics w)
-- draw the first layer of pictures
-- these will probably all be opaque
_ <- renderFoldable pdata $ picToLTree (Just 0) pic
-- reset blend so that light map doesn't apply
-- useful for drawing vivid projectiles
blendFuncSeparate $= ((SrcAlpha,OneMinusSrcAlpha) , (Zero,One))
depthFunc $= Just Lequal
_ <- renderFoldable pdata $ picToLTree (Just 1) pic
depthMask $= Disabled
_ <- renderFoldable pdata $ picToLTree (Just 3) pic
_ <- renderFoldable pdata $ picToLTree (Just 4) pic
_ <- renderFoldable pdata $ picToLTree (Just 5) pic
depthMask $= Enabled
-- reset blend so that light map applies again
-- allows us to be certain these elements are drawn on top of those before,
-- in case we want transparency effects
blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One))
_ <- renderFoldable pdata $ picToLTree (Just 2) pic
depthMask $= Disabled
-- render transparent walls
-- the ordering between these and transparent clouds perhaps presents a challenge
renderBlankWalls pdata windowPoints
depthMask $= Enabled
depthFunc $= Just Lequal
_ <- renderFoldable pdata $ picToLTree (Just 0) (polysToPic $ foregroundPics w)
--(Pictures $ concatmap (Poly3D 0 . _pyFaces) (foregroundPics w))
-- draw the fbo to the screen
-- allows for post-processing
-- first, bind the screen fbo
-- draw opaque background to screen
bindFramebuffer Framebuffer $= defaultFramebufferObject
-- we probably do not want to blend during this step
blend $= Disabled
@@ -133,12 +109,63 @@ doDrawing pdata w = do
bindShaderBuffers [_grayscaleShader pdata] [4]
drawShader (_grayscaleShader pdata) 4
blend $= Enabled
bindFramebuffer Framebuffer $= fst3 (_fbo2 pdata)
depthFunc $= Just Less
clearColor $= Color4 0 0 0 0
clear [ColorBuffer]
-- reset blend so that light map doesn't apply
-- useful for drawing vivid projectiles
blendFunc $= (SrcAlpha,OneMinusSrcAlpha)
_ <- renderFoldable pdata $ picToLTree (Just 1) pic
depthMask $= Disabled
_ <- renderFoldable pdata $ picToLTree (Just 3) pic
_ <- renderFoldable pdata $ picToLTree (Just 4) pic
_ <- renderFoldable pdata $ picToLTree (Just 5) pic
--depthFunc $= Just Lequal
--_ <- renderFoldable pdata $ picToLTree (Just 0) (polysToPic $ foregroundPics w)
--(Pictures $ concatmap (Poly3D 0 . _pyFaces) (foregroundPics w))
-- draw the fbo to the screen
-- allows for post-processing
-- first, bind the screen fbo
bindFramebuffer Framebuffer $= defaultFramebufferObject
blend $= Enabled
blendFuncSeparate $= ((SrcAlpha,OneMinusSrcAlpha),(Zero,One))
depthFunc $= Just Always
textureBinding Texture2D $= Just (snd3 $ _fbo2 pdata)
-- textureFilter Texture2D $= ((Linear',Just Linear') , Linear')
-- generateMipmap' Texture2D
if _crHP (you w) > 0
then do
bindShaderBuffers [_fullscreenShader pdata] [4]
drawShader (_fullscreenShader pdata) 4
else do
bindShaderBuffers [_grayscaleShader pdata] [4]
drawShader (_grayscaleShader pdata) 4
blend $= Enabled
--depthMask $= Enabled
depthMask $= Disabled
depthFunc $= Just Less
-- reset blend so that light map applies again
-- allows us to be certain these elements are drawn on top of those before,
-- in case we want transparency effects
blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One))
_ <- renderFoldable pdata $ picToLTree (Just 2) pic
-- render transparent walls
-- the ordering between these and transparent clouds perhaps presents a challenge
renderBlankWalls pdata windowPoints
--depthMask $= Enabled
bufferUBO $ isoMatrix 0 1 (0,0) (2,2)
depthFunc $= Just Always
blendFunc $= (SrcAlpha,OneMinusSrcAlpha)
_ <- renderFoldable pdata (picToLTree Nothing $ fixedCoordPictures w)
eTicks <- SDL.ticks
depthMask $= Enabled
return (eTicks - sTicks)
--------------------------------------------------------------------------------