Enable more control of bloom using hdr

This commit is contained in:
2021-08-20 15:06:55 +02:00
parent 822c65e0cc
commit 778d18276b
6 changed files with 24 additions and 22 deletions
+2 -4
View File
@@ -41,10 +41,8 @@ void main()
{ {
sumFive += vec4(texture(screenTexture, vTexPos + fiveOff[i])); sumFive += vec4(texture(screenTexture, vTexPos + fiveOff[i]));
} }
// divinding by 4 is not ideal, because it adds extra alpha //fColor = max(texture(screenTexture,vTexPos), sumFive / 5);
// but has more juice than dividing by 5 fColor = vec4 ( (sumFive / 5).rgb, max((sumFive/5).a,texture(screenTexture,vTexPos).a) );
fColor = max(texture(screenTexture,vTexPos), sumFive / 4);
//fColor = sumFive / 4;
// vec4 sampleTex[9]; // vec4 sampleTex[9];
// for(int i=0; i<9; i++) // for(int i=0; i<9; i++)
// { // {
+1 -1
View File
@@ -19,7 +19,7 @@ aGenBulAt maycid pos vel hiteff width = Bul'
{ _ptDraw = drawBul { _ptDraw = drawBul
, _ptUpdate' = mvGenBullet , _ptUpdate' = mvGenBullet
, _btVel' = vel , _btVel' = vel
, _btColor' = white , _btColor' = V4 100 100 50 1.5
, _btTrail' = [pos] , _btTrail' = [pos]
, _btPassThrough' = maycid , _btPassThrough' = maycid
, _btWidth' = width , _btWidth' = width
+1 -1
View File
@@ -112,7 +112,7 @@ doDrawing pdata w = do
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_ 2 $ pingPongBetween (_fboFourth1 pdata) (_fboFourth2 pdata) (_bloomBlurShader pdata)
blend $= Enabled blend $= Enabled
viewport $= (Position 0 0 viewport $= (Position 0 0
, divideSize (w ^. config . shadow_resolution) $ Size (round $ fstV2 wins) (round $ sndV2 wins)) , divideSize (w ^. config . shadow_resolution) $ Size (round $ fstV2 wins) (round $ sndV2 wins))
+6 -4
View File
@@ -1,6 +1,8 @@
{- | For initialising framebuffers.
-}
module Framebuffer.Setup module Framebuffer.Setup
( setupTextureFramebuffer ( setupTextureFramebuffer
, newFramebufferGivenStencil , setupFramebufferGivenStencil
) where ) where
import Graphics.Rendering.OpenGL hiding (Point,translate,scale,imageHeight) import Graphics.Rendering.OpenGL hiding (Point,translate,scale,imageHeight)
import Graphics.GL.Core43 import Graphics.GL.Core43
@@ -23,11 +25,11 @@ setupTextureFramebuffer x y = do
print fboStatus print fboStatus
return (fboName, fboTO) return (fboName, fboTO)
newFramebufferGivenStencil setupFramebufferGivenStencil
:: RenderbufferObject :: RenderbufferObject
-> IO (FramebufferObject, TextureObject) -> IO (FramebufferObject, TextureObject)
{-# INLINE newFramebufferGivenStencil #-} {-# INLINE setupFramebufferGivenStencil #-}
newFramebufferGivenStencil rboName = do setupFramebufferGivenStencil rboName = do
fboName <- genObjectName fboName <- genObjectName
bindFramebuffer Framebuffer $= fboName bindFramebuffer Framebuffer $= fboName
toName <- genObjectName toName <- genObjectName
+10 -8
View File
@@ -24,10 +24,10 @@ sizeFBOs
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 minMagFilter) rdata [fboBase, fboColor,fboLighting] rdata' <- foldM (updateFBOTO xsize ysize minMagFilter GL_RGBA8) rdata [fboBase, fboColor,fboLighting]
rdata'' <- updateFBOTO xsize ysize minMagFilter rdata' fboBloom rdata'' <- updateFBOTO xsize ysize linMinMagFilter GL_RGBA16F rdata' fboBloom
rdata''' <- foldM (updateFBOTO xfull yfull minMagFilter) rdata'' [fbo2, fbo3] rdata''' <- foldM (updateFBOTO xfull yfull minMagFilter GL_RGBA8) rdata'' [fbo2, fbo3]
foldM (updateFBOTO (xsize `div` 2) (ysize `div` 2) linMinMagFilter) rdata''' [fboFourth1,fboFourth2] foldM (updateFBOTO (xsize `div` 2) (ysize `div` 2) linMinMagFilter GL_RGBA16F) rdata''' [fboFourth1,fboFourth2]
resizeRBO resizeRBO
:: RenderbufferObject :: RenderbufferObject
@@ -44,11 +44,12 @@ updateFBOTO
:: Int :: Int
-> Int -> Int
-> ((TextureFilter, Maybe TextureFilter),TextureFilter) -> ((TextureFilter, Maybe TextureFilter),TextureFilter)
-> GLenum
-> RenderData -> RenderData
-> ALens' RenderData (FramebufferObject, TextureObject) -> ALens' RenderData (FramebufferObject, TextureObject)
-> IO (RenderData) -> IO (RenderData)
updateFBOTO xsize ysize mmfilt pdata target = do updateFBOTO xsize ysize mmfilt inFormat pdata target = do
newfbo2 <- resizeFBOTO (pdata ^# target) xsize ysize mmfilt newfbo2 <- resizeFBOTO (pdata ^# target) xsize ysize mmfilt inFormat
return $ storing target newfbo2 pdata return $ storing target newfbo2 pdata
resizeFBOTO resizeFBOTO
@@ -56,15 +57,16 @@ resizeFBOTO
-> Int -> Int
-> Int -> Int
-> ((TextureFilter, Maybe TextureFilter),TextureFilter) -> ((TextureFilter, Maybe TextureFilter),TextureFilter)
-> GLenum
-> IO (FramebufferObject, TextureObject) -> IO (FramebufferObject, TextureObject)
resizeFBOTO (fboName,toOld) xsize ysize mmfilt = do resizeFBOTO (fboName,toOld) xsize ysize mmfilt inFormat = do
bindFramebuffer Framebuffer $= fboName bindFramebuffer Framebuffer $= fboName
let xsize' = fromIntegral xsize let xsize' = fromIntegral xsize
ysize' = fromIntegral ysize ysize' = fromIntegral ysize
deleteObjectName toOld deleteObjectName toOld
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 inFormat xsize' ysize'
textureFilter Texture2D $= mmfilt textureFilter Texture2D $= mmfilt
framebufferTexture2D Framebuffer (ColorAttachment 0) Texture2D toName 0 framebufferTexture2D Framebuffer (ColorAttachment 0) Texture2D toName 0
fboStatus <- framebufferStatus Framebuffer fboStatus <- framebufferStatus Framebuffer
+4 -4
View File
@@ -101,15 +101,15 @@ preloadRender = do
rboLightingName <- genObjectName rboLightingName <- genObjectName
bindRenderbuffer Renderbuffer $= rboLightingName bindRenderbuffer Renderbuffer $= rboLightingName
renderbufferStorage Renderbuffer Depth24Stencil8 (RenderbufferSize 800 600) renderbufferStorage Renderbuffer Depth24Stencil8 (RenderbufferSize 800 600)
fboLightingName <- newFramebufferGivenStencil rboLightingName fboLightingName <- setupFramebufferGivenStencil rboLightingName
rboBaseBloomName <- genObjectName rboBaseBloomName <- genObjectName
bindRenderbuffer Renderbuffer $= rboBaseBloomName bindRenderbuffer Renderbuffer $= rboBaseBloomName
renderbufferStorage Renderbuffer Depth24Stencil8 (RenderbufferSize 800 600) renderbufferStorage Renderbuffer Depth24Stencil8 (RenderbufferSize 800 600)
fboBaseName <- newFramebufferGivenStencil rboBaseBloomName fboBaseName <- setupFramebufferGivenStencil rboBaseBloomName
fboBloomName <- newFramebufferGivenStencil rboBaseBloomName fboBloomName <- setupFramebufferGivenStencil rboBaseBloomName
fboColorName <- newFramebufferGivenStencil rboBaseBloomName fboColorName <- setupFramebufferGivenStencil rboBaseBloomName
fboFourth1Name <- setupTextureFramebuffer 300 300 fboFourth1Name <- setupTextureFramebuffer 300 300
fboFourth2Name <- setupTextureFramebuffer 300 300 fboFourth2Name <- setupTextureFramebuffer 300 300