Use mipmaps when downscaling bloom

This commit is contained in:
2025-11-25 11:28:37 +00:00
parent c0cfadbdd3
commit 1d177a7e16
3 changed files with 315 additions and 291 deletions
+1
View File
@@ -207,6 +207,7 @@ doDrawing' win pdata u = do
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboHalf1 pdata)))
glDepthFunc GL_ALWAYS
glBindTextureUnit 0 (pdata ^. fboBloom . _2 . unTO)
glGenerateTextureMipmap (pdata ^. fboBloom . _2 . unTO)
glDisable GL_BLEND
-- this all needs more tuning + more thought
-- a fade effect would be cool, so not to fully reset last frames bloom
+55 -43
View File
@@ -21,17 +21,6 @@ import Unsafe.Coerce
sizeFBOs :: Config -> RenderData -> IO RenderData
sizeFBOs cfig rdata =
uncurryV (resizeRBO (_rboBaseBloom rdata)) (getWindowSize _gr_world_res cfig)
-- >> updateFBOTO3
-- (getWindowSize _gr_world_res cfig)
-- GL_NEAREST
-- GL_NEAREST
-- GL_RGB16F -- RGBAF not sure if the alpha is necessary here
-- GL_RGB16F -- could possibly recover using depth in a clever way
-- -- but probably not, because the projection matrix is
-- -- not always on-center
-- GL_RGBA8_SNORM
-- rdata
-- fboBase
>> fboBase (resizeFBOTO3'
(getWindowSize _gr_world_res cfig)
GL_NEAREST
@@ -61,12 +50,20 @@ sizeFBOs cfig rdata =
GL_NEAREST
GL_RGBA8
[fboLighting]
>>= foldUpdateFBOTO
_gr_world_res
>>= fboBloom (resizeFBOTO'
(getWindowSize _gr_world_res cfig)
3
GL_LINEAR_MIPMAP_LINEAR
GL_LINEAR
GL_RGBA16F
[fboBloom, fboPos] -- fboPos probably doesn't need the alpha channel
-- [fboBloom] -- fboPos probably doesn't need the alpha channel
)
>>= foldUpdateFBOTO
_gr_world_res
GL_NEAREST
GL_NEAREST
GL_RGBA16F
[fboPos] -- fboPos probably doesn't need the alpha channel
>>= foldUpdateFBOTO
_gr_downsize_res
GL_LINEAR_MIPMAP_LINEAR
@@ -104,8 +101,8 @@ updateFBOTO ::
RenderData ->
ALens' RenderData (FBO, TO) ->
IO RenderData
updateFBOTO (V2 xsize ysize) minfilt magfilt form pdata target = do
newfbo2 <- resizeFBOTO (pdata ^# target) xsize ysize minfilt magfilt form
updateFBOTO wsize minfilt magfilt form pdata target = do
newfbo2 <- resizeFBOTO (pdata ^# target) wsize minfilt magfilt form
return $ storing target newfbo2 pdata
-- note that the ordering of arguments is different to the other update
@@ -123,8 +120,8 @@ updateFBOTO2 ::
RenderData ->
ALens' RenderData (FBO, (TO, TO)) ->
IO RenderData
updateFBOTO2 (V2 xsize ysize) minfilt magfilt form1 form2 pdata target = do
newfbo2 <- resizeFBOTO2 (pdata ^# target) xsize ysize minfilt magfilt form1 form2
updateFBOTO2 wsize minfilt magfilt form1 form2 pdata target = do
newfbo2 <- resizeFBOTO2 (pdata ^# target) wsize minfilt magfilt form1 form2
return $ storing target newfbo2 pdata
updateFBOTO3 ::
@@ -142,14 +139,13 @@ updateFBOTO3 ::
RenderData ->
ALens' RenderData (FBO, (TO, TO, TO)) ->
IO RenderData
updateFBOTO3 (V2 xsize ysize) minfilt magfilt form1 form2 form3 pdata target = do
newfbo2 <- resizeFBOTO3 (pdata ^# target) xsize ysize minfilt magfilt form1 form2 form3
updateFBOTO3 wsize minfilt magfilt form1 form2 form3 pdata target = do
newfbo2 <- resizeFBOTO3 (pdata ^# target) wsize minfilt magfilt form1 form2 form3
return $ storing target newfbo2 pdata
resizeFBOTO2 ::
(FBO, (TO, TO)) ->
Int ->
Int ->
V2 Int ->
-- | minification filter
GLenum ->
-- | magnification filter
@@ -159,12 +155,12 @@ resizeFBOTO2 ::
-- | internal color format2
GLenum ->
IO (FBO, (TO, TO))
resizeFBOTO2 (fbo, (told1, told2)) xsize ysize minfilt magfilt form1 form2 = do
resizeFBOTO2 (fbo, (told1, told2)) wsize minfilt magfilt form1 form2 = do
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo)
mglDelete glDeleteTextures $ _unTO told1
mglDelete glDeleteTextures $ _unTO told2
to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 xsize ysize minfilt magfilt form1
to2 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT1 xsize ysize minfilt magfilt form2
to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 wsize 1 minfilt magfilt form1
to2 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT1 wsize 1 minfilt magfilt form2
withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1] $
glNamedFramebufferDrawBuffers (_unFBO fbo) 2
checkFBO fbo
@@ -172,8 +168,7 @@ resizeFBOTO2 (fbo, (told1, told2)) xsize ysize minfilt magfilt form1 form2 = do
resizeFBOTO3 ::
(FBO, (TO, TO, TO)) ->
Int ->
Int ->
V2 Int ->
-- | minification filter
GLenum ->
-- | magnification filter
@@ -185,14 +180,14 @@ resizeFBOTO3 ::
-- | internal color format3
GLenum ->
IO (FBO, (TO, TO, TO))
resizeFBOTO3 (fbo, (told1, told2, told3)) xsize ysize minfilt magfilt form1 form2 form3 = do
resizeFBOTO3 (fbo, (told1, told2, told3)) wsize minfilt magfilt form1 form2 form3 = do
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo)
mglDelete glDeleteTextures $ _unTO told1
mglDelete glDeleteTextures $ _unTO told2
mglDelete glDeleteTextures $ _unTO told3
to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 xsize ysize minfilt magfilt form1
to2 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT1 xsize ysize minfilt magfilt form2
to3 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT2 xsize ysize minfilt magfilt form3
to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 wsize 1 minfilt magfilt form1
to2 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT1 wsize 1 minfilt magfilt form2
to3 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT2 wsize 1 minfilt magfilt form3
withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $
glNamedFramebufferDrawBuffers (_unFBO fbo) 3
checkFBO fbo
@@ -216,14 +211,14 @@ resizeFBOTO3' ::
GLenum ->
(FBO, (TO, TO, TO)) ->
IO (FBO, (TO, TO, TO))
resizeFBOTO3' (V2 xsize ysize) min1 mag1 minfilt magfilt form1 form2 form3 (fbo, (told1, told2, told3)) = do
resizeFBOTO3' wsize min1 mag1 minfilt magfilt form1 form2 form3 (fbo, (told1, told2, told3)) = do
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo)
mglDelete glDeleteTextures $ _unTO told1
mglDelete glDeleteTextures $ _unTO told2
mglDelete glDeleteTextures $ _unTO told3
to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 xsize ysize min1 mag1 form1
to2 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT1 xsize ysize minfilt magfilt form2
to3 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT2 xsize ysize minfilt magfilt form3
to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 wsize 1 min1 mag1 form1
to2 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT1 wsize 1 minfilt magfilt form2
to3 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT2 wsize 1 minfilt magfilt form3
withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $
glNamedFramebufferDrawBuffers (_unFBO fbo) 3
checkFBO fbo
@@ -231,8 +226,7 @@ resizeFBOTO3' (V2 xsize ysize) min1 mag1 minfilt magfilt form1 form2 form3 (fbo,
resizeFBOTO ::
(FBO, TO) ->
Int ->
Int ->
V2 Int ->
-- | minification filter
GLenum ->
-- | magnification filter
@@ -240,20 +234,38 @@ resizeFBOTO ::
-- | internal color format
GLenum ->
IO (FBO, TO)
resizeFBOTO (fbo, oldto) xsize ysize minfilt magfilt form = do
resizeFBOTO (fbo, oldto) wsize minfilt magfilt form = do
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo)
mglDelete glDeleteTextures $ _unTO oldto
to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 xsize ysize minfilt magfilt form
to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 wsize 1 minfilt magfilt form
checkFBO fbo
return (fbo, TO to1)
initializeTexture2D ::
FBO -> GLenum -> Int -> Int -> GLenum -> GLenum -> GLenum -> IO GLuint
initializeTexture2D fbo attachpoint x y minfilt magfilt form = do
resizeFBOTO' ::
V2 Int ->
Int ->
-- | minification filter
GLenum ->
-- | magnification filter
GLenum ->
-- | internal color format
GLenum ->
(FBO, TO) ->
IO (FBO, TO)
resizeFBOTO' wsize nlevels minfilt magfilt form (fbo, oldto) = do
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo)
mglDelete glDeleteTextures $ _unTO oldto
to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 wsize nlevels minfilt magfilt form
checkFBO fbo
return (fbo, TO to1)
initializeTexture2D :: FBO -> GLenum -> V2 Int -> Int
-> GLenum -> GLenum -> GLenum -> IO GLuint
initializeTexture2D fbo attachpoint (V2 x y) nlevels minfilt magfilt form = do
let xsize' = fromIntegral x
ysize' = fromIntegral y
to1 <- mglCreate (glCreateTextures GL_TEXTURE_2D)
glTextureStorage2D to1 1 form xsize' ysize'
glTextureStorage2D to1 (fromIntegral nlevels) form xsize' ysize'
glTextureParameteri to1 GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt)
glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt)
glTextureParameteri to1 GL_TEXTURE_WRAP_S (unsafeCoerce GL_CLAMP_TO_EDGE)
+259 -248
View File
File diff suppressed because it is too large Load Diff