Work on transparency of windows/clouds

This commit is contained in:
2025-11-20 12:02:05 +00:00
parent 10dbb238c8
commit 6563d87247
7 changed files with 49 additions and 37 deletions
+7 -4
View File
@@ -1,11 +1,14 @@
#version 450 core
layout (location=0) out vec4 fCol;
layout (location=1) out vec4 fPos;
layout (location=0) out vec4 fColOverCloud;
layout (location=1) out vec4 fColUnderCloud;
layout(binding = 3) uniform sampler2D cloudpos;
in vec4 vCol;
in vec4 vPos;
in vec2 vScreenPos;
void main()
{
fCol = vCol;
fPos = vPos;
float cloudz = texture(cloudpos, vScreenPos).z;
fColOverCloud = ( cloudz > vPos.z ? vec4(0) : vCol);
fColUnderCloud = ( cloudz > vPos.z ? vCol : vec4(0));
fColUnderCloud = vec4(0);
}
+10 -2
View File
@@ -4,14 +4,22 @@ layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
layout (std430, binding = 1) readonly buffer Pos { PosCol data[]; };
out vec4 vCol;
out vec4 vPos;
int indices[6] = {0,1,3,0,3,2};
out vec2 vScreenPos;
//int indices[6] = {0,1,3,0,3,2};
int indices[6] =
{0,3,1
,0,2,3};
// note reversed compared to walls
void main()
{
vCol = data[gl_VertexID / 6].col;
vec4 pp = data[gl_VertexID / 6].pospos;
int j = indices[gl_VertexID % 6];
float z = (j > 1.5 ? 5000 : 0);
//float z = (j > 1.5 ? 5000 : 0);
float z = (j > 1.5 ? 200 : 0);
vec2 xy = (j % 2 > 0 ? pp.xy : pp.zw);
vPos = vec4( xy, z, 1);
gl_Position = theMat * vPos;
vScreenPos = 0.5 * (vec2(1) + vec2(gl_Position.x / gl_Position.w
,gl_Position.y / gl_Position.w));
}
+3 -13
View File
@@ -138,7 +138,7 @@ makeFragBullets p w = w & cWorld . lWorld . bullets .++~ bus
f a s =
defaultBullet
& buPayload .~ BulPlain 5
& buVel .~ s *.* unitVectorAtAngle a
& buVel .~ s *^ unitVectorAtAngle a
& buDrag .~ 0.8
& buPos .~ p
& buOldPos .~ p
@@ -151,20 +151,10 @@ makeFlak bu _ w = w & cWorld . lWorld . bullets .++~ [f x | x <- xs]
f x =
bu & buVel %~ g x
& buPayload .~ BulPlain 25
g x v = v +.+ x *.* normalizeV (vNormal v)
g x v = v + x *^ normalizeV (vNormal v)
hitEffFromBul :: World -> Bullet -> (World, Bullet)
hitEffFromBul w bu = hitEffFromBul' w' bu
where
w' = w & cWorld . lWorld . distortions .:~ x
x = RadialDistortion (_buPos bu + _buVel bu) (V2 50 0) (V2 0 50)
(v3 & _3 .~ t) (v3 & _3 .~ negate t) v3 1
v3 = V3 (V2 1 0) (V2 0 1) 0
t = vNormal (_buVel bu)
-- (V2 1 0) (V2
hitEffFromBul' :: World -> Bullet -> (World, Bullet)
hitEffFromBul' w bu = case _buEffect bu of
hitEffFromBul w bu = case _buEffect bu of
PenetrateBullet -> movePenBullet bu hitstream w
BounceBullet -> fromMaybe (expireAndDamage bu hitstream w) $ do
(hp, crwl) <- hitstream ^? _head
+1 -2
View File
@@ -6,8 +6,7 @@ import Dodge.Data.Material
import Color
materialColor :: Material -> Color
materialColor =
withAlpha 0.5 . \case
materialColor = \case
Wood -> dark yellow
Dirt -> dark $ dark orange
Stone -> greyN 0.5
+20 -14
View File
@@ -308,7 +308,9 @@ doDrawing' win pdata u = do
glDepthFunc GL_LEQUAL
glDepthMask GL_FALSE
glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA GL_ONE
--glBlendFunc GL_SRC_ALPHA GL_ONE
glBindTextureUnit 3 (pdata ^. fboPos . _2 . unTO)
glBlendFunc GL_ONE_MINUS_DST_ALPHA GL_ONE_MINUS_SRC_ALPHA
glUseProgram $ pdata ^. windowPullShader
glBindVertexArray $ pdata ^. dummyVAO
glDrawArrays GL_TRIANGLES 0 (fromIntegral nWins * 6)
@@ -327,22 +329,26 @@ doDrawing' win pdata u = do
glUseProgram (pdata ^. fullscreenShader)
glDrawArrays GL_TRIANGLES 0 6
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
-- bind base buffer for drawing clouds and bloom
--
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase . _1 . unFBO)
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 ^. fboPos . _2 . unTO)
--drawShader (_transparencyCompShader pdata) 4
glUseProgram (pdata ^. transparencyCompShader)
glUseProgram (pdata ^. fullscreenShader)
glBindTextureUnit 0 (pdata ^. fboWindow . _2 . _2 . unTO)
glDrawArrays GL_TRIANGLES 0 6
glBindTextureUnit 0 (pdata ^. fboCloud . _2 . _1 . unTO)
glDrawArrays GL_TRIANGLES 0 6
glBindTextureUnit 0 (pdata ^. fboWindow . _2 . _1 . unTO)
glDrawArrays GL_TRIANGLES 0 6
-- -- --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 ^. fboPos . _2 . unTO)
--
-- --drawShader (_transparencyCompShader pdata) 4
-- glUseProgram (pdata ^. transparencyCompShader)
-- glDrawArrays GL_TRIANGLES 0 6
--Draw blurred bloom onto base buffer
glEnable GL_BLEND
+7 -1
View File
@@ -1,5 +1,6 @@
module Dodge.Render.Walls (wallsToDraw) where
import Color.Data
import qualified Control.Foldl as L
import Control.Lens
import Dodge.Base.Wall
@@ -11,6 +12,7 @@ import Dodge.Wall.Draw
--import Dodge.Zoning.World
import Geometry
import ShapePicture
import Linear
-- not necessary: should just poke all walls to their wanted places
wallsToDraw :: World -> ([((Point2, Point2), Point4)], SPic, [Wall])
@@ -25,7 +27,11 @@ wallsToDraw w =
where
-- (wlsFromIXs w $ zonesExtract (w ^. wlZoning) $ zoneOfSight wlZoneSize cam)
f wl = (_wlLine wl, materialColor $ _wlMaterial wl)
f wl = (_wlLine wl, setWindowColor $ materialColor $ _wlMaterial wl)
setWindowColor :: Color -> Color
setWindowColor c = c & _w .~ 0.25
--setWindowColor (V4 r g b _) = V4 (r*0.5) (g*0.5) (b*0.5) 0.8
-- cam = w ^. cWorld . camPos
+1 -1
View File
@@ -17,7 +17,7 @@ drawForceField wl =
noShape
. setLayer BloomLayer
. setDepth 20
. color (materialColor (wl ^. wlMaterial))
. color (withAlpha 0.5 $ materialColor (wl ^. wlMaterial))
$ thickLine 5 [a, b]
where
(a, b) = _wlLine wl