From 05c530eeb179a6c059b71b5398879762bda8efbe Mon Sep 17 00:00:00 2001 From: justin Date: Tue, 4 Nov 2025 10:42:18 +0000 Subject: [PATCH] Play around with alpha blending --- shader/lighting/lineShadow.geom | 31 ++++++++++--------------------- src/Dodge/Render.hs | 8 ++++++-- src/Dodge/Render/HUD.hs | 9 +++++---- tags | 18 +++++++++--------- 4 files changed, 30 insertions(+), 36 deletions(-) diff --git a/shader/lighting/lineShadow.geom b/shader/lighting/lineShadow.geom index 39a2ddfc3..fe83d9fcc 100644 --- a/shader/lighting/lineShadow.geom +++ b/shader/lighting/lineShadow.geom @@ -4,8 +4,6 @@ layout(triangle_strip, max_vertices = 4) out; layout(std140, binding = 0) uniform TheMat { mat4 theMat; }; layout(location=0) uniform vec3 lightPos; layout(location=1) uniform float radiusUniform; -// vec4 shift (vec4 p) { return (vec4 (p.xyz + -// (lumRad.a*normalize(p.xyz-lightPos)), 1));} float closestPointOnLineParam3 (vec3 a, vec3 b, vec3 p) { return dot(p - a,b-a) / dot(b-a,b-a); } @@ -17,13 +15,10 @@ vec3 closestPointOnSeg3 (vec3 a,vec3 b, vec3 p) { { return a + (x * (b- a));} } } -//vec3 closepoint = -vec4 shift(vec4 p) { return (vec4(p.xyz + (100000 * (p.xyz - lightPos)), 1)); } +vec4 shift(vec4 p) { return (vec4(p.xyz + (10000 * (p.xyz - lightPos)), 1)); } vec4 shiftBy(float x, vec4 p) { return (vec4(lightPos + (x * normalize(p.xyz - lightPos)), 1)); } -// vec4 shift (vec4 p) { return (vec4 (lightPos + -// (lumRad.a*normalize(p.xyz-lightPos)), 1));} // copied from lighting/cap.geom, should not be changed on its own vec4 projNear(vec4 pos) { // note we project to a specific height @@ -34,7 +29,6 @@ vec4 projNear(vec4 pos) { return vec4(xy, 100, 1); } vec4 shiftNear(vec4 pos) -//{ vec4 sp = shiftBy(radiusUniform,pos); { vec4 sp = shift(pos); if (sp.z > 100) { @@ -43,19 +37,16 @@ vec4 shiftNear(vec4 pos) return sp; } } -vec4 f(vec4 p) { return (theMat * p); } void main() { -vec4 p0 = gl_in[0].gl_Position; -vec4 p1 = gl_in[1].gl_Position; -vec3 closepoint = closestPointOnSeg3(p0.xyz,p1.xyz,lightPos); + vec4 p0 = gl_in[0].gl_Position; + vec4 p1 = gl_in[1].gl_Position; + vec3 closepoint = closestPointOnSeg3(p0.xyz,p1.xyz,lightPos); float ru2 = radiusUniform * radiusUniform; vec4 mid = 0.5 * (p0 + p1); vec3 n0a = gl_in[2].gl_Position.xyz; vec3 n1a = gl_in[3].gl_Position.xyz; vec3 n0 = cross(p1.xyz - p0.xyz, n0a - p0.xyz); vec3 n1 = cross(p0.xyz - p1.xyz, n1a - p1.xyz); - - // vec3 n2 = n0 + n1; // assumes the summands are normalized vec3 lightDir = p0.xyz - lightPos.xyz; vec3 lightDir2 = p1.xyz - lightPos.xyz; // first test if the edge is part of the silhouette @@ -66,24 +57,22 @@ vec3 closepoint = closestPointOnSeg3(p0.xyz,p1.xyz,lightPos); // using <= rather than < seems to get rid of overlapping shadow // artefacts { - //vec4 p2 = shiftNear(p0); - //vec4 p3 = shiftNear(p1); vec4 p2 = shiftNear(p0); vec4 p3 = shiftNear(p1); - gl_Position = f(p0); + gl_Position = theMat * p0; EmitVertex(); if (dot(n0, lightDir) > 0) { - gl_Position = f(p2); + gl_Position = theMat * p2; EmitVertex(); - gl_Position = f(p1); + gl_Position = theMat * p1; EmitVertex(); } else { - gl_Position = f(p1); + gl_Position = theMat * p1; EmitVertex(); - gl_Position = f(p2); + gl_Position = theMat * p2; EmitVertex(); } - gl_Position = f(p3); + gl_Position = theMat * p3; EmitVertex(); EndPrimitive(); } else { diff --git a/src/Dodge/Render.hs b/src/Dodge/Render.hs index 1902c336f..93713f373 100644 --- a/src/Dodge/Render.hs +++ b/src/Dodge/Render.hs @@ -231,7 +231,9 @@ doDrawing' win pdata u = do withArray [0, 0, 0, 0] $ glClearNamedFramebufferfv (pdata ^. fboBloom . _1 . unFBO) GL_COLOR 0 glDepthFunc GL_LESS - glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA + --glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA + --glBlendFunc GL_ONE GL_ONE_MINUS_SRC_ALPHA + glBlendFunc GL_ONE GL_ONE glDepthMask GL_FALSE renderLayer BloomNoZWrite shadV pokeCounts glDepthMask GL_TRUE @@ -271,6 +273,7 @@ doDrawing' win pdata u = do glDepthFunc GL_LEQUAL glDepthMask GL_FALSE glBlendFuncSeparatei 0 GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA GL_ONE_MINUS_DST_ALPHA GL_ONE + --glBlendFunci 0 GL_ONE GL_ONE_MINUS_SRC_ALPHA --withArray [GL_COLOR_ATTACHMENT0, GL_NONE] $ withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1] $ glNamedFramebufferDrawBuffers (pdata ^. fboCloud . _1 . unFBO) 2 @@ -408,7 +411,8 @@ doDrawing' win pdata u = do glDepthFunc GL_ALWAYS glDepthMask GL_FALSE glEnable GL_BLEND - glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA + --glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA + glBlendFunc GL_ONE GL_ONE_MINUS_SRC_ALPHA -- assume premultiplied alpha renderLayer DebugLayer shadV pokeCounts glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. matUBO) withArray (scaleMatrix (2 / windowXFloat cfig) (2 / windowYFloat cfig)) $ diff --git a/src/Dodge/Render/HUD.hs b/src/Dodge/Render/HUD.hs index 1ec149f47..c7c1a4ea5 100644 --- a/src/Dodge/Render/HUD.hs +++ b/src/Dodge/Render/HUD.hs @@ -2,6 +2,7 @@ module Dodge.Render.HUD (drawHUD) where +import Linear import Dodge.Clock import qualified Data.Vector as V import Dodge.Terminal @@ -118,7 +119,7 @@ drawMouseOver cfig w = <|> w ^? input . mouseContext . mcoInvFilt sss <- w ^? hud . diSections return . translateScreenPos cfig (invDP ^. ldpPos) - . color (withAlpha 0.1 white) + . color (0.3*^white) -- . color white $ selSecDrawCursorAt invDP curs sss (j, i) -- curs = BoundaryCursor [West] @@ -130,7 +131,7 @@ drawMouseOver cfig w = sss <- w ^? hud . subInventory . ciSections let idp = secondColumnLDP return . translateScreenPos cfig (idp ^. ldpPos) - . color (withAlpha 0.2 white) + . color (0.3*white) $ selSecDrawCursorAt idp curs sss (j, i) drawDragSelected :: Config -> World -> Maybe Picture @@ -146,7 +147,7 @@ drawDragSelected cfig w = do sss <- w ^? hud . diSections let f x = (selSecDrawCursorAt invDP BackdropCursor sss (i, x) <>) return . translateScreenPos cfig (invDP ^. ldpPos) - . color (withAlpha 0.2 white) + . color (0.2*^white) . IS.foldr f mempty $ ys @@ -156,7 +157,7 @@ drawDragSelecting cfig w = do sss <- w ^? hud . diSections let f x = selSecDrawCursorAt invDP BackdropCursor sss (i, x) return . translateScreenPos cfig (invDP ^. ldpPos) - . color (withAlpha 0.2 white) + . color (0.2*^white) . foldMap f $ [min j b .. max j b] diff --git a/tags b/tags index e57781a7d..5cdaf26c7 100644 --- a/tags +++ b/tags @@ -2644,7 +2644,7 @@ beltMag src/Dodge/Item/Ammo.hs 39;" f bfsThenReturn src/Dodge/Creature/ReaderUpdate.hs 225;" f bgateCalc src/Dodge/Inventory/SelectionList.hs 118;" f bgunSound src/Dodge/HeldUse.hs 514;" f -bindFBO src/Render.hs 247;" f +bindFBO src/Render.hs 251;" f bingate src/Dodge/Item/Scope.hs 109;" f black src/Color.hs 27;" f blank src/Picture/Base.hs 59;" f @@ -2700,7 +2700,7 @@ brightX src/Color.hs 116;" f btSPic src/Dodge/Render/ShapePicture.hs 129;" f btText src/Dodge/Inventory/SelectionList.hs 237;" f bufferEBO src/Shader/Bind.hs 28;" f -bufferPerspectiveMatrixUBO src/Dodge/Render.hs 420;" f +bufferPerspectiveMatrixUBO src/Dodge/Render.hs 422;" f bufferPokedVBO src/Shader/Bind.hs 19;" f bufferShaderLayers src/Shader/Bind.hs 36;" f bulletBeltBracer src/Dodge/Item/Equipment.hs 67;" f @@ -2793,7 +2793,7 @@ clang2S src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 676;" f clangS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 542;" f cldtPropagateFold src/Dodge/DoubleTree.hs 358;" f cleanUpPreload src/Preload.hs 10;" f -cleanUpRenderPreload src/Preload/Render.hs 236;" f +cleanUpRenderPreload src/Preload/Render.hs 237;" f cleanUpSoundPreload src/Preload.hs 15;" f cleanupHalted src/Sound.hs 117;" f cleatLabel src/Dodge/Cleat.hs 30;" f @@ -3558,7 +3558,7 @@ getCrMoveSpeed src/Dodge/Creature/Statistics.hs 50;" f getCrsFromRooms src/Dodge/Room/Tutorial.hs 357;" f getCrsFromRooms' src/Dodge/Room/Tutorial.hs 344;" f getDebugMouseOver src/Dodge/Update.hs 377;" f -getDistortions src/Dodge/Render.hs 426;" f +getDistortions src/Dodge/Render.hs 428;" f getEdgesCrossing src/Dodge/Path.hs 42;" f getGrenadeHitEffect src/Dodge/HeldUse.hs 1264;" f getInventoryPath src/Dodge/Inventory/Path.hs 9;" f @@ -4335,7 +4335,7 @@ pincerP src/Dodge/Creature/Boid.hs 63;" f pincerP' src/Dodge/Creature/Boid.hs 96;" f pincerP'' src/Dodge/Creature/Boid.hs 106;" f pincerP''' src/Dodge/Creature/Boid.hs 77;" f -pingPongBetween src/Render.hs 223;" f +pingPongBetween src/Render.hs 227;" f pipe src/Dodge/Item/Craftable.hs 32;" f pistol src/Dodge/Item/Held/Stick.hs 40;" f pistolerRoom src/Dodge/Room/Room.hs 330;" f @@ -4613,13 +4613,13 @@ removeLights src/Dodge/Room/Tutorial.hs 257;" f removeShieldWall src/Dodge/Item/BackgroundEffect.hs 57;" f removeWallsInPolygon src/Dodge/LevelGen/StaticWalls.hs 182;" f renderDataResizeUpdate src/Preload/Update.hs 26;" f -renderFlatLighting src/Render.hs 104;" f +renderFlatLighting src/Render.hs 107;" f renderInfoListAt src/Dodge/Render/InfoBox.hs 17;" f renderInfoListsAt src/Dodge/Render/InfoBox.hs 44;" f -renderLayer src/Render.hs 236;" f +renderLayer src/Render.hs 240;" f renderLightingNoShadows src/Render.hs 48;" f renderListAt src/Dodge/Render/List.hs 192;" f -renderShadows src/Render.hs 117;" f +renderShadows src/Render.hs 122;" f replaceNullWith src/Dodge/Creature/ReaderUpdate.hs 167;" f replacePutID src/Dodge/Placement/Instance/Wall.hs 105;" f resetCrVocCoolDown src/Dodge/Creature/Vocalization.hs 47;" f @@ -4827,7 +4827,7 @@ setTiles src/Dodge/Layout.hs 67;" f setTreeInts src/Dodge/Room/Tutorial.hs 98;" f setViewDistance src/Dodge/Update/Camera.hs 239;" f setViewPos src/Dodge/Creature/ReaderUpdate.hs 69;" f -setViewport src/Dodge/Render.hs 431;" f +setViewport src/Dodge/Render.hs 433;" f setVol src/Dodge/Config.hs 47;" f setWristShieldPos src/Dodge/Equipment.hs 49;" f setWristShieldPos src/Dodge/Euse.hs 38;" f