Play around with alpha blending

This commit is contained in:
2025-11-04 10:42:18 +00:00
parent 833d4562e2
commit 05c530eeb1
4 changed files with 30 additions and 36 deletions
+10 -21
View File
@@ -4,8 +4,6 @@ layout(triangle_strip, max_vertices = 4) out;
layout(std140, binding = 0) uniform TheMat { mat4 theMat; }; layout(std140, binding = 0) uniform TheMat { mat4 theMat; };
layout(location=0) uniform vec3 lightPos; layout(location=0) uniform vec3 lightPos;
layout(location=1) uniform float radiusUniform; 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) { float closestPointOnLineParam3 (vec3 a, vec3 b, vec3 p) {
return dot(p - a,b-a) / dot(b-a,b-a); 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));} { return a + (x * (b- a));}
} }
} }
//vec3 closepoint = vec4 shift(vec4 p) { return (vec4(p.xyz + (10000 * (p.xyz - lightPos)), 1)); }
vec4 shift(vec4 p) { return (vec4(p.xyz + (100000 * (p.xyz - lightPos)), 1)); }
vec4 shiftBy(float x, vec4 p) { vec4 shiftBy(float x, vec4 p) {
return (vec4(lightPos + (x * normalize(p.xyz - lightPos)), 1)); 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 // copied from lighting/cap.geom, should not be changed on its own
vec4 projNear(vec4 pos) { vec4 projNear(vec4 pos) {
// note we project to a specific height // note we project to a specific height
@@ -34,7 +29,6 @@ vec4 projNear(vec4 pos) {
return vec4(xy, 100, 1); return vec4(xy, 100, 1);
} }
vec4 shiftNear(vec4 pos) vec4 shiftNear(vec4 pos)
//{ vec4 sp = shiftBy(radiusUniform,pos);
{ {
vec4 sp = shift(pos); vec4 sp = shift(pos);
if (sp.z > 100) { if (sp.z > 100) {
@@ -43,19 +37,16 @@ vec4 shiftNear(vec4 pos)
return sp; return sp;
} }
} }
vec4 f(vec4 p) { return (theMat * p); }
void main() { void main() {
vec4 p0 = gl_in[0].gl_Position; vec4 p0 = gl_in[0].gl_Position;
vec4 p1 = gl_in[1].gl_Position; vec4 p1 = gl_in[1].gl_Position;
vec3 closepoint = closestPointOnSeg3(p0.xyz,p1.xyz,lightPos); vec3 closepoint = closestPointOnSeg3(p0.xyz,p1.xyz,lightPos);
float ru2 = radiusUniform * radiusUniform; float ru2 = radiusUniform * radiusUniform;
vec4 mid = 0.5 * (p0 + p1); vec4 mid = 0.5 * (p0 + p1);
vec3 n0a = gl_in[2].gl_Position.xyz; vec3 n0a = gl_in[2].gl_Position.xyz;
vec3 n1a = gl_in[3].gl_Position.xyz; vec3 n1a = gl_in[3].gl_Position.xyz;
vec3 n0 = cross(p1.xyz - p0.xyz, n0a - p0.xyz); vec3 n0 = cross(p1.xyz - p0.xyz, n0a - p0.xyz);
vec3 n1 = cross(p0.xyz - p1.xyz, n1a - p1.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 lightDir = p0.xyz - lightPos.xyz;
vec3 lightDir2 = p1.xyz - lightPos.xyz; vec3 lightDir2 = p1.xyz - lightPos.xyz;
// first test if the edge is part of the silhouette // 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 // using <= rather than < seems to get rid of overlapping shadow
// artefacts // artefacts
{ {
//vec4 p2 = shiftNear(p0);
//vec4 p3 = shiftNear(p1);
vec4 p2 = shiftNear(p0); vec4 p2 = shiftNear(p0);
vec4 p3 = shiftNear(p1); vec4 p3 = shiftNear(p1);
gl_Position = f(p0); gl_Position = theMat * p0;
EmitVertex(); EmitVertex();
if (dot(n0, lightDir) > 0) { if (dot(n0, lightDir) > 0) {
gl_Position = f(p2); gl_Position = theMat * p2;
EmitVertex(); EmitVertex();
gl_Position = f(p1); gl_Position = theMat * p1;
EmitVertex(); EmitVertex();
} else { } else {
gl_Position = f(p1); gl_Position = theMat * p1;
EmitVertex(); EmitVertex();
gl_Position = f(p2); gl_Position = theMat * p2;
EmitVertex(); EmitVertex();
} }
gl_Position = f(p3); gl_Position = theMat * p3;
EmitVertex(); EmitVertex();
EndPrimitive(); EndPrimitive();
} else { } else {
+6 -2
View File
@@ -231,7 +231,9 @@ doDrawing' win pdata u = do
withArray [0, 0, 0, 0] $ withArray [0, 0, 0, 0] $
glClearNamedFramebufferfv (pdata ^. fboBloom . _1 . unFBO) GL_COLOR 0 glClearNamedFramebufferfv (pdata ^. fboBloom . _1 . unFBO) GL_COLOR 0
glDepthFunc GL_LESS 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 glDepthMask GL_FALSE
renderLayer BloomNoZWrite shadV pokeCounts renderLayer BloomNoZWrite shadV pokeCounts
glDepthMask GL_TRUE glDepthMask GL_TRUE
@@ -271,6 +273,7 @@ doDrawing' win pdata u = do
glDepthFunc GL_LEQUAL glDepthFunc GL_LEQUAL
glDepthMask GL_FALSE glDepthMask GL_FALSE
glBlendFuncSeparatei 0 GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA GL_ONE_MINUS_DST_ALPHA GL_ONE 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_NONE] $
withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1] $ withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1] $
glNamedFramebufferDrawBuffers (pdata ^. fboCloud . _1 . unFBO) 2 glNamedFramebufferDrawBuffers (pdata ^. fboCloud . _1 . unFBO) 2
@@ -408,7 +411,8 @@ doDrawing' win pdata u = do
glDepthFunc GL_ALWAYS glDepthFunc GL_ALWAYS
glDepthMask GL_FALSE glDepthMask GL_FALSE
glEnable GL_BLEND 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 renderLayer DebugLayer shadV pokeCounts
glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. matUBO) glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. matUBO)
withArray (scaleMatrix (2 / windowXFloat cfig) (2 / windowYFloat cfig)) $ withArray (scaleMatrix (2 / windowXFloat cfig) (2 / windowYFloat cfig)) $
+5 -4
View File
@@ -2,6 +2,7 @@
module Dodge.Render.HUD (drawHUD) where module Dodge.Render.HUD (drawHUD) where
import Linear
import Dodge.Clock import Dodge.Clock
import qualified Data.Vector as V import qualified Data.Vector as V
import Dodge.Terminal import Dodge.Terminal
@@ -118,7 +119,7 @@ drawMouseOver cfig w =
<|> w ^? input . mouseContext . mcoInvFilt <|> w ^? input . mouseContext . mcoInvFilt
sss <- w ^? hud . diSections sss <- w ^? hud . diSections
return . translateScreenPos cfig (invDP ^. ldpPos) return . translateScreenPos cfig (invDP ^. ldpPos)
. color (withAlpha 0.1 white) . color (0.3*^white)
-- . color white -- . color white
$ selSecDrawCursorAt invDP curs sss (j, i) $ selSecDrawCursorAt invDP curs sss (j, i)
-- curs = BoundaryCursor [West] -- curs = BoundaryCursor [West]
@@ -130,7 +131,7 @@ drawMouseOver cfig w =
sss <- w ^? hud . subInventory . ciSections sss <- w ^? hud . subInventory . ciSections
let idp = secondColumnLDP let idp = secondColumnLDP
return . translateScreenPos cfig (idp ^. ldpPos) return . translateScreenPos cfig (idp ^. ldpPos)
. color (withAlpha 0.2 white) . color (0.3*white)
$ selSecDrawCursorAt idp curs sss (j, i) $ selSecDrawCursorAt idp curs sss (j, i)
drawDragSelected :: Config -> World -> Maybe Picture drawDragSelected :: Config -> World -> Maybe Picture
@@ -146,7 +147,7 @@ drawDragSelected cfig w = do
sss <- w ^? hud . diSections sss <- w ^? hud . diSections
let f x = (selSecDrawCursorAt invDP BackdropCursor sss (i, x) <>) let f x = (selSecDrawCursorAt invDP BackdropCursor sss (i, x) <>)
return . translateScreenPos cfig (invDP ^. ldpPos) return . translateScreenPos cfig (invDP ^. ldpPos)
. color (withAlpha 0.2 white) . color (0.2*^white)
. IS.foldr f mempty . IS.foldr f mempty
$ ys $ ys
@@ -156,7 +157,7 @@ drawDragSelecting cfig w = do
sss <- w ^? hud . diSections sss <- w ^? hud . diSections
let f x = selSecDrawCursorAt invDP BackdropCursor sss (i, x) let f x = selSecDrawCursorAt invDP BackdropCursor sss (i, x)
return . translateScreenPos cfig (invDP ^. ldpPos) return . translateScreenPos cfig (invDP ^. ldpPos)
. color (withAlpha 0.2 white) . color (0.2*^white)
. foldMap f . foldMap f
$ [min j b .. max j b] $ [min j b .. max j b]
+9 -9
View File
@@ -2644,7 +2644,7 @@ beltMag src/Dodge/Item/Ammo.hs 39;" f
bfsThenReturn src/Dodge/Creature/ReaderUpdate.hs 225;" f bfsThenReturn src/Dodge/Creature/ReaderUpdate.hs 225;" f
bgateCalc src/Dodge/Inventory/SelectionList.hs 118;" f bgateCalc src/Dodge/Inventory/SelectionList.hs 118;" f
bgunSound src/Dodge/HeldUse.hs 514;" 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 bingate src/Dodge/Item/Scope.hs 109;" f
black src/Color.hs 27;" f black src/Color.hs 27;" f
blank src/Picture/Base.hs 59;" 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 btSPic src/Dodge/Render/ShapePicture.hs 129;" f
btText src/Dodge/Inventory/SelectionList.hs 237;" f btText src/Dodge/Inventory/SelectionList.hs 237;" f
bufferEBO src/Shader/Bind.hs 28;" 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 bufferPokedVBO src/Shader/Bind.hs 19;" f
bufferShaderLayers src/Shader/Bind.hs 36;" f bufferShaderLayers src/Shader/Bind.hs 36;" f
bulletBeltBracer src/Dodge/Item/Equipment.hs 67;" 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 clangS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 542;" f
cldtPropagateFold src/Dodge/DoubleTree.hs 358;" f cldtPropagateFold src/Dodge/DoubleTree.hs 358;" f
cleanUpPreload src/Preload.hs 10;" 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 cleanUpSoundPreload src/Preload.hs 15;" f
cleanupHalted src/Sound.hs 117;" f cleanupHalted src/Sound.hs 117;" f
cleatLabel src/Dodge/Cleat.hs 30;" 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 357;" f
getCrsFromRooms' src/Dodge/Room/Tutorial.hs 344;" f getCrsFromRooms' src/Dodge/Room/Tutorial.hs 344;" f
getDebugMouseOver src/Dodge/Update.hs 377;" 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 getEdgesCrossing src/Dodge/Path.hs 42;" f
getGrenadeHitEffect src/Dodge/HeldUse.hs 1264;" f getGrenadeHitEffect src/Dodge/HeldUse.hs 1264;" f
getInventoryPath src/Dodge/Inventory/Path.hs 9;" 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 96;" f
pincerP'' src/Dodge/Creature/Boid.hs 106;" f pincerP'' src/Dodge/Creature/Boid.hs 106;" f
pincerP''' src/Dodge/Creature/Boid.hs 77;" 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 pipe src/Dodge/Item/Craftable.hs 32;" f
pistol src/Dodge/Item/Held/Stick.hs 40;" f pistol src/Dodge/Item/Held/Stick.hs 40;" f
pistolerRoom src/Dodge/Room/Room.hs 330;" 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 removeShieldWall src/Dodge/Item/BackgroundEffect.hs 57;" f
removeWallsInPolygon src/Dodge/LevelGen/StaticWalls.hs 182;" f removeWallsInPolygon src/Dodge/LevelGen/StaticWalls.hs 182;" f
renderDataResizeUpdate src/Preload/Update.hs 26;" 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 renderInfoListAt src/Dodge/Render/InfoBox.hs 17;" f
renderInfoListsAt src/Dodge/Render/InfoBox.hs 44;" 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 renderLightingNoShadows src/Render.hs 48;" f
renderListAt src/Dodge/Render/List.hs 192;" 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 replaceNullWith src/Dodge/Creature/ReaderUpdate.hs 167;" f
replacePutID src/Dodge/Placement/Instance/Wall.hs 105;" f replacePutID src/Dodge/Placement/Instance/Wall.hs 105;" f
resetCrVocCoolDown src/Dodge/Creature/Vocalization.hs 47;" 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 setTreeInts src/Dodge/Room/Tutorial.hs 98;" f
setViewDistance src/Dodge/Update/Camera.hs 239;" f setViewDistance src/Dodge/Update/Camera.hs 239;" f
setViewPos src/Dodge/Creature/ReaderUpdate.hs 69;" 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 setVol src/Dodge/Config.hs 47;" f
setWristShieldPos src/Dodge/Equipment.hs 49;" f setWristShieldPos src/Dodge/Equipment.hs 49;" f
setWristShieldPos src/Dodge/Euse.hs 38;" f setWristShieldPos src/Dodge/Euse.hs 38;" f