Fix normal map transformations for floor

This commit is contained in:
2023-03-18 12:17:42 +00:00
parent 2a9a38db8e
commit c6120f2fc9
11 changed files with 33 additions and 49 deletions
+4 -1
View File
@@ -14,7 +14,10 @@ data Floor
data Tile = Tile data Tile = Tile
{ _tilePoly :: [Point2] { _tilePoly :: [Point2]
, _tileZero :: Point2 -- ^ point in the world where tile texture is 0,0 , _tileZero :: Point2 -- ^ point in the world where tile texture is 0,0
, _tileX :: Point2 -- ^ vector in the X direction (1,0) , _tileTangentPos :: Point2
-- ^ world position one along in the X direction, note this also set the scale of the
-- texture
-- this has to be a position because it is shifted
, _tileZ :: Float , _tileZ :: Float
} }
deriving (Eq, Ord, Show) deriving (Eq, Ord, Show)
-1
View File
@@ -30,7 +30,6 @@ data CWorld = CWorld
, _pastWorlds :: [LWorld] , _pastWorlds :: [LWorld]
, _timeFlow :: TimeFlowStatus , _timeFlow :: TimeFlowStatus
, _seenWalls :: IS.IntSet , _seenWalls :: IS.IntSet
, _floorTiles :: [(Point3, Point3)]
, _cwTiles :: [Tile] , _cwTiles :: [Tile]
, _pathGraph :: Gr Point2 PathEdge , _pathGraph :: Gr Point2 PathEdge
, _numberFloorVerxs :: Int , _numberFloorVerxs :: Int
-2
View File
@@ -84,8 +84,6 @@ defaultCWorld =
, _pastWorlds = [] , _pastWorlds = []
, _timeFlow = NormalTimeFlow , _timeFlow = NormalTimeFlow
, _seenWalls = mempty , _seenWalls = mempty
, _floorTiles = mempty
--, _pathGraph = mempty
, _pathGraph = Data.Graph.Inductive.Graph.empty , _pathGraph = Data.Graph.Inductive.Graph.empty
, _cwTiles = mempty , _cwTiles = mempty
, _numberFloorVerxs = 0 , _numberFloorVerxs = 0
+1 -14
View File
@@ -30,7 +30,6 @@ import Dodge.Zoning.Pathing
import Geometry import Geometry
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
import RandomHelp import RandomHelp
import Tile
generateLevelFromRoomList :: IM.IntMap Room -> World -> GenWorld generateLevelFromRoomList :: IM.IntMap Room -> World -> GenWorld
generateLevelFromRoomList gr' w = generateLevelFromRoomList gr' w =
@@ -42,7 +41,7 @@ generateLevelFromRoomList gr' w =
. doInPlacements . doInPlacements
. doOutPlacements . doOutPlacements
. doIndividualPlacements . doIndividualPlacements
. setFloors . setTiles
. worldToGenWorld rs' . worldToGenWorld rs'
$ w & cWorld . lWorld . walls .~ wallsFromRooms rs $ w & cWorld . lWorld . walls .~ wallsFromRooms rs
& cWorld . cwGen . cwgGameRooms .~ gameRoomsFromRooms (IM.elems rs') & cWorld . cwGen . cwgGameRooms .~ gameRoomsFromRooms (IM.elems rs')
@@ -60,12 +59,6 @@ generateLevelFromRoomList gr' w =
randomCompass :: World -> World randomCompass :: World -> World
randomCompass w = w & cWorld . camPos . camRot .~ (takeOne [0, 0.5 * pi, pi, 1.5 * pi] & evalState $ _randGen w) randomCompass w = w & cWorld . camPos . camRot .~ (takeOne [0, 0.5 * pi, pi, 1.5 * pi] & evalState $ _randGen w)
putFloorTiles :: GenWorld -> GenWorld
putFloorTiles gw = gw & gwWorld . cWorld . floorTiles .~ floorsFromGenWorld gw
setFloors :: GenWorld -> GenWorld
setFloors = putFloorTiles . setTiles
-- note the order of traversal of the rooms is important -- note the order of traversal of the rooms is important
-- hence the reverse -- hence the reverse
-- this is not ideal: should do this in some more sensible way -- this is not ideal: should do this in some more sensible way
@@ -209,15 +202,9 @@ gameRoomFromRoom rm =
_ -> getDir xs _ -> getDir xs
getDir _ = 0 -- fallback getDir _ = 0 -- fallback
floorsFromRooms :: [Room] -> [(Point3, Point3)]
floorsFromRooms = concatMap (concatMap tileToRenderList . getTiles . _rmFloor . doRoomShift)
tilesFromRooms :: [Room] -> [Tile] tilesFromRooms :: [Room] -> [Tile]
tilesFromRooms = concatMap (getTiles . _rmFloor . doRoomShift) tilesFromRooms = concatMap (getTiles . _rmFloor . doRoomShift)
floorsFromGenWorld :: GenWorld -> [(Point3, Point3)]
floorsFromGenWorld = floorsFromRooms . IM.elems . _genRooms
getTiles :: Floor -> [Tile] getTiles :: Floor -> [Tile]
getTiles fl = case fl of getTiles fl = case fl of
Tiled xs -> xs Tiled xs -> xs
+1 -6
View File
@@ -33,12 +33,7 @@ generateWorldFromSeed rdata i = do
postGenerationProcessing :: RenderData -> GenWorld -> IO World postGenerationProcessing :: RenderData -> GenWorld -> IO World
postGenerationProcessing _ gw = do postGenerationProcessing _ gw = do
let w' = _gwWorld gw let w' = _gwWorld gw
-- nfloorvxs <- foldM (pokeTile (rdata ^. floorVBO . vboPtr)) let w = w' & cWorld . cwTiles .~ (tilesFromRooms . IM.elems $ _genRooms gw)
-- 0
-- (tilesFromRooms . IM.elems $ _genRooms gw)
-- bufferPokedVBO (rdata ^. floorVBO) nfloorvxs
let w = w' -- & cWorld . numberFloorVerxs .~ nfloorvxs
& cWorld . cwTiles .~ (tilesFromRooms . IM.elems $ _genRooms gw)
return $ foldl' assignPushDoors w (w ^. cWorld . lWorld . doors) return $ foldl' assignPushDoors w (w ^. cWorld . lWorld . doors)
generateGraphs :: IO () generateGraphs :: IO ()
-1
View File
@@ -89,7 +89,6 @@ doDrawing' win pdata u = do
unzip unzip
[ (pdata ^. vboWalls, nWalls) [ (pdata ^. vboWalls, nWalls)
, (pdata ^. vboWindows, nWins) , (pdata ^. vboWindows, nWins)
, (pdata ^. floorVBO, nFls)
] ]
bufferPokedVBO (_vboShapes pdata) nShapeVs bufferPokedVBO (_vboShapes pdata) nShapeVs
glNamedBufferSubData glNamedBufferSubData
+2 -2
View File
@@ -46,7 +46,7 @@ shiftRoomBy shift r =
%~ map %~ map
( (tilePoly %~ map (shiftPointBy shift)) ( (tilePoly %~ map (shiftPointBy shift))
. (tileZero %~ shiftPointBy shift) . (tileZero %~ shiftPointBy shift)
. (tileX %~ shiftPointBy shift) . (tileTangentPos %~ shiftPointBy shift)
) )
& rmViewpoints %~ map (shiftPointBy shift) & rmViewpoints %~ map (shiftPointBy shift)
@@ -62,7 +62,7 @@ moveRoomBy shift r =
%~ map %~ map
( (tilePoly %~ map (shiftPointBy shift)) ( (tilePoly %~ map (shiftPointBy shift))
. (tileZero %~ shiftPointBy shift) . (tileZero %~ shiftPointBy shift)
. (tileX %~ shiftPointBy shift) . (tileTangentPos %~ shiftPointBy shift)
) )
& rmViewpoints %~ map (shiftPointBy shift) & rmViewpoints %~ map (shiftPointBy shift)
& rmPos %~ map ((rpPos %~ shiftPointBy shift) . (rpDir +~ snd shift)) & rmPos %~ map ((rpPos %~ shiftPointBy shift) . (rpDir +~ snd shift))
+1 -1
View File
@@ -61,7 +61,7 @@ roomRect x y xn yn =
[ Tile [ Tile
{ _tilePoly = rectNSWE y 0 0 x { _tilePoly = rectNSWE y 0 0 x
, _tileZero = V2 0 0 , _tileZero = V2 0 0
, _tileX = V2 1 0 , _tileTangentPos = V2 32 0
, _tileZ = 16 , _tileZ = 16
} }
] ]
+1 -1
View File
@@ -213,7 +213,7 @@ preloadRender = do
] ]
initializeGLState initializeGLState
tonormalmap <- initTexture 3 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/verticalRidge.png" tonormalmap <- initTexture 3 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/squaresPattern.png"
return $ return $
RenderData RenderData
{ _pictureShaders = shadV { _pictureShaders = shadV
+8 -7
View File
@@ -8,12 +8,13 @@ import Data.Tile
import Foreign import Foreign
pokeTile :: Ptr Float -> Int -> Tile -> IO Int pokeTile :: Ptr Float -> Int -> Tile -> IO Int
pokeTile ptr i t@Tile { _tilePoly = ps , _tileX = ttan } = do pokeTile ptr i t@Tile { _tilePoly = ps } = do
let coords = map (calcTexCoord (_tileZero t) ttan) ps foldM (pokeTileVerx ttan (_tileZ t) ptr) i $ triangulate $ zip ps (tileTexCoords t)
coords3 = map (addZ (_tileZ t)) coords where
foldM (pokeTileVerx ttan ptr) i $ triangulate $ zip ps coords3 ttan = _tileTangentPos t - _tileZero t
pokeTileVerx :: Point2 -> Ptr Float -> Int -> (Point2,Point3) -> IO Int pokeTileVerx :: Point2 -> Float -> Ptr Float -> Int -> (Point2,Point2) -> IO Int
pokeTileVerx (V2 t s) ptr i (V2 x y,V3 u v w) = do pokeTileVerx tangent tilez ptr i (V2 x y,V2 s t) = do
zipWithM_ (\off -> pokeElemOff ptr (i*8 + off)) [0..] [x,y,s,t,u,v,w,1] let a = argV tangent
zipWithM_ (\off -> pokeElemOff ptr (i*8 + off)) [0..] [x,y,1,1,s,t,tilez,a]
return $ i + 1 return $ i + 1
+15 -13
View File
@@ -1,33 +1,35 @@
module Tile module Tile
( tileTexCoords
, makeTileFromPoly
)
where where
import Data.Tile import Data.Tile
import Geometry import Geometry
tileToRenderList :: Tile -> [(Point3,Point3)] tileTexCoords :: Tile -> [Point2]
tileToRenderList t = polyToTris $ zip ps3 coords3 tileTexCoords t = map
(calcTexCoord (_tileZero t) tangent (- vNormal tangent))
(_tilePoly t)
where where
ps = _tilePoly t tangent = _tileTangentPos t - _tileZero t
coords = map (calcTexCoord (_tileZero t) (_tileX t)) ps
ps3 = map (addZ 0) ps
coords3 = map (addZ (_tileZ t)) coords
calcTexCoord calcTexCoord
:: Point2 -- ^ tile (0,0) :: Point2 -- ^ tile (0,0)
-> Point2 -- ^ tile (1,0) -> Point2 -- ^ tile tangent
-> Point2 -- ^ tile cotangent
-> Point2 -- ^ world point -> Point2 -- ^ world point
-> Point2 -> Point2
calcTexCoord c p x = V2 (vectorAmountIn xdir) (vectorAmountIn ydir) calcTexCoord zp tangent cotangent p = V2 (f tangent) (f cotangent)
where where
vectorAmountIn dir = 0.02 * dotV (p -.- c) dir f t = closestPointOnLineParam zp (zp + t) p
xdir = x -.- c
ydir = vNormal xdir
makeTileFromPoly :: [Point2] -> Float -> Tile makeTileFromPoly :: [Point2] -> Float -> Tile
makeTileFromPoly poly z = Tile makeTileFromPoly poly z = Tile
{ _tilePoly = poly { _tilePoly = poly
, _tileZero = c , _tileZero = c
, _tileX = c +.+ normalizeV ((poly !! 1) -.- c) , _tileTangentPos = c + (32 * normalizeV (d -.- c))
, _tileZ = z , _tileZ = z
} }
where where
c = head poly (c:d:_) = poly