From a24ee66f51ed571bbb4fb8d4da97f5d805aaf176 Mon Sep 17 00:00:00 2001 From: justin Date: Fri, 14 Nov 2025 12:41:44 +0000 Subject: [PATCH] Clamp framebuffer textures to edges --- shader/texture/barrel.frag | 8 +++++--- src/Dodge/Distortion.hs | 5 +++-- src/Dodge/Event/Test.hs | 15 +++++++++------ src/Framebuffer/Update.hs | 2 ++ src/Preload/Render.hs | 9 +++++---- tags | 6 +++--- 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/shader/texture/barrel.frag b/shader/texture/barrel.frag index 775ba804f..1925c2e5e 100644 --- a/shader/texture/barrel.frag +++ b/shader/texture/barrel.frag @@ -11,8 +11,10 @@ float f ( float x) { void main() { float t = f(length(texDist)); - fColor = vec4(texture(screenTexture + float r = texture(screenTexture , (t*texPos - vcpos)).r ; + vec2 gb = texture(screenTexture , 0.5+0.5 *( vcpos + t * (texPos - vcpos)) - ) - ); + ).gb + ; + fColor = vec4(r,gb,1); } diff --git a/src/Dodge/Distortion.hs b/src/Dodge/Distortion.hs index 6ced06bef..401719b84 100644 --- a/src/Dodge/Distortion.hs +++ b/src/Dodge/Distortion.hs @@ -1,9 +1,10 @@ -module Dodge.Distortion where +{-# LANGUAGE LambdaCase #-} +module Dodge.Distortion (updateDistortion) where import Dodge.Data.Distortion updateDistortion :: Distortion -> Maybe Distortion -updateDistortion dt = case dt of +updateDistortion = \case RadialDistortion a b c v | v > 1 -> Just $ RadialDistortion a b c $ max 1 (v - 0.05) | v < 1 -> Just $ RadialDistortion a b c $ min 1 (v + 0.05) diff --git a/src/Dodge/Event/Test.hs b/src/Dodge/Event/Test.hs index 7586b4536..abb0b01e6 100644 --- a/src/Dodge/Event/Test.hs +++ b/src/Dodge/Event/Test.hs @@ -1,11 +1,14 @@ -module Dodge.Event.Test ( - testEvent, -) where +module Dodge.Event.Test (testEvent) where --import Dodge.Creature.State import Dodge.Data.World ---import Control.Lens +import Linear +import LensHelp +import Data.Maybe testEvent :: World -> World -testEvent w = w - +testEvent w = fromMaybe w $ do + cpos <- w ^? cWorld . lWorld . creatures . ix 0 . crPos . _xy + let distR = 50 + distortionBulge = RadialDistortion cpos (cpos + V2 distR 0) (cpos + V2 0 distR) 1.9 + return $ w & cWorld . lWorld . distortions .~ [distortionBulge] diff --git a/src/Framebuffer/Update.hs b/src/Framebuffer/Update.hs index 093bde552..84e965421 100644 --- a/src/Framebuffer/Update.hs +++ b/src/Framebuffer/Update.hs @@ -220,5 +220,7 @@ initializeTexture2D fbo attachpoint x y minfilt magfilt form = do glTextureStorage2D to1 1 form xsize' ysize' glTextureParameteri to1 GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt) glTextureParameteri to1 GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt) + glTextureParameteri to1 GL_TEXTURE_WRAP_S (unsafeCoerce GL_CLAMP_TO_EDGE) + glTextureParameteri to1 GL_TEXTURE_WRAP_T (unsafeCoerce GL_CLAMP_TO_EDGE) glNamedFramebufferTexture (_unFBO fbo) attachpoint to1 0 return to1 diff --git a/src/Preload/Render.hs b/src/Preload/Render.hs index 2fc5191fe..5c613dbf3 100644 --- a/src/Preload/Render.hs +++ b/src/Preload/Render.hs @@ -128,7 +128,7 @@ preloadRender = do bloomBlurShad <- makeSourcedShader "texture/bloomBlur" [vert, frag] lightingTextureShad <- makeSourcedShader "lighting/texture" [vert, frag] barrelShad <- makeShaderVBO "texture/barrel" [vert, geom, frag] (toFloatVAs [2, 2, 2, 1]) pmPoints - -- blank wallShader + putStrLn "Setup floor VBO, shader" flvbo <- mglCreate glCreateBuffers flptr <- mallocArray (8 * 65536) @@ -142,8 +142,7 @@ preloadRender = do chptr <- mallocArray (2 * 65536) let chasmvbo = VBO chvbo chptr (2 * floatSize) chasmshader <- makeSourcedShader "chasm" [vert] - framebuf2 <- newTextureFramebuffer - framebuf3 <- newTextureFramebuffer + putStrLn "Setup framebuffers" rboBaseBloomName <- mglCreate glCreateRenderbuffers @@ -157,6 +156,9 @@ preloadRender = do fboPosName <- setupFramebufferGivenStencil rboBaseBloomName fboLightingName <- setupFramebufferGivenStencil rboBaseBloomName + framebuf2 <- newTextureFramebuffer + framebuf3 <- newTextureFramebuffer + fboHalf1Name <- newTextureFramebuffer fboHalf2Name <- newTextureFramebuffer @@ -205,7 +207,6 @@ preloadRender = do , _winVBO = winvbo , _cloudVBO = cloudvbo , _cloudShader = cloudshader --- , _screenTextureVAO = screentexturevao , _dummyVAO = dummyvao } diff --git a/tags b/tags index 72d64edd7..b26215a1e 100644 --- a/tags +++ b/tags @@ -2885,7 +2885,7 @@ copier src/Dodge/Item/Scope.hs 88;" f copierItemUpdate src/Dodge/Creature/State.hs 131;" f copyItemToFloor src/Dodge/FloorItem.hs 14;" f corDoor src/Dodge/Room/Room.hs 385;" f -cornerList src/Preload/Render.hs 213;" f +cornerList src/Preload/Render.hs 214;" f corpseOrGib src/Dodge/Creature/Update.hs 111;" f corridor src/Dodge/Room/Corridor.hs 17;" f corridorBoss src/Dodge/LockAndKey.hs 133;" f @@ -3712,7 +3712,7 @@ initWallZoning src/Dodge/Wall/Zone.hs 12;" f initialRoomTree src/Dodge/Floor.hs 24;" f initialWorld src/Dodge/Initialisation.hs 15;" f initialisePlaying src/Sound.hs 77;" f -initializeGLState src/Preload/Render.hs 234;" f +initializeGLState src/Preload/Render.hs 235;" f initializeOptionMenu src/Dodge/Menu/Option.hs 17;" f initializeOptionMenuBO src/Dodge/Menu/Option.hs 30;" f initializeTexture2D src/Framebuffer/Update.hs 214;" f @@ -5306,7 +5306,7 @@ updateDebrisChunk src/Dodge/Prop/Moving.hs 16;" f updateDebugMessageOffset src/Dodge/Update.hs 95;" f updateDelayedEvents src/Dodge/Update.hs 888;" f updateDisplaySections src/Dodge/DisplayInventory.hs 116;" f -updateDistortion src/Dodge/Distortion.hs 5;" f +updateDistortion src/Dodge/Distortion.hs 6;" f updateDistortions src/Dodge/Update.hs 556;" f updateDoor src/Dodge/Door.hs 22;" f updateDoors src/Dodge/Update.hs 308;" f