From 0a8370c7c61727bdeba50dfc2de53655b9eaf8df Mon Sep 17 00:00:00 2001 From: jgk Date: Thu, 10 Jun 2021 15:45:52 +0200 Subject: [PATCH] Commit before fully removing uniforms other than the matrix --- shader/background.frag | 5 +- shader/background.geom | 28 ----------- shader/background.vert | 10 ---- shader/lighting/floor.frag | 3 -- shader/lighting/floor.geom | 18 +++----- src/Dodge/Default.hs | 92 ------------------------------------- src/Dodge/Initialisation.hs | 2 +- src/Dodge/Render.hs | 5 ++ src/Picture/Render.hs | 13 +++++- 9 files changed, 25 insertions(+), 151 deletions(-) diff --git a/shader/background.frag b/shader/background.frag index 62485dfc5..846d95e59 100644 --- a/shader/background.frag +++ b/shader/background.frag @@ -2,10 +2,9 @@ in vec2 gTexPos; out vec4 fColor; -uniform sampler2D aTexture; void main() { -// fColor = vec4 (1,1,0,1); - fColor = texture(aTexture, gTexPos); + fColor = vec4 (0.5,0.2,0,1); +// fColor = texture(aTexture, gTexPos); } diff --git a/shader/background.geom b/shader/background.geom index 280eae591..1db0c2bd1 100644 --- a/shader/background.geom +++ b/shader/background.geom @@ -1,43 +1,15 @@ #version 430 core layout (points) in; layout (triangle_strip, max_vertices = 4) out; -in vec4 vParams []; -in vec2 vWinSize []; -out vec2 gTexPos; - -uniform vec2 winSize; -uniform vec2 translation; -uniform float zoom; -uniform float rotation; - -vec2 rotBy( float rot, vec2 v) -{ - return vec2 ( v.x * cos(rot) - v.y * sin(rot) - , v.x * sin(rot) + v.y * cos(rot) - ); - -} - void main() { - vec2 cPos = vec2(translation.x / 250 , translation.y /250 ); -// float zoom = vParams[0].w; - float rot = 0 - rotation; - - float x = winSize.x / (500*zoom) ; - float y = winSize.y / (500*zoom) ; - gTexPos = cPos + rotBy(-rot , vec2(x,y)); gl_Position = vec4 (1,1,0.9,1); EmitVertex(); - gTexPos = cPos + rotBy(-rot , vec2(x,-y)); gl_Position = vec4 (1,-1,0.9,1); EmitVertex(); - gTexPos = cPos + rotBy(-rot , vec2(-x,y)); gl_Position = vec4 (-1,1,0.9,1); EmitVertex(); - gTexPos = cPos + rotBy(-rot , vec2(-x,-y)); gl_Position = vec4 (-1,-1,0.9,1); EmitVertex(); - EndPrimitive(); } diff --git a/shader/background.vert b/shader/background.vert index 9cc312b34..14710c32e 100644 --- a/shader/background.vert +++ b/shader/background.vert @@ -1,18 +1,8 @@ #version 430 core layout (location = 0) in vec4 params; layout (location = 1) in vec2 texCoor; -out vec4 vParams; -out vec2 vWinSize; - -uniform vec2 winSize; -uniform float zoom; -uniform vec2 translation; -uniform float rotation; uniform mat4 worldMat; - void main() { gl_Position = vec4(0,0,0,0); - vParams = params; - vWinSize = winSize; } diff --git a/shader/lighting/floor.frag b/shader/lighting/floor.frag index c8e032fb9..85cb88c37 100644 --- a/shader/lighting/floor.frag +++ b/shader/lighting/floor.frag @@ -1,10 +1,7 @@ #version 430 core in float lum; - in vec2 dField; - out vec4 fColor; - void main() { float c = pow (1 - min(1, dot(dField,dField)) , 2) * lum ; diff --git a/shader/lighting/floor.geom b/shader/lighting/floor.geom index 63cdd527c..7bf87da54 100644 --- a/shader/lighting/floor.geom +++ b/shader/lighting/floor.geom @@ -4,31 +4,25 @@ layout (triangle_strip, max_vertices = 4) out; out float lum; out vec2 dField; -uniform vec2 winSize; -uniform float zoom; uniform mat4 worldMat; void main() { lum = gl_in[0].gl_Position.w; - vec4 cenPos = worldMat * vec4( gl_in[0].gl_Position.xy, 0 , 1); - float gRad = gl_in[0].gl_Position.z * zoom * 2; + vec4 cenPos = vec4( gl_in[0].gl_Position.xy, 0 , 1); + float gRad = gl_in[0].gl_Position.z; dField = vec2 ( 1, 1); - gl_Position - = vec4 (cenPos.x + gRad/winSize.x, cenPos.y + gRad/winSize.y, -0 , 1); + gl_Position = worldMat * vec4 (cenPos.x + gRad, cenPos.y + gRad, -0 , 1); EmitVertex(); dField = vec2 (-1, 1); - gl_Position - = vec4 (cenPos.x - gRad/winSize.x, cenPos.y + gRad/winSize.y, -0 , 1); + gl_Position = worldMat * vec4 (cenPos.x - gRad, cenPos.y + gRad, -0 , 1); EmitVertex(); dField = vec2 ( 1,-1); - gl_Position - = vec4 (cenPos.x + gRad/winSize.x, cenPos.y - gRad/winSize.y, -0 , 1); + gl_Position = worldMat * vec4 (cenPos.x + gRad, cenPos.y - gRad, -0 , 1); EmitVertex(); dField = vec2 (-1,-1); - gl_Position - = vec4 (cenPos.x - gRad/winSize.x, cenPos.y - gRad/winSize.y, -0 , 1); + gl_Position = worldMat * vec4 (cenPos.x - gRad, cenPos.y - gRad, -0 , 1); EmitVertex(); EndPrimitive(); diff --git a/src/Dodge/Default.hs b/src/Dodge/Default.hs index 622a9ac41..ed57951b2 100644 --- a/src/Dodge/Default.hs +++ b/src/Dodge/Default.hs @@ -11,94 +11,14 @@ import Dodge.Item.Data import Dodge.Creature.Stance.Data import Dodge.Creature.State.Data import Dodge.Creature.AlertLevel.Data -import Dodge.Debug.Flag.Data -import Dodge.Data.Menu import Dodge.SoundLogic -import Dodge.Base import Dodge.Picture.Layer -import Dodge.Config.Data -import Dodge.Config.KeyConfig import Geometry import Picture import Control.Lens -import System.Random import qualified Data.IntMap.Strict as IM -import qualified Data.Map as M -import qualified Data.Set as S -import Data.Graph.Inductive.Graph hiding ((&)) import Data.List -defaultWorld :: World -defaultWorld = World - { _keys = S.empty - , _mouseButtons = S.empty - , _cameraCenter = (0,0) - , _cameraRot = 0 - , _cameraZoom = 1 - , _cameraViewFrom = (0,0) - , _creatures = IM.empty - , _creaturesZone = IM.empty - , _creatureGroups = IM.empty - , _clouds = IM.empty - , _cloudsZone = IM.empty - , _itemPositions = IM.empty - , _projectiles = IM.empty - , _particles = [] - , _staticWalls = [] - , _walls = IM.empty - , _wallsZone = IM.empty - , _forceFields = IM.empty - , _floorItems = IM.empty - , _randGen = mkStdGen 2 - , _mousePos = (0,0) - , _testString = [] - , _yourID = 0 - , _worldEvents = id - , _pressPlates = IM.empty - , _buttons = IM.empty - , _soundQueue = [] - , _sounds = M.empty - , _corpses = IM.empty - , _decorations = IM.empty - , _storedLevel = Nothing - , _menuLayers = [LevelMenu 1] - , _worldState = M.empty - , _worldTriggers = S.empty - , _clickMousePos = (0,0) - , _pathGraph = Data.Graph.Inductive.Graph.empty - , _pathGraph' = [] - , _pathPoints = IM.empty - , _pathInc = M.empty - , _carteDisplay = False - , _carteCenter = (0,0) - , _carteZoom = 0.5 - , _carteRot = 0 - , _lightSources = IM.empty - , _tempLightSources = [youLight] - , _closeActiveObjects = [] - , _seenLocations = IM.fromList - [(0, (_crPos . you, "CURRENT POSITION")) - ,(1, (const (0,0) , "START POSITION")) - ] - , _selLocation = 0 - , _keyConfig = defaultKeyConfigSDL - , _config = defaultConfig - , _sideEffects = [] - , _doneSideEffects = [] - , _debugFlags = defaultDebugFlags - , _inventoryMode = TopInventory - , _lClickHammer = HammerUp - , _foregroundDecorations = - [ setDepth (-0.1) $ color orange $ pictures - [ polygon $ rectNSEW 50 40 140 (-20) - , translate 60 45 $ scale 0.5 1 $ thickArc 0 pi 75 10 - ] - , setDepth (-0.2) $ rotate 0.75 $ pictures - $ map f [5,25,45,65] - ] - } - where - f x = polygon $ rectNSEW (x - 20) (x-22) 500 0 defaultCreature :: Creature defaultCreature = Creature @@ -255,18 +175,6 @@ defaultPP = PressPlate , _ppID = -1 , _ppText = "Pressure plate" } -defaultDebugFlags :: DebugFlags -defaultDebugFlags = DebugFlags - { _noClip = False - , _displaySecondsPerFrame = True - } -youLight :: TempLightSource -youLight = - TLS { _tlsPos = (0,0) - ,_tlsRad = 300 - ,_tlsIntensity = 0.1 - ,_tlsUpdate = \w _ -> (w, Just (youLight {_tlsPos = _crPos (you w)})) - } diff --git a/src/Dodge/Initialisation.hs b/src/Dodge/Initialisation.hs index 13164451d..434e8214d 100644 --- a/src/Dodge/Initialisation.hs +++ b/src/Dodge/Initialisation.hs @@ -1,5 +1,5 @@ module Dodge.Initialisation where -import Dodge.Default +import Dodge.Default.World import Dodge.Data import Dodge.Data.Menu import Dodge.Creature diff --git a/src/Dodge/Render.hs b/src/Dodge/Render.hs index df52673e2..d9f7212db 100644 --- a/src/Dodge/Render.hs +++ b/src/Dodge/Render.hs @@ -61,6 +61,11 @@ doDrawing pdata w = do :: IO (GLmatrix GLfloat) -- draw the lightmap. Probably changes the bound framebufferObject createLightMap pdata (w ^. config . shadow_resolution) wallPoints lightPoints viewFroms pmat + (foregroundPics w) + +-- -- set the coordinate uniforms ready for drawing elements using world coordinates +-- setCommonUniforms pdata rot camzoom trans wins + -- draw the background. Assumes that depth testing is not enabled or that -- the depth buffer is ready to be drawn on blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One)) diff --git a/src/Picture/Render.hs b/src/Picture/Render.hs index 337f3a455..0586be1c1 100644 --- a/src/Picture/Render.hs +++ b/src/Picture/Render.hs @@ -64,9 +64,10 @@ createLightMap -> [(Point2,Point2)] -- Wall pairs -> [Point4] -- Lights -> (Float,Float) -- View from position - -> GLmatrix GLfloat + -> GLmatrix GLfloat -- perspective matrix + -> Picture -- foreground pictures -> IO () -createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) pmat = do +createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) pmat _ = do -- get viewport size so we can reset it later (vppos,vpsize) <- get viewport @@ -99,6 +100,14 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) pmat = $= (0 :: Float) cullFace $= Just Back drawShader (_lightingOccludeShader pdata) nWalls + + cullFace $= Nothing +---- draw foreground elements to set z buffer +-- forM_ (_pictureShaders pdata) $ \shad -> do +-- currentProgram $= Just (_shaderProgram shad) +-- uniform (_shaderUniforms shad !! 4) $= pmat +-- _ <- renderFoldable pdata $ picToLTree (Just 0) fpics + -- for each of the lights: -- stencil out the walls from this light's point of view -- draw fading lightmap circles on the floor