Prevent cloud "pop" when an overlapping cloud fades out to nothing

This commit is contained in:
2023-03-21 14:46:41 +00:00
parent e56ca3dd8d
commit d5fbc06332
7 changed files with 40 additions and 17 deletions
+4 -3
View File
@@ -21,14 +21,15 @@ void main()
//float rad = vCenterSize.w; //float rad = vCenterSize.w;
float rad = vCenterSize.w*0.5; float rad = vCenterSize.w*0.5;
float h = (1-d) * rad; float h = (1-d) * rad;
fPos = vec4(vPosID.xy, vPosID.z + h, 1); fPos = vec4(vPosID.xy, vPosID.z + h, vCol.w*(1-d));
float h1 = float (1 - 0.01*fPos.z); float h1 = float (1 - 0.01*fPos.z);
//vec3 fn1 = fPos.z*(1-d)*normalize(vec3(vCenterSize.xyz - fPos.xyz)); //vec3 fn1 = fPos.z*(1-d)*normalize(vec3(vCenterSize.xyz - fPos.xyz));
//vec3 fn1 = fPos.z*normalize(vec3(vCenterSize.xyz - fPos.xyz)); //vec3 fn1 = fPos.z*normalize(vec3(vCenterSize.xyz - fPos.xyz));
//vec3 fn1 = vec3(vCenterSize.xyz - fPos.xyz); //vec3 fn1 = vec3(vCenterSize.xyz - fPos.xyz);
vec3 fn1 = fPos.z*(1-d)*normalize(vec3(vCenterSize.xyz - (fPos.xyz + vec3(0,0,0.5*h)))); //vec3 fn1 = fPos.z*(1-d)*normalize(vec3(vCenterSize.xyz - (fPos.xyz + vec3(0,0,0.5*h))));
vec3 fn1 = fPos.z*normalize(vec3(vCenterSize.xyz - (fPos.xyz + vec3(0,0,0.5*h))));
//fNorm = vec4(0.5*fn1.xy,fn1.z, 0.5); //fNorm = vec4(0.5*fn1.xy,fn1.z, 0.5);
//fNorm = vec4(fn1.xyz, fCol.w); //fNorm = vec4(fn1.xyz, fCol.w);
fNorm = vec4(fn1,1); fNorm = vec4(fn1,fPos.w);
//fNorm = vec4(0,0,1, 1); //fNorm = vec4(0,0,1, 1);
} }
+1 -1
View File
@@ -29,7 +29,7 @@ data RenderData = RenderData
, _wallBlankShader :: FullShader , _wallBlankShader :: FullShader
, _windowShader :: FullShader , _windowShader :: FullShader
, _wallTextureShader :: FullShader , _wallTextureShader :: FullShader
, _fullscreenShader :: FullShader , _fullscreenShader :: Shader
, _bloomBlurShader :: FullShader , _bloomBlurShader :: FullShader
, _colorBlurShader :: FullShader , _colorBlurShader :: FullShader
, _barrelShader :: (FullShader,VBO) , _barrelShader :: (FullShader,VBO)
+2 -1
View File
@@ -10,7 +10,8 @@ import Geometry
testEvent :: World -> World testEvent :: World -> World
testEvent w = w testEvent w = w
& cWorld . lWorld . worldEvents .~ SoundStart BackgroundSound (V2 0 0) foamSprayFadeOutS Nothing : & cWorld . lWorld . worldEvents .~ SoundStart BackgroundSound (V2 0 0) foamSprayFadeOutS Nothing :
[MakeStartCloudAt (V3 (cx + x) (cy + y) 5) | x <- [-5, -4 .. 5], y <- [-5, -4 .. 5]] --[MakeStartCloudAt (V3 (cx + x) (cy + y) 5) | x <- [-5, -4 .. 5], y <- [-5, -4 .. 5]]
[MakeStartCloudAt (V3 (cx + x) (cy + y) 5) | x <- [0], y <- [0]]
where where
V2 cx cy = w ^?! cWorld . lWorld . creatures . ix 0 . crPos V2 cx cy = w ^?! cWorld . lWorld . creatures . ix 0 . crPos
+16 -6
View File
@@ -234,7 +234,7 @@ doDrawing' win pdata u = do
glDepthFunc GL_ALWAYS glDepthFunc GL_ALWAYS
glBindTexture GL_TEXTURE_2D (pdata ^. fboBloom . _2 . unTO) glBindTexture GL_TEXTURE_2D (pdata ^. fboBloom . _2 . unTO)
glDisable GL_BLEND glDisable GL_BLEND
drawShader (_bloomBlurShader pdata) 4 drawFullShader (_bloomBlurShader pdata) 4
replicateM_ 9 $ pingPongBetween (_fboHalf1 pdata) (_fboHalf2 pdata) (_bloomBlurShader pdata) replicateM_ 9 $ 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` resFact) (round winy `div` resFact)
@@ -264,7 +264,7 @@ doDrawing' win pdata u = do
(fromIntegral nCloudIs) (fromIntegral nCloudIs)
GL_UNSIGNED_SHORT GL_UNSIGNED_SHORT
nullPtr nullPtr
drawShader (_windowShader pdata) nWins drawFullShader (_windowShader pdata) nWins
when (_graphics_cloud_shadows cfig) $ do when (_graphics_cloud_shadows cfig) $ do
----render transparency depths ----render transparency depths
glDepthMask GL_TRUE glDepthMask GL_TRUE
@@ -286,7 +286,8 @@ doDrawing' win pdata u = do
-- the idea is to (roughly) get the average position -- the idea is to (roughly) get the average position
--glBlendFunci 1 GL_ONE_MINUS_DST_ALPHA GL_DST_ALPHA --glBlendFunci 1 GL_ONE_MINUS_DST_ALPHA GL_DST_ALPHA
-- or, if we order the clouds, just get the top pos -- or, if we order the clouds, just get the top pos
glBlendFunci 1 GL_ONE GL_ZERO --glBlendFunci 1 GL_ONE GL_ZERO
glBlendFuncSeparatei 1 GL_SRC_ALPHA GL_ONE GL_ONE GL_ONE
-- and to sum the normals (based on the alpha) -- and to sum the normals (based on the alpha)
glBlendFunci 2 GL_SRC_ALPHA GL_ONE glBlendFunci 2 GL_SRC_ALPHA GL_ONE
-- just get the top normal -- just get the top normal
@@ -298,7 +299,15 @@ doDrawing' win pdata u = do
(fromIntegral nCloudIs) (fromIntegral nCloudIs)
GL_UNSIGNED_SHORT GL_UNSIGNED_SHORT
nullPtr nullPtr
drawShader (_windowShader pdata) nWins drawFullShader (_windowShader pdata) nWins
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboPos . _1 . unFBO)
withArray [0,0,0,0] $ \ptr -> glClearNamedFramebufferfv
(pdata ^. fboPos . _1 . unFBO)
GL_COLOR
0
ptr
glBindTextureUnit 0 (pdata ^. fboCloud . _2 . _2 . unTO)
drawShader (pdata ^. alphaDivideShader) 4
glEnable GL_BLEND glEnable GL_BLEND
----draw lightmap for cloud buffer ----draw lightmap for cloud buffer
glDepthMask GL_FALSE glDepthMask GL_FALSE
@@ -313,7 +322,8 @@ doDrawing' win pdata u = do
nSilIndices nSilIndices
nIndices nIndices
(_graphics_object_shadows $ _uvConfig u) (_graphics_object_shadows $ _uvConfig u)
(pdata ^. fboCloud . _2 . _2) --(pdata ^. fboCloud . _2 . _2)
(pdata ^. fboPos . _2)
(pdata ^. fboCloud . _2 . _3) (pdata ^. fboCloud . _2 . _3)
glInvalidateBufferData (pdata ^. vboShapes . vboName) glInvalidateBufferData (pdata ^. vboShapes . vboName)
--apply lightmap to cloud buffer --apply lightmap to cloud buffer
@@ -352,7 +362,7 @@ doDrawing' win pdata u = do
bindDrawDist (RadialDistortion (V2 a b) (V2 c d) (V2 e f) g) = do bindDrawDist (RadialDistortion (V2 a b) (V2 c d) (V2 e f) g) = do
pokeArray (shadVBOptr $ _barrelShader pdata) [a, b, c, d, e, f, g] pokeArray (shadVBOptr $ _barrelShader pdata) [a, b, c, d, e, f, g]
bufferPokedVBO (snd $ _barrelShader pdata) 1 bufferPokedVBO (snd $ _barrelShader pdata) 1
drawShader (fst $ _barrelShader pdata) 1 drawFullShader (fst $ _barrelShader pdata) 1
fboList = fboList =
take (length rds - 1) (concat (repeat [fst $ _fbo2 pdata, fst $ _fbo3 pdata])) take (length rds - 1) (concat (repeat [fst $ _fbo2 pdata, fst $ _fbo3 pdata]))
++ [FBO 0] ++ [FBO 0]
+1 -1
View File
@@ -145,7 +145,7 @@ preloadRender = do
0 0
screentexturevao <- setupVAOvbo' [2,2] 4 screentexturevbo screentexturevao <- setupVAOvbo' [2,2] 4 screentexturevbo
alphadivideshader <- makeShader4UsingVAO "texture2D/alphaDivide" [vert,frag] GL_TRIANGLE_STRIP screentexturevao alphadivideshader <- makeShader4UsingVAO "texture2D/alphaDivide" [vert,frag] GL_TRIANGLE_STRIP screentexturevao
fsShad <- makeShaderUsingVAO "texture/simple" [vert, frag] ETriangleStrip screentexturevao fsShad <- makeShader4UsingVAO "texture/simple" [vert, frag] GL_TRIANGLE_STRIP screentexturevao
bloomBlurShad <- makeShaderUsingVAO "texture/bloomBlur" [vert, frag] ETriangleStrip screentexturevao bloomBlurShad <- makeShaderUsingVAO "texture/bloomBlur" [vert, frag] ETriangleStrip screentexturevao
colorBlurShad <- makeShaderUsingVAO "texture/colorBlur" [vert, frag] ETriangleStrip screentexturevao colorBlurShad <- makeShaderUsingVAO "texture/colorBlur" [vert, frag] ETriangleStrip screentexturevao
grayscaleShad <- makeShaderUsingVAO "texture/grayscale" [vert, frag] ETriangleStrip screentexturevao grayscaleShad <- makeShaderUsingVAO "texture/grayscale" [vert, frag] ETriangleStrip screentexturevao
+2 -2
View File
@@ -346,12 +346,12 @@ pingPongBetween (fb1, to1) (fb2, to2) fs = do
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fb2) glBindFramebuffer GL_FRAMEBUFFER (_unFBO fb2)
--textureBinding Texture2D $= Just to1 --textureBinding Texture2D $= Just to1
glBindTexture GL_TEXTURE_2D (_unTO to1) glBindTexture GL_TEXTURE_2D (_unTO to1)
drawShader fs 4 drawFullShader fs 4
--bindFramebuffer Framebuffer $= fb1 --bindFramebuffer Framebuffer $= fb1
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fb1) glBindFramebuffer GL_FRAMEBUFFER (_unFBO fb1)
--textureBinding Texture2D $= Just to2 --textureBinding Texture2D $= Just to2
glBindTexture GL_TEXTURE_2D (_unTO to2) glBindTexture GL_TEXTURE_2D (_unTO to2)
drawShader fs 4 drawFullShader fs 4
renderFoldable :: renderFoldable ::
MV.MVector (PrimState IO) (FullShader,VBO) -> MV.MVector (PrimState IO) (FullShader,VBO) ->
+14 -3
View File
@@ -2,6 +2,7 @@ module Shader
( freeShaderPointers' ( freeShaderPointers'
, drawShaderLay , drawShaderLay
, shadVBOptr , shadVBOptr
, drawFullShader
, drawShader , drawShader
, pokeBindFoldable , pokeBindFoldable
, pokeBindFoldableLayer , pokeBindFoldableLayer
@@ -35,9 +36,9 @@ drawShaderLay l countsVector shadIn fs = do
(fromIntegral $ l*numSubElements) (fromIntegral $ l*numSubElements)
(fromIntegral i) (fromIntegral i)
drawShader :: FullShader -> Int -> IO () drawFullShader :: FullShader -> Int -> IO ()
{-# INLINE drawShader #-} {-# INLINE drawFullShader #-}
drawShader fs i = do drawFullShader fs i = do
glUseProgram (_shadName fs) glUseProgram (_shadName fs)
glBindVertexArray $ fs ^. shadVAO . vaoName glBindVertexArray $ fs ^. shadVAO . vaoName
case _shadTex' fs of case _shadTex' fs of
@@ -50,6 +51,16 @@ drawShader fs i = do
0 0
(fromIntegral i) (fromIntegral i)
drawShader :: Shader -> Int -> IO ()
{-# INLINE drawShader #-}
drawShader fs i = do
glUseProgram (_shaderUINT fs)
glBindVertexArray $ fs ^. shaderVAO . vaoName
glDrawArrays
(_shaderPrimitive fs)
0
(fromIntegral i)
freeShaderPointers' :: (FullShader,VBO) -> IO () freeShaderPointers' :: (FullShader,VBO) -> IO ()
freeShaderPointers' = free . _vboPtr . snd freeShaderPointers' = free . _vboPtr . snd