diff --git a/src/Dodge/Base/Coordinate.hs b/src/Dodge/Base/Coordinate.hs index 3baac69d2..0f5340a62 100644 --- a/src/Dodge/Base/Coordinate.hs +++ b/src/Dodge/Base/Coordinate.hs @@ -2,8 +2,12 @@ module Dodge.Base.Coordinate ( worldPosToScreen, screenToWorldPos, mouseWorldPos, + worldPosToResOffset, ) where +import Dodge.WindowSize +import Linear +import Dodge.Data.Config import Control.Lens import Dodge.Data.Camera import Dodge.Data.Input @@ -18,9 +22,17 @@ import Geometry worldPosToScreen :: Camera -> Point2 -> Point2 worldPosToScreen cam = rotateV (negate $ cam ^. camRot) - . ((cam ^. camZoom) *.*) + . ((cam ^. camZoom) *^) . (-.- (cam ^. camCenter)) +-- gets the position from the bottom left in "world res" "pixels" +worldPosToResOffset :: Config -> Camera -> Point2 -> Point2 +worldPosToResOffset cfig cam p = (worldPosToScreen cam p & each %~ f) + + 0.5 *^ (uncurry V2 (getWindowSize _gr_world_res cfig::(Int,Int)) & each %~ fromIntegral) + where + f x = applyResFactorF (cfig ^. gr_world_res) x + + -- | The mouse position in world coordinates. mouseWorldPos :: Input -> Camera -> Point2 mouseWorldPos inp cam = screenToWorldPos cam (inp ^. mousePos) diff --git a/src/Dodge/Data/Config.hs b/src/Dodge/Data/Config.hs index 75e0a6ccf..a9922ec6a 100644 --- a/src/Dodge/Data/Config.hs +++ b/src/Dodge/Data/Config.hs @@ -129,6 +129,15 @@ applyResFactor rf = case rf of EighthRes -> (`div` 8) SixteenthRes -> (`div` 16) +applyResFactorF :: ResFactor -> Float -> Float +applyResFactorF rf = case rf of + DoubleRes -> (2*) + FullRes -> id + HalfRes -> (/ 2) + QuarterRes -> (/ 4) + EighthRes -> (/ 8) + SixteenthRes -> (/ 16) + --resFactorNum :: ResFactor -> Int --resFactorNum rf = case rf of -- FullRes -> 1 diff --git a/src/Dodge/Render.hs b/src/Dodge/Render.hs index 05799c6c2..981528ecc 100644 --- a/src/Dodge/Render.hs +++ b/src/Dodge/Render.hs @@ -161,6 +161,7 @@ doDrawing' win pdata u = do glEnable GL_BLEND --draw lightmap into its own buffer createLightMap + (w ^. wCam) cfig (fromIntegral trueNWalls) nSilIndices @@ -284,6 +285,7 @@ doDrawing' win pdata u = do glEnable GL_BLEND glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata))) createLightMap + (w ^. wCam) cfig (fromIntegral trueNWalls) nSilIndices diff --git a/src/Render.hs b/src/Render.hs index ee5b053e8..f4888faec 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -5,6 +5,8 @@ module Render ( bindFBO, ) where +import Dodge.Base.Coordinate +import Dodge.Data.Camera import Control.Lens import Control.Monad.Primitive import Data.Preload.Render @@ -24,6 +26,7 @@ import Shader.Data away" from the shape colors. -} createLightMap :: + Camera -> Config -> -- | number of walls GLsizei -> @@ -38,10 +41,10 @@ createLightMap :: [(Point3, Float, Point3)] -> -- Lights RenderData -> IO () -createLightMap cfig = case shadrendertype of +createLightMap cam cfig = case shadrendertype of NoShadows -> const . const . const renderLightingNoShadows NoLighting -> const . const . const . const . const . const renderFlatLighting - _ -> renderShadows shadrendertype + _ -> renderShadows cam cfig shadrendertype where shadrendertype = cfig ^. gr_shadow_rendering @@ -114,6 +117,8 @@ renderFlatLighting pdata = do glStencilOp GL_KEEP GL_KEEP GL_KEEP renderShadows :: + Camera -> + Config -> ShadowRendering -> GLsizei -> Int -> @@ -123,7 +128,7 @@ renderShadows :: [(Point3, Float, Point3)] -> RenderData -> IO () -renderShadows shadrendertype nWalls nSils nCaps positiontexture normaltexture lightPoints pdata = do +renderShadows cam cfig shadrendertype nWalls nSils nCaps positiontexture normaltexture lightPoints pdata = do glBindFramebuffer GL_FRAMEBUFFER $ pdata ^. fboLighting . _1 . unFBO let llinesShad = _lightingLineShadowShader pdata lcapShad = _lightingCapShader pdata @@ -150,12 +155,14 @@ renderShadows shadrendertype nWalls nSils nCaps positiontexture normaltexture li -- 1. stencil out the shadows from this light's point of view -- 2. calculate lighting based on each fragment's position and normal -- TODO stencil out square around light! --- glEnable GL_SCISSOR_TEST + glEnable GL_SCISSOR_TEST glDisable GL_CULL_FACE flip VFSM.mapM_ (VFSM.fromList lightPoints) $ \(V3 x y z, rad, V3 r g b) -> do withArray [x,y,z,1,r,g,b,rad] $ glNamedBufferSubData (pdata ^. lightUBO) 0 32 -- note that the stencil shadows rely on the depth buffer --- glScissor 0 0 200 200 + let d = rad * cam ^. camZoom + V2 x' y' = worldPosToResOffset cfig cam (V2 x y) + glScissor (round (x'-d)) (round (y'-d)) (round $ 2 *d) (round $ 2* d) glDepthFunc GL_LESS glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE -- setup stencil @@ -187,8 +194,7 @@ renderShadows shadrendertype nWalls nSils nCaps positiontexture normaltexture li glUseProgram ltextShad glDrawArrays GL_TRIANGLES 0 6 --cleanup: may not be necessary, depending on what comes after... --- glDisable GL_STENCIL_TEST --- glDisable GL_SCISSOR_TEST + glDisable GL_SCISSOR_TEST glStencilFunc GL_NOTEQUAL 128 255 glStencilOp GL_KEEP GL_KEEP GL_KEEP glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE diff --git a/tags b/tags index 765f198c4..b769d18b1 100644 --- a/tags +++ b/tags @@ -2550,6 +2550,7 @@ applyPastDamages src/Dodge/Creature/State.hs 49;" f applyPosition src/Sound.hs 111;" f applyRecoil src/Dodge/HeldUse.hs 459;" f applyResFactor src/Dodge/Data/Config.hs 123;" f +applyResFactorF src/Dodge/Data/Config.hs 132;" f applySetTerminalString src/Dodge/Debug/Terminal.hs 83;" f applySidePush src/Dodge/HeldUse.hs 559;" f applySoundCME src/Dodge/HeldUse.hs 449;" f @@ -2648,7 +2649,7 @@ beltMag src/Dodge/Item/Ammo.hs 39;" f bfsThenReturn src/Dodge/Creature/ReaderUpdate.hs 226;" f bgateCalc src/Dodge/Inventory/SelectionList.hs 118;" f bgunSound src/Dodge/HeldUse.hs 514;" f -bindFBO src/Render.hs 222;" f +bindFBO src/Render.hs 228;" f bingate src/Dodge/Item/Scope.hs 109;" f black src/Color.hs 27;" f blank src/Picture/Base.hs 59;" f @@ -2704,7 +2705,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 409;" f +bufferPerspectiveMatrixUBO src/Dodge/Render.hs 402;" f bufferPokedVBO src/Shader/Bind.hs 19;" f bufferShaderLayers src/Shader/Bind.hs 32;" f bulletBeltBracer src/Dodge/Item/Equipment.hs 67;" f @@ -2941,7 +2942,7 @@ createForceField src/Dodge/ForceField.hs 7;" f createGas src/Dodge/Gas.hs 10;" f createHeadLamp src/Dodge/Euse.hs 58;" f createItemYou src/Dodge/Inventory/Add.hs 61;" f -createLightMap src/Render.hs 26;" f +createLightMap src/Render.hs 28;" f createProjectile src/Dodge/HeldUse.hs 1276;" f createProjectileR src/Dodge/HeldUse.hs 1225;" f createShell src/Dodge/Projectile/Create.hs 21;" f @@ -3032,7 +3033,7 @@ debugItem src/Dodge/Debug.hs 40;" f debugMenu src/Dodge/Menu.hs 124;" f debugMenuOptions src/Dodge/Menu.hs 130;" f debugMouseClickPos src/Dodge/Debug.hs 145;" f -debugOn src/Dodge/Data/Config.hs 164;" f +debugOn src/Dodge/Data/Config.hs 173;" f debugPutDraw src/Dodge/Debug.hs 95;" f debugPutItems src/Dodge/Debug.hs 78;" f debugPutN src/Dodge/Debug.hs 84;" f @@ -3066,7 +3067,7 @@ defaultCWGen src/Dodge/Default/World.hs 59;" f defaultCWorld src/Dodge/Default/World.hs 84;" f defaultChaseMvType src/Dodge/Creature/MoveType.hs 25;" f defaultClusterStatus src/Dodge/Default/Room.hs 37;" f -defaultConfig src/Dodge/Data/Config.hs 140;" f +defaultConfig src/Dodge/Data/Config.hs 149;" f defaultCraftItem src/Dodge/Default/Item.hs 25;" f defaultCreature src/Dodge/Default/Creature.hs 12;" f defaultCreatureMemory src/Dodge/Default/Creature.hs 65;" f @@ -3445,7 +3446,7 @@ facesToVF src/Polyhedra/Geodesic.hs 69;" f farWallDistDirection src/Dodge/Update/Camera.hs 244;" f fdiv src/ShortShow.hs 41;" f feet src/Dodge/Creature/Picture.hs 51;" f -ffoldM src/Framebuffer/Update.hs 85;" f +ffoldM src/Framebuffer/Update.hs 86;" f filter3 src/FoldableHelp.hs 76;" f filterSectionsPair src/Dodge/DisplayInventory.hs 157;" f findBlips src/Dodge/RadarSweep.hs 63;" f @@ -3558,7 +3559,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 374;" f -getDistortions src/Dodge/Render.hs 421;" f +getDistortions src/Dodge/Render.hs 414;" f getEdgesCrossing src/Dodge/Path.hs 37;" f getGrenadeHitEffect src/Dodge/HeldUse.hs 1264;" f getInventoryPath src/Dodge/Inventory/Path.hs 9;" f @@ -3712,7 +3713,7 @@ initialisePlaying src/Sound.hs 77;" f initializeGLState src/Preload/Render.hs 234;" f initializeOptionMenu src/Dodge/Menu/Option.hs 17;" f initializeOptionMenuBO src/Dodge/Menu/Option.hs 30;" f -initializeTexture2D src/Framebuffer/Update.hs 217;" f +initializeTexture2D src/Framebuffer/Update.hs 218;" f inorderNumberTree src/TreeHelp.hs 190;" f insertAt src/Padding.hs 63;" f insertIMInZone src/Dodge/Base.hs 54;" f @@ -4169,7 +4170,7 @@ mntLightLnkCond' src/Dodge/Placement/Instance/LightSource.hs 148;" f modTo src/Geometry/Zone.hs 18;" f mouseClickOptionsList src/Dodge/Update/Input/ScreenLayer.hs 60;" f mouseCursorType src/Dodge/Render/Picture.hs 92;" f -mouseWorldPos src/Dodge/Base/Coordinate.hs 25;" f +mouseWorldPos src/Dodge/Base/Coordinate.hs 35;" f moveBullet src/Dodge/Bullet.hs 197;" f moveCombineSel src/Dodge/Update/Scroll.hs 121;" f moveInverseShockwave src/Dodge/Shockwave/Update.hs 31;" f @@ -4334,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 197;" f +pingPongBetween src/Render.hs 203;" 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 @@ -4606,23 +4607,23 @@ 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 101;" f +renderFlatLighting src/Render.hs 104;" f renderInfoListAt src/Dodge/Render/InfoBox.hs 17;" f renderInfoListsAt src/Dodge/Render/InfoBox.hs 44;" f -renderLayer src/Render.hs 211;" f -renderLightingNoShadows src/Render.hs 48;" f +renderLayer src/Render.hs 217;" f +renderLightingNoShadows src/Render.hs 51;" f renderListAt src/Dodge/Render/List.hs 192;" f -renderShadows src/Render.hs 116;" f +renderShadows src/Render.hs 119;" f replaceNullWith src/Dodge/Creature/ReaderUpdate.hs 168;" f replacePutID src/Dodge/Placement/Instance/Wall.hs 105;" f resetCrVocCoolDown src/Dodge/Creature/Vocalization.hs 47;" f resetPLUse src/Dodge/PlacementSpot.hs 92;" f resetStride src/Dodge/Creature/State/WalkCycle.hs 25;" f resetTerminal src/Dodge/WorldEffect.hs 109;" f -resizeFBOTO src/Framebuffer/Update.hs 199;" f -resizeFBOTO2 src/Framebuffer/Update.hs 147;" f -resizeFBOTO3 src/Framebuffer/Update.hs 171;" f -resizeRBO src/Framebuffer/Update.hs 88;" f +resizeFBOTO src/Framebuffer/Update.hs 200;" f +resizeFBOTO2 src/Framebuffer/Update.hs 148;" f +resizeFBOTO3 src/Framebuffer/Update.hs 172;" f +resizeRBO src/Framebuffer/Update.hs 89;" f respawn src/Dodge/SpawnAt.hs 12;" f restrictInLinks src/Dodge/RoomLink.hs 44;" f restrictLinkType src/Dodge/RoomLink.hs 34;" f @@ -4744,7 +4745,7 @@ screenBox src/Dodge/Base/Window.hs 53;" f screenPolygon src/Dodge/Base/Window.hs 17;" f screenPolygonBord src/Dodge/Base/Window.hs 27;" f screenPosAbs src/Dodge/ScreenPos.hs 15;" f -screenToWorldPos src/Dodge/Base/Coordinate.hs 28;" f +screenToWorldPos src/Dodge/Base/Coordinate.hs 38;" f scrollAugInvSel src/Dodge/Inventory.hs 191;" f scrollAugNextInSection src/Dodge/Inventory.hs 204;" f scrollRBOption src/Dodge/Update/Scroll.hs 202;" f @@ -4821,7 +4822,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 426;" f +setViewport src/Dodge/Render.hs 419;" f setVol src/Dodge/Config.hs 47;" f setWristShieldPos src/Dodge/Equipment.hs 49;" f setWristShieldPos src/Dodge/Euse.hs 38;" f @@ -4901,9 +4902,9 @@ showEquipItem src/Dodge/Item/Display.hs 107;" f showInt src/Dodge/Item/Info.hs 75;" f showIntsString src/Dodge/Tree/Compose.hs 129;" f showInventoryPathing src/Dodge/Item/Display.hs 86;" f -showManObj src/Dodge/TestString.hs 48;" f +showManObj src/Dodge/TestString.hs 51;" f showTerminalError src/Dodge/Debug/Terminal.hs 80;" f -showTimeFlow src/Dodge/TestString.hs 71;" f +showTimeFlow src/Dodge/TestString.hs 74;" f shrinkPolyOnEdges src/Geometry/Polygon.hs 175;" f shrinkVert src/Geometry/Polygon.hs 179;" f shuffle src/RandomHelp.hs 49;" f @@ -5175,7 +5176,7 @@ tone440sawtoothquietS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 448;" f topInvW src/Dodge/ListDisplayParams.hs 49;" f topPrismEdgeIndices src/Shader/Poke.hs 334;" f topPrismIndices src/Shader/Poke.hs 409;" f -topTestPart src/Dodge/TestString.hs 44;" f +topTestPart src/Dodge/TestString.hs 47;" f torchShape src/Dodge/Item/Draw/SPic.hs 276;" f torqueAmount src/Dodge/HeldUse.hs 581;" f torqueCr src/Dodge/WorldEffect.hs 77;" f @@ -5325,9 +5326,9 @@ updateEnergyBall src/Dodge/EnergyBall.hs 31;" f updateEnergyBalls src/Dodge/Update.hs 658;" f updateEnterRegex src/Dodge/Update/Input/InGame.hs 505;" f updateExpBarrel src/Dodge/Barreloid.hs 21;" f -updateFBOTO src/Framebuffer/Update.hs 91;" f -updateFBOTO2 src/Framebuffer/Update.hs 109;" f -updateFBOTO3 src/Framebuffer/Update.hs 127;" f +updateFBOTO src/Framebuffer/Update.hs 92;" f +updateFBOTO2 src/Framebuffer/Update.hs 110;" f +updateFBOTO3 src/Framebuffer/Update.hs 128;" f updateFlame src/Dodge/Flame.hs 19;" f updateFlames src/Dodge/Update.hs 655;" f updateFloatingCamera src/Dodge/Update/Camera.hs 36;" f @@ -5539,7 +5540,8 @@ wlsNearPoint src/Dodge/Zoning/Wall.hs 39;" f wlsNearRect src/Dodge/Zoning/Wall.hs 46;" f wlsNearSeg src/Dodge/Zoning/Wall.hs 42;" f wordsBy src/ListHelp.hs 116;" f -worldPosToScreen src/Dodge/Base/Coordinate.hs 18;" f +worldPosToResOffset src/Dodge/Base/Coordinate.hs 28;" f +worldPosToScreen src/Dodge/Base/Coordinate.hs 21;" f worldSPic src/Dodge/Render/ShapePicture.hs 22;" f worldToGenWorld src/Dodge/LevelGen/LevelStructure.hs 14;" f wpAdd src/Dodge/Room/RezBox.hs 148;" f