Refactor differing resolutions somewhat

This commit is contained in:
2023-03-24 11:14:49 +00:00
parent cd224437e7
commit 4b92a43535
11 changed files with 69 additions and 52 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 12 KiB

+2 -2
View File
@@ -48,8 +48,8 @@ applyWorldConfig ::
IO PreloadData IO PreloadData
applyWorldConfig cfig pdata = do applyWorldConfig cfig pdata = do
setVol cfig setVol cfig
pdataResizeUpdate (x `div` divRes) (y `div` divRes) x y pdata pdataResizeUpdate cfig (x `div` divRes) (y `div` divRes) x y pdata
where where
x = round $ _windowX cfig x = round $ _windowX cfig
y = round $ _windowY cfig y = round $ _windowY cfig
divRes = resFactorNum $ _graphics_resolution_factor cfig divRes = resFactorNum $ _graphics_world_resolution cfig
+9 -3
View File
@@ -42,7 +42,9 @@ data Configuration = Configuration
, _graphics_distortions :: Bool , _graphics_distortions :: Bool
, _graphics_bloom :: Bool , _graphics_bloom :: Bool
, _graphics_object_shadows :: ShadowRendering , _graphics_object_shadows :: ShadowRendering
, _graphics_resolution_factor :: ResFactor , _graphics_downsize_resolution :: ResFactor
, _graphics_world_resolution :: ResFactor
, _graphics_overlay_resolution :: ResFactor
, _graphics_num_shadow_casters :: NumShadowCasters , _graphics_num_shadow_casters :: NumShadowCasters
, _windowX :: Float , _windowX :: Float
, _windowY :: Float , _windowY :: Float
@@ -83,7 +85,7 @@ data DebugBool
| Show_path_between | Show_path_between
deriving (Eq, Ord, Bounded, Enum, Show) deriving (Eq, Ord, Bounded, Enum, Show)
data ResFactor = FullRes | HalfRes | QuarterRes data ResFactor = FullRes | HalfRes | QuarterRes | EighthRes | SixteenthRes
deriving (Show, Eq, Ord, Enum, Bounded) deriving (Show, Eq, Ord, Enum, Bounded)
data ShadowRendering data ShadowRendering
@@ -102,6 +104,8 @@ resFactorNum rf = case rf of
FullRes -> 1 FullRes -> 1
HalfRes -> 2 HalfRes -> 2
QuarterRes -> 4 QuarterRes -> 4
EighthRes -> 8
SixteenthRes -> 16
defaultConfig :: Configuration defaultConfig :: Configuration
defaultConfig = defaultConfig =
@@ -113,7 +117,9 @@ defaultConfig =
, _graphics_bloom = True , _graphics_bloom = True
, _graphics_object_shadows = GeoObjShads , _graphics_object_shadows = GeoObjShads
, _graphics_distortions = True , _graphics_distortions = True
, _graphics_resolution_factor = QuarterRes , _graphics_downsize_resolution = SixteenthRes
, _graphics_world_resolution = QuarterRes
, _graphics_overlay_resolution = FullRes
, _graphics_num_shadow_casters = toEnum 10 , _graphics_num_shadow_casters = toEnum 10
, _windowX = 800 , _windowX = 800
, _windowY = 600 , _windowY = 600
-5
View File
@@ -1,5 +0,0 @@
module Dodge.DownscaleSize where
downSize :: Int
{-# INLINE downSize #-}
downSize = 8
+1 -1
View File
@@ -61,4 +61,4 @@ handleResizeEvent sev u =
x = fromIntegral x' x = fromIntegral x'
y = fromIntegral y' y = fromIntegral y'
V2 x' y' = windowSizeChangedEventSize sev V2 x' y' = windowSizeChangedEventSize sev
divRes = resFactorNum $ u ^. uvConfig . graphics_resolution_factor divRes = resFactorNum $ u ^. uvConfig . graphics_world_resolution
+5 -1
View File
@@ -182,7 +182,11 @@ graphicsMenu = titleOptionsMenu "OPTIONS:GRAPHICS" graphicsMenuOptions
graphicsMenuOptions :: [MenuOption] graphicsMenuOptions :: [MenuOption]
graphicsMenuOptions = graphicsMenuOptions =
[ makeEnumOption graphics_resolution_factor "RESOLUTION" (uvIOEffects .~ updateFramebufferSize) [ makeEnumOption graphics_world_resolution "World resolution" (uvIOEffects .~ updateFramebufferSize)
, makeEnumOption graphics_downsize_resolution "Downsize resolution"
(uvIOEffects .~ updateFramebufferSize)
, makeEnumOption graphics_overlay_resolution "Overlay resolution"
(uvIOEffects .~ updateFramebufferSize)
, makeEnumOption graphics_object_shadows "SHADOW DETAIL" id , makeEnumOption graphics_object_shadows "SHADOW DETAIL" id
, makeEnumOption graphics_distortions "ENABLE DISTORTIONS" id , makeEnumOption graphics_distortions "ENABLE DISTORTIONS" id
, makeEnumOption graphics_bloom "ENABLE BLOOM" id , makeEnumOption graphics_bloom "ENABLE BLOOM" id
+3 -3
View File
@@ -7,12 +7,12 @@ import Preload.Update
sideEffectUpdatePreload :: Int -> Int -> Int -> (Universe -> IO Universe) -> Universe -> IO Universe sideEffectUpdatePreload :: Int -> Int -> Int -> (Universe -> IO Universe) -> Universe -> IO Universe
sideEffectUpdatePreload divRes x y f u = do sideEffectUpdatePreload divRes x y f u = do
-- GL.viewport $= (GL.Position 0 0, GL.Size (fromIntegral x) (fromIntegral y)) -- GL.viewport $= (GL.Position 0 0, GL.Size (fromIntegral x) (fromIntegral y))
pdata <- pdataResizeUpdate (x `div` divRes) (y `div` divRes) x y (_preloadData u) pdata <- pdataResizeUpdate (u ^. uvConfig) (x `div` divRes) (y `div` divRes) x y (_preloadData u)
f $ u & preloadData .~ pdata f $ u & preloadData .~ pdata
updatePreload :: Int -> Int -> Int -> Universe -> IO Universe updatePreload :: Int -> Int -> Int -> Universe -> IO Universe
updatePreload divRes x y u = do updatePreload divRes x y u = do
pdata <- pdataResizeUpdate (x `div` divRes) (y `div` divRes) x y (_preloadData u) pdata <- pdataResizeUpdate (u ^. uvConfig) (x `div` divRes) (y `div` divRes) x y (_preloadData u)
return $ u & preloadData .~ pdata return $ u & preloadData .~ pdata
updateFramebufferSize :: Universe -> IO Universe updateFramebufferSize :: Universe -> IO Universe
@@ -20,4 +20,4 @@ updateFramebufferSize u = updatePreload divRes x y u
where where
(x, y) = (round $ _windowX cfig, round $ _windowY cfig) (x, y) = (round $ _windowX cfig, round $ _windowY cfig)
cfig = _uvConfig u cfig = _uvConfig u
divRes = resFactorNum $ u ^. uvConfig . graphics_resolution_factor divRes = resFactorNum $ u ^. uvConfig . graphics_world_resolution
+17 -6
View File
@@ -1,6 +1,7 @@
-- | Contains the central drawing functions for the dodge loop. -- | Contains the central drawing functions for the dodge loop.
module Dodge.Render ( module Dodge.Render (
doDrawing, doDrawing,
getWindowSize
) where ) where
--import qualified Data.Vector as V --import qualified Data.Vector as V
@@ -13,7 +14,6 @@ import qualified Data.Map.Strict as M
import Data.Preload.Render import Data.Preload.Render
import qualified Data.Vector.Unboxed.Mutable as UMV import qualified Data.Vector.Unboxed.Mutable as UMV
import Dodge.Data.Universe import Dodge.Data.Universe
import Dodge.DownscaleSize
import Dodge.Render.Lights import Dodge.Render.Lights
import Dodge.Render.ShapePicture import Dodge.Render.ShapePicture
import Dodge.Render.Walls import Dodge.Render.Walls
@@ -49,7 +49,9 @@ doDrawing' win pdata u = do
camzoom = w ^. cWorld . camPos . camZoom camzoom = w ^. cWorld . camPos . camZoom
trans = w ^. cWorld . camPos . camCenter trans = w ^. cWorld . camPos . camCenter
wins@(V2 winx winy) = V2 (_windowX cfig) (_windowY cfig) wins@(V2 winx winy) = V2 (_windowX cfig) (_windowY cfig)
resFact = resFactorNum $ cfig ^. graphics_resolution_factor worldres = resFactorNum $ cfig ^. graphics_world_resolution
downres = resFactorNum $ cfig ^. graphics_downsize_resolution
overlayres = resFactorNum $ cfig ^. graphics_overlay_resolution
(windowPoints, wallSPics, wallsToPoke) = wallsToDraw w (windowPoints, wallSPics, wallsToPoke) = wallsToDraw w
lightPoints = lightsToRender cfig (w ^. cWorld . camPos) (w ^. cWorld . lWorld) lightPoints = lightsToRender cfig (w ^. cWorld . camPos) (w ^. cWorld . lWorld)
viewFroms@(V2 vfx vfy) = w ^. cWorld . camPos . camViewFrom viewFroms@(V2 vfx vfy) = w ^. cWorld . camPos . camViewFrom
@@ -105,7 +107,7 @@ doDrawing' win pdata u = do
glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. matUBO) glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. matUBO)
withArray (perspectiveMatrixb rot camzoom trans wins viewFroms) $ \ptr -> withArray (perspectiveMatrixb rot camzoom trans wins viewFroms) $ \ptr ->
glNamedBufferSubData (pdata ^. matUBO) 0 64 ptr glNamedBufferSubData (pdata ^. matUBO) 0 64 ptr
setViewportSize (round winx `div` resFact) (round winy `div` resFact) setViewportSize (round winx `div` worldres) (round winy `div` worldres)
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase ._1 . unFBO) glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase ._1 . unFBO)
glDepthMask GL_TRUE glDepthMask GL_TRUE
glDisable GL_BLEND glDisable GL_BLEND
@@ -216,7 +218,7 @@ doDrawing' win pdata u = do
renderLayer BloomLayer shadV layerCounts renderLayer BloomLayer shadV layerCounts
--setup downscale viewport for blurring bloom --setup downscale viewport for blurring bloom
--setViewportSize (round winx `div` (2 * resFact)) (round winy `div` (2 * resFact)) --setViewportSize (round winx `div` (2 * resFact)) (round winy `div` (2 * resFact))
setViewportSize (round winx `div` downSize) (round winy `div` downSize) setViewportSize (round winx `div` downres) (round winy `div` downres)
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboHalf1 pdata))) glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboHalf1 pdata)))
glDepthFunc GL_ALWAYS glDepthFunc GL_ALWAYS
glBindTextureUnit 0 (pdata ^. fboBloom . _2 . unTO) glBindTextureUnit 0 (pdata ^. fboBloom . _2 . unTO)
@@ -224,7 +226,7 @@ doDrawing' win pdata u = do
drawShader (_bloomBlurShader pdata) 4 drawShader (_bloomBlurShader pdata) 4
replicateM_ 2 $ pingPongBetween (_fboHalf1 pdata) (_fboHalf2 pdata) (_bloomBlurShader pdata) replicateM_ 2 $ pingPongBetween (_fboHalf1 pdata) (_fboHalf2 pdata) (_bloomBlurShader pdata)
glEnable GL_BLEND glEnable GL_BLEND
setViewportSize (round winx `div` resFact) (round winy `div` resFact) setViewportSize (round winx `div` worldres) (round winy `div` worldres)
--draw clouds onto cloud buffer --draw clouds onto cloud buffer
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboCloud pdata))) glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboCloud pdata)))
glDepthFunc GL_LEQUAL glDepthFunc GL_LEQUAL
@@ -332,7 +334,8 @@ doDrawing' win pdata u = do
glBindTextureUnit 0 (pdata ^. fboCloud . _2 . _1 . unTO) glBindTextureUnit 0 (pdata ^. fboCloud . _2 . _1 . unTO)
drawShader (_fullscreenShader pdata) 4 drawShader (_fullscreenShader pdata) 4
--set viewport for radial distortion --set viewport for radial distortion
setViewportSize (round winx) (round winy) --setViewportSize (round winx) (round winy)
setViewportType _graphics_overlay_resolution cfig
glDepthFunc GL_ALWAYS glDepthFunc GL_ALWAYS
glBlendFunc GL_ONE GL_ZERO glBlendFunc GL_ONE GL_ZERO
-- perform any radial distortion -- perform any radial distortion
@@ -371,3 +374,11 @@ getDistortions cfig w
setViewportSize :: Int -> Int -> IO () setViewportSize :: Int -> Int -> IO ()
setViewportSize x y = glViewport 0 0 (fromIntegral x) (fromIntegral y) setViewportSize x y = glViewport 0 0 (fromIntegral x) (fromIntegral y)
getWindowSize :: Integral a => (Configuration -> ResFactor) -> Configuration -> (a,a)
getWindowSize f cfig = (g _windowX,g _windowY)
where
g h = fromIntegral $ round (h cfig) `div` resFactorNum (f cfig)
setViewportType :: (Configuration -> ResFactor) -> Configuration -> IO ()
setViewportType f = uncurry (glViewport 0 0) . getWindowSize f
+1 -1
View File
@@ -7,4 +7,4 @@ getWindowSize cfig = (x `div` divRes,y `div` divRes)
where where
x = round $ _windowX cfig x = round $ _windowX cfig
y = round $ _windowY cfig y = round $ _windowY cfig
divRes = resFactorNum $ _graphics_resolution_factor cfig divRes = resFactorNum $ _graphics_world_resolution cfig
+24 -26
View File
@@ -7,7 +7,7 @@ module Framebuffer.Update (
sizeFBOs, sizeFBOs,
) where ) where
import Dodge.DownscaleSize import Dodge.Data.Config
import Shader.Data import Shader.Data
import Framebuffer.Check import Framebuffer.Check
import Control.Lens import Control.Lens
@@ -19,52 +19,45 @@ import Graphics.GL.Core45
import Unsafe.Coerce import Unsafe.Coerce
sizeFBOs :: sizeFBOs ::
-- | Scaled width Configuration ->
Int ->
-- | Scaled height
Int ->
-- | Full width
Int ->
-- | Full height
Int ->
RenderData -> RenderData ->
IO RenderData IO RenderData
sizeFBOs xsize ysize xfull yfull rdata = do sizeFBOs cfig rdata = do
resizeRBO (_rboBaseBloom rdata) xsize ysize uncurry (resizeRBO (_rboBaseBloom rdata)) (getWindowSize _graphics_world_resolution cfig)
rdata1 <- updateFBOTO3 xsize ysize GL_NEAREST GL_NEAREST GL_RGBA8 GL_RGBA16F GL_RGBA16F rdata fboBase rdata1 <- uncurry updateFBOTO3 (getWindowSize _graphics_world_resolution cfig)
rdata2 <- updateFBOTO3 xsize ysize GL_NEAREST GL_NEAREST GL_RGBA8 GL_RGBA16F GL_RGBA16F rdata1 fboCloud GL_NEAREST GL_NEAREST GL_RGBA8 GL_RGBA16F GL_RGBA16F rdata fboBase
rdata' <- updateFBOTO xsize ysize GL_NEAREST GL_NEAREST GL_RGBA8 rdata2 fboLighting rdata2 <- uncurry updateFBOTO3 (getWindowSize _graphics_world_resolution cfig)
GL_NEAREST GL_NEAREST GL_RGBA8 GL_RGBA16F GL_RGBA16F rdata1 fboCloud
rdata' <- uncurry updateFBOTO (getWindowSize _graphics_world_resolution cfig)
GL_NEAREST GL_NEAREST GL_RGBA8 rdata2 fboLighting
rdata'' <- rdata'' <-
foldM foldM
(updateFBOTO xsize ysize GL_LINEAR_MIPMAP_LINEAR GL_LINEAR GL_RGBA16F) (uncurry updateFBOTO (getWindowSize _graphics_world_resolution cfig)
GL_LINEAR_MIPMAP_LINEAR GL_LINEAR GL_RGBA16F)
rdata' rdata'
[fboBloom, fboPos] [fboBloom, fboPos]
rdata''' <- rdata''' <-
foldM foldM
(updateFBOTO xfull yfull GL_NEAREST GL_NEAREST GL_RGBA8) (uncurry updateFBOTO (getWindowSize _graphics_overlay_resolution cfig) GL_NEAREST GL_NEAREST GL_RGBA8)
rdata'' rdata''
[fbo2, fbo3] [fbo2, fbo3]
rdata4 <- rdata4 <-
foldM foldM
(updateFBOTO (xfull `div` downSize) (yfull `div` downSize) GL_LINEAR_MIPMAP_LINEAR GL_LINEAR GL_RGBA16F) (uncurry updateFBOTO (getWindowSize _graphics_downsize_resolution cfig) GL_LINEAR_MIPMAP_LINEAR GL_LINEAR GL_RGBA16F)
rdata''' rdata'''
[fboHalf1, fboHalf2, fboHalf3] [fboHalf1, fboHalf2, fboHalf3]
newShadowFBO <- resizeShadowFBO (rdata ^. fboShadow) xsize ysize newShadowFBO <- uncurry (resizeShadowFBO (rdata ^. fboShadow))
(getWindowSize _graphics_world_resolution cfig)
return $ rdata4 & fboShadow .~ newShadowFBO return $ rdata4 & fboShadow .~ newShadowFBO
resizeRBO :: resizeRBO ::
GLuint -> -- RenderbufferObject GLuint -> -- RenderbufferObject
Int -> GLsizei ->
Int -> GLsizei ->
IO () IO ()
resizeRBO rboName xsize ysize = do resizeRBO rboName = glNamedRenderbufferStorage
let xsize' = fromIntegral xsize
ysize' = fromIntegral ysize
glNamedRenderbufferStorage
rboName rboName
GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8
xsize'
ysize'
updateFBOTO :: updateFBOTO ::
Int -> Int ->
@@ -228,3 +221,8 @@ initializeTexture2DArray fbo attachpoint x y z minfilt magfilt informat = do
glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt) glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt)
glNamedFramebufferTexture (_unFBO fbo) attachpoint to1 0 glNamedFramebufferTexture (_unFBO fbo) attachpoint to1 0
return to1 return to1
getWindowSize :: Integral a => (Configuration -> ResFactor) -> Configuration -> (a,a)
getWindowSize f cfig = (g _windowX,g _windowY)
where
g h = fromIntegral $ round (h cfig) `div` resFactorNum (f cfig)
+7 -4
View File
@@ -4,6 +4,7 @@ module Preload.Update (
pdataResizeUpdate, pdataResizeUpdate,
) where ) where
import Dodge.Data.Config
import Control.Lens import Control.Lens
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC import qualified Data.ByteString.Char8 as BSC
@@ -14,6 +15,7 @@ import Shader.Compile
import Shader.Data import Shader.Data
pdataResizeUpdate :: pdataResizeUpdate ::
Configuration ->
-- | Scaled width -- | Scaled width
Int -> Int ->
-- | Scaled height -- | Scaled height
@@ -24,11 +26,12 @@ pdataResizeUpdate ::
Int -> Int ->
PreloadData -> PreloadData ->
IO PreloadData IO PreloadData
pdataResizeUpdate xsize ysize xfull yfull pdata = do pdataResizeUpdate cfig xsize ysize xfull yfull pdata = do
rd <- renderDataResizeUpdate xsize ysize xfull yfull (_renderData pdata) rd <- renderDataResizeUpdate cfig xsize ysize xfull yfull (_renderData pdata)
return (pdata{_renderData = rd}) return (pdata{_renderData = rd})
renderDataResizeUpdate :: renderDataResizeUpdate ::
Configuration ->
-- | Scaled width -- | Scaled width
Int -> Int ->
-- | Scaled height -- | Scaled height
@@ -39,8 +42,8 @@ renderDataResizeUpdate ::
Int -> Int ->
RenderData -> RenderData ->
IO RenderData IO RenderData
renderDataResizeUpdate xsize ysize xfull yfull rdata = do renderDataResizeUpdate cfig xsize ysize xfull yfull rdata = do
rdata' <- sizeFBOs xsize ysize xfull yfull rdata rdata' <- sizeFBOs cfig rdata
bbVert <- BS.readFile "shader/texture/bloomBlur.vert" bbVert <- BS.readFile "shader/texture/bloomBlur.vert"
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