Separate rendering of background, bloom, lightmap into framebuffers
This commit is contained in:
+13
-22
@@ -46,10 +46,12 @@ setWallDepth pdata wallPoints (viewFromx,viewFromy) = do
|
||||
divideSize :: Int -> Size -> Size
|
||||
divideSize i (Size x y) = Size (div x $ fromIntegral i) (div y $ fromIntegral i)
|
||||
|
||||
sizeToTexSize :: Size -> TextureSize2D
|
||||
sizeToTexSize (Size x y) = TextureSize2D x y
|
||||
|
||||
{- |
|
||||
Determine where light is shining in the world.
|
||||
Note that this currently (1/5/2021) sets the bound framebuffer to fbo2.
|
||||
The lightmap itself is rendered into this buffer. -}
|
||||
-}
|
||||
createLightMap
|
||||
:: RenderData
|
||||
-> Int -- Resolution division
|
||||
@@ -61,9 +63,14 @@ createLightMap
|
||||
createLightMap pdata resDiv wallPoints lightPoints fpics scPol = do
|
||||
-- get viewport size so we can reset it later
|
||||
(vppos,vpsize) <- get viewport
|
||||
-- set the viewport size to that of the render buffer
|
||||
viewport $= (vppos, divideSize resDiv vpsize)
|
||||
bindFramebuffer Framebuffer $= _spareFBO pdata
|
||||
-- set the viewport size to desired fidelity
|
||||
let vsize = divideSize resDiv vpsize
|
||||
viewport $= (vppos, vsize)
|
||||
textureBinding Texture2D $= Just (snd $ (fst $ _fbos pdata) !! 2)
|
||||
texImage2D Texture2D NoProxy 0 RGBA8 (sizeToTexSize vsize) 0 (PixelData RGBA UnsignedByte nullPtr)
|
||||
textureFilter Texture2D $= ((Linear',Just Linear') , Linear')
|
||||
generateMipmap' Texture2D
|
||||
-- bindFramebuffer Framebuffer $= _spareFBO pdata
|
||||
-- store wall and light positions into buffer
|
||||
nWallLights <- F.foldM (pokeShader $ _lightingWallShader pdata) (map Render22 wallPoints)
|
||||
bindShaderBuffers [_lightingWallShader pdata] [nWallLights]
|
||||
@@ -80,6 +87,7 @@ createLightMap pdata resDiv wallPoints lightPoints fpics scPol = do
|
||||
bindShaderBuffers [_lightingSurfaceShader pdata] [nsurfVs]
|
||||
-- clear buffer to full alpha and furthest depth
|
||||
-- clearColor is specified in preloadRender
|
||||
clearColor $= Color4 0 0 0 1
|
||||
clear [ColorBuffer,DepthBuffer]
|
||||
cullFace $= Just Back
|
||||
-- draw walls from your point of view in order to set z buffer
|
||||
@@ -153,23 +161,6 @@ createLightMap pdata resDiv wallPoints lightPoints fpics scPol = do
|
||||
-- set the viewport size to that of the window
|
||||
viewport $= (vppos, vpsize)
|
||||
-- disable depth testing for blurring
|
||||
depthFunc $= Just Always
|
||||
-- draw the lightmap on a full size fbo
|
||||
bindFramebuffer Framebuffer $= fst3 (_fbo2 pdata)
|
||||
colorMask $= Color4 Disabled Disabled Disabled Enabled
|
||||
bindShaderBuffers [_boxBlurShader pdata] [4]
|
||||
textureBinding Texture2D $= Just (_fboTexture pdata)
|
||||
-- by upscaling the shadowmap texture and using Linear' magnification
|
||||
-- interpolation, we get a poor mans blur, not sure about performance
|
||||
textureFilter Texture2D $= ((Linear',Just Linear') , Linear')
|
||||
generateMipmap' Texture2D
|
||||
drawShader (_boxBlurShader pdata) 4
|
||||
-- ping pong blur between '_fbo2' and '_fbo3' as many times as desired
|
||||
replicateM_ 3 $ pingPongBlur pdata
|
||||
-- reset drawing parameters ready for drawing on top of the light map
|
||||
colorMask $= Color4 Enabled Enabled Enabled Enabled
|
||||
depthMask $= Enabled
|
||||
blend $= Enabled
|
||||
{- |
|
||||
Blur between two framebuffers.
|
||||
Assumes no depth testing is done (depthFunc %= Just Always).
|
||||
|
||||
Reference in New Issue
Block a user