Downsample when blurring bloom
This commit is contained in:
@@ -3,10 +3,12 @@ in vec2 vTexPos;
|
|||||||
out vec4 fColor;
|
out vec4 fColor;
|
||||||
const vec2 winSize = vec2 (300,300);
|
const vec2 winSize = vec2 (300,300);
|
||||||
// note that the above opening bracket should be the first in this file
|
// note that the above opening bracket should be the first in this file
|
||||||
|
// this is so that the window size can be extracted and the shader recompiled on
|
||||||
|
// the fly
|
||||||
uniform sampler2D screenTexture;
|
uniform sampler2D screenTexture;
|
||||||
|
|
||||||
const float hOff = 4.0 / winSize.x;
|
const float hOff = 3.0 / winSize.x;
|
||||||
const float vOff = 4.0 / winSize.y;
|
const float vOff = 3.0 / winSize.y;
|
||||||
const float frac = 1.0 / 9;
|
const float frac = 1.0 / 9;
|
||||||
const vec2 off[9] = vec2[]
|
const vec2 off[9] = vec2[]
|
||||||
( vec2( vOff,hOff )
|
( vec2( vOff,hOff )
|
||||||
|
|||||||
+7
-5
@@ -104,21 +104,21 @@ doDrawing pdata w = do
|
|||||||
renderLayer 5 shadV layerCounts
|
renderLayer 5 shadV layerCounts
|
||||||
|
|
||||||
depthMask $= Enabled
|
depthMask $= Enabled
|
||||||
|
-- this is not ideal if the original is not divisible by 2
|
||||||
|
viewport $= (Position 0 0
|
||||||
|
, divideSize (2 * (w ^. config . shadow_resolution)) $ Size (round $ fstV2 wins) (round $ sndV2 wins))
|
||||||
bindFramebuffer Framebuffer $= fst (_fboFourth1 pdata)
|
bindFramebuffer Framebuffer $= fst (_fboFourth1 pdata)
|
||||||
--viewport $= (Position 0 0, Size 300 300)
|
|
||||||
depthFunc $= Just Always
|
depthFunc $= Just Always
|
||||||
textureBinding Texture2D $= Just (snd $ _fboBloom pdata)
|
textureBinding Texture2D $= Just (snd $ _fboBloom pdata)
|
||||||
blend $= Disabled
|
blend $= Disabled
|
||||||
drawShader (_bloomBlurShader pdata) 4
|
drawShader (_bloomBlurShader pdata) 4
|
||||||
replicateM_ 3 $ pingPongBetween (_fboFourth1 pdata) (_fboFourth2 pdata) (_bloomBlurShader pdata)
|
replicateM_ 3 $ pingPongBetween (_fboFourth1 pdata) (_fboFourth2 pdata) (_bloomBlurShader pdata)
|
||||||
-- viewport $= (Position 0 0, Size (round $ fstV2 wins) (round $ sndV2 wins))
|
|
||||||
blend $= Enabled
|
blend $= Enabled
|
||||||
|
viewport $= (Position 0 0
|
||||||
|
, divideSize (w ^. config . shadow_resolution) $ Size (round $ fstV2 wins) (round $ sndV2 wins))
|
||||||
|
|
||||||
bindFramebuffer Framebuffer $= fst (_fboLighting pdata)
|
bindFramebuffer Framebuffer $= fst (_fboLighting pdata)
|
||||||
--viewport $= (Position 0 0
|
|
||||||
-- , divideSize (w ^. config . shadow_resolution) $ Size (round $ fstV2 wins) (round $ sndV2 wins))
|
|
||||||
createLightMap pdata lightPoints nWalls nSils nsurfVs
|
createLightMap pdata lightPoints nWalls nSils nsurfVs
|
||||||
--viewport $= (Position 0 0, Size (round $ fstV2 wins) (round $ sndV2 wins))
|
|
||||||
colorMask $= Color4 Enabled Enabled Enabled Enabled
|
colorMask $= Color4 Enabled Enabled Enabled Enabled
|
||||||
clearColor $= Color4 0 0 0 0
|
clearColor $= Color4 0 0 0 0
|
||||||
|
|
||||||
@@ -138,8 +138,10 @@ doDrawing pdata w = do
|
|||||||
textureBinding Texture2D $= Just (snd $ _fboColor pdata)
|
textureBinding Texture2D $= Just (snd $ _fboColor pdata)
|
||||||
drawShader (_colorBlurShader pdata) 4
|
drawShader (_colorBlurShader pdata) 4
|
||||||
--textureBinding Texture2D $= Just (snd3 $ _fbo2 pdata)
|
--textureBinding Texture2D $= Just (snd3 $ _fbo2 pdata)
|
||||||
|
--blendFunc $= (SrcAlpha, One)
|
||||||
textureBinding Texture2D $= Just (snd $ _fboFourth1 pdata)
|
textureBinding Texture2D $= Just (snd $ _fboFourth1 pdata)
|
||||||
drawShader (_fullscreenShader pdata) 4
|
drawShader (_fullscreenShader pdata) 4
|
||||||
|
blendFunc $= (SrcAlpha, OneMinusSrcAlpha)
|
||||||
textureBinding Texture2D $= Just (snd $ _fboBloom pdata)
|
textureBinding Texture2D $= Just (snd $ _fboBloom pdata)
|
||||||
drawShader (_fullscreenShader pdata) 4
|
drawShader (_fullscreenShader pdata) 4
|
||||||
|
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ sizeFBOs
|
|||||||
-> IO (RenderData)
|
-> IO (RenderData)
|
||||||
sizeFBOs xsize ysize xfull yfull rdata = do
|
sizeFBOs xsize ysize xfull yfull rdata = do
|
||||||
resizeRBO (_rboBaseBloom rdata) xsize ysize
|
resizeRBO (_rboBaseBloom rdata) xsize ysize
|
||||||
resizeRBO (_rboLighting rdata) xsize ysize
|
resizeRBO (_rboLighting rdata) xsize ysize
|
||||||
rdata' <- foldM (updateFBOTO xsize ysize) rdata [fboBase, fboBloom, fboColor,fboFourth1,fboFourth2]
|
rdata' <- foldM (updateFBOTO xsize ysize minMagFilter) rdata [fboBase, fboColor,fboLighting]
|
||||||
rdata'' <- foldM (updateFBOTO xfull yfull) rdata' [fbo2, fbo3]
|
rdata'' <- updateFBOTO xsize ysize minMagFilter rdata' fboBloom
|
||||||
updateFBOTO xsize ysize rdata'' fboLighting
|
rdata''' <- foldM (updateFBOTO xfull yfull minMagFilter) rdata'' [fbo2, fbo3]
|
||||||
|
foldM (updateFBOTO (xsize `div` 2) (ysize `div` 2) linMinMagFilter) rdata''' [fboFourth1,fboFourth2]
|
||||||
|
|
||||||
resizeRBO
|
resizeRBO
|
||||||
:: RenderbufferObject
|
:: RenderbufferObject
|
||||||
@@ -42,19 +43,21 @@ resizeRBO rboName xsize ysize = do
|
|||||||
updateFBOTO
|
updateFBOTO
|
||||||
:: Int
|
:: Int
|
||||||
-> Int
|
-> Int
|
||||||
|
-> ((TextureFilter, Maybe TextureFilter),TextureFilter)
|
||||||
-> RenderData
|
-> RenderData
|
||||||
-> ALens' RenderData (FramebufferObject, TextureObject)
|
-> ALens' RenderData (FramebufferObject, TextureObject)
|
||||||
-> IO (RenderData)
|
-> IO (RenderData)
|
||||||
updateFBOTO xsize ysize pdata target = do
|
updateFBOTO xsize ysize mmfilt pdata target = do
|
||||||
newfbo2 <- resizeFBOTO (pdata ^# target) xsize ysize
|
newfbo2 <- resizeFBOTO (pdata ^# target) xsize ysize mmfilt
|
||||||
return $ storing target newfbo2 pdata
|
return $ storing target newfbo2 pdata
|
||||||
|
|
||||||
resizeFBOTO
|
resizeFBOTO
|
||||||
:: (FramebufferObject , TextureObject)
|
:: (FramebufferObject , TextureObject)
|
||||||
-> Int
|
-> Int
|
||||||
-> Int
|
-> Int
|
||||||
|
-> ((TextureFilter, Maybe TextureFilter),TextureFilter)
|
||||||
-> IO (FramebufferObject, TextureObject)
|
-> IO (FramebufferObject, TextureObject)
|
||||||
resizeFBOTO (fboName,toOld) xsize ysize = do
|
resizeFBOTO (fboName,toOld) xsize ysize mmfilt = do
|
||||||
bindFramebuffer Framebuffer $= fboName
|
bindFramebuffer Framebuffer $= fboName
|
||||||
let xsize' = fromIntegral xsize
|
let xsize' = fromIntegral xsize
|
||||||
ysize' = fromIntegral ysize
|
ysize' = fromIntegral ysize
|
||||||
@@ -62,7 +65,7 @@ resizeFBOTO (fboName,toOld) xsize ysize = do
|
|||||||
toName <- genObjectName
|
toName <- genObjectName
|
||||||
textureBinding Texture2D $= Just toName
|
textureBinding Texture2D $= Just toName
|
||||||
glTexStorage2D GL_TEXTURE_2D 1 GL_RGBA8 xsize' ysize'
|
glTexStorage2D GL_TEXTURE_2D 1 GL_RGBA8 xsize' ysize'
|
||||||
textureFilter Texture2D $= minMagFilter
|
textureFilter Texture2D $= mmfilt
|
||||||
framebufferTexture2D Framebuffer (ColorAttachment 0) Texture2D toName 0
|
framebufferTexture2D Framebuffer (ColorAttachment 0) Texture2D toName 0
|
||||||
fboStatus <- framebufferStatus Framebuffer
|
fboStatus <- framebufferStatus Framebuffer
|
||||||
putStrLn $ "after resize, framebuffer status:" ++ show fboStatus
|
putStrLn $ "after resize, framebuffer status:" ++ show fboStatus
|
||||||
@@ -71,3 +74,5 @@ resizeFBOTO (fboName,toOld) xsize ysize = do
|
|||||||
minMagFilter :: ((TextureFilter, Maybe TextureFilter),TextureFilter)
|
minMagFilter :: ((TextureFilter, Maybe TextureFilter),TextureFilter)
|
||||||
minMagFilter = ((Nearest,Nothing),Nearest)
|
minMagFilter = ((Nearest,Nothing),Nearest)
|
||||||
|
|
||||||
|
linMinMagFilter :: ((TextureFilter, Maybe TextureFilter),TextureFilter)
|
||||||
|
linMinMagFilter = ((Linear',Nothing),Linear')
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ renderDataResizeUpdate xsize ysize xfull yfull rdata = do
|
|||||||
bbFrag <- BS.readFile "shader/texture/bloomBlur.frag"
|
bbFrag <- BS.readFile "shader/texture/bloomBlur.frag"
|
||||||
let (bh,bmid) = BS.breakSubstring "(" bbFrag
|
let (bh,bmid) = BS.breakSubstring "(" bbFrag
|
||||||
(_,btt) = BS.breakSubstring ")" bmid
|
(_,btt) = BS.breakSubstring ")" bmid
|
||||||
bbFrag' = BS.append bh $ BS.append (BSC.pack $ '(' : show xfull ++ "," ++ show yfull) btt
|
bbFrag' = BS.append bh $ BS.append (BSC.pack $ '(' : show xsize ++ "," ++ show ysize) btt
|
||||||
--BSC.putStrLn bbFrag'
|
--BSC.putStrLn bbFrag'
|
||||||
bbShad <- makeByteStringShaderUsingVAO "bloomBlur" [(vert,bbVert),(frag,bbFrag')] ETriangleStrip
|
bbShad <- makeByteStringShaderUsingVAO "bloomBlur" [(vert,bbVert),(frag,bbFrag')] ETriangleStrip
|
||||||
(_fullscreenShader rdata)
|
(_fullscreenShader rdata)
|
||||||
|
|||||||
Reference in New Issue
Block a user