Work on cloud/window transparency

This commit is contained in:
2025-11-09 11:00:12 +00:00
parent 7c62479f30
commit e9ffeeaea7
16 changed files with 221 additions and 168 deletions
+18 -18
View File
@@ -39,15 +39,15 @@ data Config = Config
{ _volume_master :: Float
, _volume_sound :: Float
, _volume_music :: Float
, _graphics_cloud_shadows :: Bool
, _graphics_distortions :: Bool
, _graphics_bloom :: Bool
, _graphics_shadow_rendering :: ShadowRendering
, _graphics_shadow_size :: Importance
, _graphics_downsize_resolution :: ResFactor
, _graphics_world_resolution :: ResFactor
, _graphics_distortion_resolution :: ResFactor
, _graphics_num_shadow_casters :: NumShadowCasters
, _gr_cloud_shadows :: Bool
, _gr_distortions :: Bool
, _gr_bloom :: Bool
, _gr_shadow_rendering :: ShadowRendering
, _gr_shadow_size :: Importance
, _gr_downsize_res :: ResFactor
, _gr_world_res :: ResFactor
, _gr_distortion_res :: ResFactor
, _gr_num_shadow_casters :: NumShadowCasters
, _windowX :: Int --size
, _windowY :: Int
, _windowPosX :: Int --position in os
@@ -133,15 +133,15 @@ defaultConfig =
{ _volume_master = 1
, _volume_sound = 1
, _volume_music = 0
, _graphics_cloud_shadows = True
, _graphics_bloom = True
, _graphics_shadow_rendering = GeoObjShads
, _graphics_shadow_size = Typical
, _graphics_distortions = True
, _graphics_downsize_resolution = EighthRes
, _graphics_world_resolution = QuarterRes
, _graphics_distortion_resolution = FullRes
, _graphics_num_shadow_casters = toEnum 10
, _gr_cloud_shadows = True
, _gr_bloom = True
, _gr_shadow_rendering = GeoObjShads
, _gr_shadow_size = Typical
, _gr_distortions = True
, _gr_downsize_res = EighthRes
, _gr_world_res = QuarterRes
, _gr_distortion_res = FullRes
, _gr_num_shadow_casters = toEnum 10
, _windowX = 800
, _windowY = 600
, _windowPosX = 0
+9 -15
View File
@@ -187,21 +187,15 @@ graphicsMenu = titleOptionsMenu "OPTIONS:GRAPHICS" graphicsMenuOptions
graphicsMenuOptions :: [MenuOption]
graphicsMenuOptions =
[ makeEnumOption graphics_world_resolution "World resolution" (uvIOEffects .~ updatePreload)
, makeEnumOption
graphics_downsize_resolution
"Downsize resolution"
(uvIOEffects .~ updatePreload)
, makeEnumOption
graphics_distortion_resolution
"Distortion resolution"
(uvIOEffects .~ updatePreload)
, makeEnumOption graphics_shadow_rendering "SHADOW RENDERING" id
, makeEnumOption graphics_shadow_size "SHADOW DETAIL" id
, makeEnumOption graphics_distortions "ENABLE DISTORTIONS" id
, makeEnumOption graphics_bloom "ENABLE BLOOM" id
, makeBoolOption graphics_cloud_shadows "CLOUD SHADOWS"
, makeEnumOption graphics_num_shadow_casters "NUM SHADOW CASTERS" id
[ makeEnumOption gr_world_res "World resolution" (uvIOEffects .~ updatePreload)
, makeEnumOption gr_downsize_res "Downsize resolution" (uvIOEffects .~ updatePreload)
, makeEnumOption gr_distortion_res "Distortion resolution" (uvIOEffects .~ updatePreload)
, makeEnumOption gr_shadow_rendering "SHADOW RENDERING" id
, makeEnumOption gr_shadow_size "SHADOW DETAIL" id
, makeEnumOption gr_distortions "ENABLE DISTORTIONS" id
, makeEnumOption gr_bloom "ENABLE BLOOM" id
, makeBoolOption gr_cloud_shadows "CLOUD SHADOWS"
, makeEnumOption gr_num_shadow_casters "NUM SHADOW CASTERS" id
]
gameOverMenu :: Universe -> ScreenLayer
+55 -26
View File
@@ -76,7 +76,7 @@ doDrawing' win pdata u = do
wallsToPoke
)
( pokeShape
(drawShadowsByImportance $ cfig ^. graphics_shadow_size)
(drawShadowsByImportance $ cfig ^. gr_shadow_size)
(_vboPtr $ _vboShapes pdata)
(_eboPtr $ _shapeEBO pdata)
(_eboPtr $ _silhouetteEBO pdata)
@@ -111,7 +111,7 @@ doDrawing' win pdata u = do
]
-- set the coordinate uniform ready for drawing elements using world coordinates
bufferPerspectiveMatrixUBO cfig (w ^. wCam) (pdata ^. matUBO)
setViewport _graphics_world_resolution cfig
setViewport _gr_world_res cfig
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase . _1 . unFBO)
glDepthMask GL_TRUE
glDisable GL_BLEND
@@ -257,7 +257,7 @@ doDrawing' win pdata u = do
--setup downscale viewport for blurring bloom
--setViewportSize (round winx `div` (2 * resFact)) (round winy `div` (2 * resFact))
setViewport _graphics_downsize_resolution cfig
setViewport _gr_downsize_res cfig
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboHalf1 pdata)))
glDepthFunc GL_ALWAYS
glBindTextureUnit 0 (pdata ^. fboBloom . _2 . unTO)
@@ -271,11 +271,11 @@ doDrawing' win pdata u = do
-- glClearNamedFramebufferfv (pdata ^. fboHalf2 . _1 . unFBO) GL_COLOR 0
-- glBlendFunc GL_ONE GL_ONE_MINUS_SRC_ALPHA
drawShader (_bloomBlurShader pdata) 4
when (cfig ^. graphics_bloom) $ do
when (cfig ^. gr_bloom) $ do
replicateM_ 2 $ pingPongBetween
(_fboHalf1 pdata) (_fboHalf2 pdata) (_bloomBlurShader pdata)
glEnable GL_BLEND
setViewport _graphics_world_resolution cfig
setViewport _gr_world_res cfig
--draw clouds onto cloud buffer
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboCloud . _1 . unFBO)
glDepthFunc GL_LEQUAL
@@ -297,15 +297,15 @@ doDrawing' win pdata u = do
(fromIntegral nCloudIs)
GL_UNSIGNED_SHORT
nullPtr
glEnable GL_CULL_FACE
glEnable GL_DEPTH_CLAMP
glCullFace GL_BACK
drawShader (_windowShader pdata) nWins
glDisable GL_DEPTH_CLAMP
glDisable GL_CULL_FACE
when (_graphics_cloud_shadows cfig) $ do
-- glEnable GL_CULL_FACE
-- glEnable GL_DEPTH_CLAMP
-- glCullFace GL_BACK
---- drawShader (_windowShader pdata) nWins
-- glDisable GL_DEPTH_CLAMP
-- glDisable GL_CULL_FACE
when (_gr_cloud_shadows cfig) $ do
----render transparency depths
glDepthMask GL_TRUE
-- glDepthMask GL_TRUE
glDepthFunc GL_ALWAYS
glDisable GL_BLEND
withArray [GL_NONE, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $
@@ -317,24 +317,25 @@ doDrawing' win pdata u = do
glEnable GL_BLEND
-- we sum the positions weighted by alpha, and sum the alpha
glBlendFuncSeparatei 1 GL_SRC_ALPHA GL_ONE GL_ONE GL_ONE
--glBlendFuncSeparatei 1 GL_ONE GL_ZERO GL_ONE GL_ZERO
-- and sum the normals weighted by alpha
--glBlendFunci 2 GL_SRC_ALPHA GL_ONE
glBlendFunci 2 GL_SRC_ALPHA GL_ONE
glUseProgram (pdata ^. cloudShader . shaderUINT)
glBindVertexArray $ pdata ^. cloudShader . shaderVAO . vaoName
glDepthMask GL_TRUE
-- glDepthMask GL_TRUE
glDrawElements
(pdata ^. cloudShader . shaderPrimitive . unPrimitiveMode)
(fromIntegral nCloudIs)
GL_UNSIGNED_SHORT
nullPtr
---
glEnable GL_CULL_FACE
glEnable GL_DEPTH_CLAMP
glCullFace GL_BACK
drawShader (_windowShader pdata) nWins
glDisable GL_DEPTH_CLAMP
glDisable GL_CULL_FACE
-- glEnable GL_CULL_FACE
-- glEnable GL_DEPTH_CLAMP
-- glCullFace GL_BACK
---- drawShader (_windowShader pdata) nWins
-- glDisable GL_DEPTH_CLAMP
-- glDisable GL_CULL_FACE
-- drawShader (_windowShader pdata) nWins
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboPos . _1 . unFBO)
withArray [0, 0, 0, 0] $ \ptr ->
@@ -360,6 +361,22 @@ doDrawing' win pdata u = do
(pdata ^. fboCloud . _2 . _3)
lightPoints
pdata
--draw windows onto window buffer
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboWindow . _1 . unFBO)
withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1] $
glNamedFramebufferDrawBuffers (pdata ^. fboWindow . _1 . unFBO) 2
withArray [0, 0, 0, 0] $
glClearNamedFramebufferfv (pdata ^. fboWindow . _1 . unFBO) GL_COLOR 0
withArray [0, 0, 0, 0] $
glClearNamedFramebufferfv (pdata ^. fboWindow . _1 . unFBO) GL_COLOR 1
glEnable GL_CULL_FACE
glEnable GL_DEPTH_CLAMP
glDepthFunc GL_LEQUAL
glCullFace GL_BACK
glDisable GL_BLEND
drawShader (_windowShader pdata) nWins
glDisable GL_DEPTH_CLAMP
glDisable GL_CULL_FACE
glInvalidateBufferData (pdata ^. vboShapes . vboName)
--apply lightmap to cloud buffer
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboCloud pdata)))
@@ -374,13 +391,24 @@ doDrawing' win pdata u = do
drawShader (_fullscreenShader pdata) 4
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
-- bind base buffer for drawing clouds and bloom
--glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboBase pdata)))
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase . _1 . unFBO)
--draw shadowed clouds onto base buffer
glBindTextureUnit 0 (pdata ^. fboCloud . _2 . _1 . unTO)
drawShader (_fullscreenShader pdata) 4
-- --draw shadowed clouds onto base buffer
-- glBindTextureUnit 0 (pdata ^. fboCloud . _2 . _1 . unTO)
-- drawShader (_fullscreenShader pdata) 4
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
-- --draw windows onto base buffer
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
glBindTextureUnit 0 (pdata ^. fboWindow . _2 . _1 . unTO)
glBindTextureUnit 1 (pdata ^. fboWindow . _2 . _2 . unTO)
glBindTextureUnit 2 (pdata ^. fboCloud . _2 . _1 . unTO)
--glBindTextureUnit 3 (pdata ^. fboCloud . _2 . _2 . unTO)
glBindTextureUnit 3 (pdata ^. fboPos . _2 . unTO)
drawShader (_transparencyCompShader pdata) 4
--Draw blurred bloom onto base buffer
glEnable GL_BLEND
@@ -388,7 +416,8 @@ doDrawing' win pdata u = do
--glBlendFunc GL_ONE GL_ONE
glBindTextureUnit 0 (_unTO . snd $ _fboHalf1 pdata)
drawShader (_fullscreenShader pdata) 4
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
-- glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
--set viewport for radial distortion
--setViewportSize (round winx) (round winy)
@@ -397,7 +426,7 @@ doDrawing' win pdata u = do
glBlendFunc GL_ONE GL_ZERO
-- perform any radial distortion
-- this is hideous
case (getDistortions cfig w, cfig ^. graphics_distortions) of
case (getDistortions cfig w, cfig ^. gr_distortions) of
(rds, x) | null rds || not x -> do
glBindTextureUnit 0 $ pdata ^. fboBase . _2 . _1 . unTO
glBindFramebuffer GL_FRAMEBUFFER 0
@@ -440,7 +469,7 @@ bufferPerspectiveMatrixUBO cfig cam uboid = withArray
getDistortions :: Config -> World -> [Distortion]
getDistortions cfig w
| cfig ^. graphics_distortions = w ^. cWorld . lWorld . distortions
| cfig ^. gr_distortions = w ^. cWorld . lWorld . distortions
| otherwise = []
setViewport :: (Config -> ResFactor) -> Config -> IO ()
+1 -1
View File
@@ -13,7 +13,7 @@ import Control.Lens
lightsToRender :: Config -> Camera -> LWorld -> [(Point3, Float, Point3)]
{-# INLINE lightsToRender #-}
lightsToRender cfig campos w = take (fromEnum $ cfig ^. graphics_num_shadow_casters) $
lightsToRender cfig campos w = take (fromEnum $ cfig ^. gr_num_shadow_casters) $
sortOn (\(_,x,_) -> negate x) $
mapMaybe getLS (IM.elems $ w ^. lightSources)
++ mapMaybe getlsparam (w ^. lights)
+1 -1
View File
@@ -1,4 +1,4 @@
module Dodge.WindowSize where
module Dodge.WindowSize (getWindowSize) where
import Dodge.Data.Config