Refactor shader loading

This commit is contained in:
2021-09-22 11:22:23 +01:00
parent 952ec1c579
commit a4fbe6126c
5 changed files with 133 additions and 78 deletions
+88 -61
View File
@@ -77,13 +77,13 @@ pistol = defaultGun
, _wpSpread = 0.02
, _wpRange = 20
, _itHammer = HammerUp
, _itFloorPict = (,) emptySH $ onLayer FlItLayer pistolPic
, _itFloorPict = pistolPic
, _itAmount = 1
, _itMaxStack = 1
, _itAimingSpeed = 1
, _itAimingRange = 0
, _itZoom = defaultItZoom
, _itEquipPict = pictureWeaponOnAim $ (,) emptySH pistolPic
, _itEquipPict = pictureWeaponOnAim pistolPic
, _itAttachment = NoItAttachment
, _itID = Nothing
, _itEffect = wpRecock
@@ -93,8 +93,11 @@ pistol = defaultGun
, _itWorldTrigger = Nothing
, _wpAmmo = basicBullet
}
pistolPic :: Picture
pistolPic = color green $ polygon $ rectNESW 5 5 (-5) (-5)
pistolPic :: SPic
pistolPic =
( colorSH green $ upperPrismPoly 3 $ rectNESW 5 5 (-5) (-5)
, mempty
)
effectGun :: String -> (Creature -> World -> World) -> Item
@@ -152,17 +155,19 @@ teslaGun = defaultGun
]
, _wpSpread = 0.001
, _wpRange = 20
, _itFloorPict = (,) emptySH $ onLayer FlItLayer teslaGunPic
, _itFloorPict = teslaGunPic
, _itAimingSpeed = 0.4
, _itZoom = defaultItZoom
, _itAimingRange = 0
, _itEquipPict = pictureWeaponOnAim $ (,) emptySH teslaGunPic
, _itEquipPict = pictureWeaponOnAim teslaGunPic
}
teslaGunPic :: Picture
teslaGunPic = color blue $ pictures
[polygon $ rectNESW xb y xa (-y)
,polygon $ rectNESW (-xa) y (-xb) (-y)
]
teslaGunPic :: SPic
teslaGunPic =
( colorSH blue $
upperPrismPoly 5 (rectNESW xb y xa (-y))
++ (upperPrismPoly 5 $ rectNESW (-xa) y (-xb) (-y))
, mempty
)
where
xa = 1
xb = 9
@@ -187,16 +192,19 @@ lasGun = defaultAutoGun
]
, _wpSpread = 0.001
, _wpRange = 20
, _itFloorPict = (,) emptySH $ onLayer FlItLayer lasGunPic
, _itFloorPict = lasGunPic
, _itAimingSpeed = 0.4
, _itAimingRange = 1
, _itEquipPict = pictureWeaponOnAim $ (,) emptySH lasGunPic
, _itEquipPict = pictureWeaponOnAim lasGunPic
, _itAttachment = ItCharMode $ Seq.fromList "/VZ"
, _itScroll = scrollCharMode
, _itInvDisplay = basicWeaponDisplay
}
lasGunPic :: Picture
lasGunPic = color blue . polygon $ rectNESW 3 15 (-3) (-15)
lasGunPic :: SPic
lasGunPic =
( colorSH blue . upperPrismPoly 5 $ rectNESW 3 15 (-3) (-15)
, mempty
)
forceFieldGun :: Item
forceFieldGun = defaultGun
{ _itName = "FORCEFIELD"
@@ -278,12 +286,18 @@ remoteLauncher = defaultGun
]
, _wpSpread = 0.02
, _wpRange = 20
, _itFloorPict = (,) emptySH $ onLayer FlItLayer $ color cyan $ polygon $ rectNESW 5 5 (-5) (-5)
, _itFloorPict = remoteLauncherSPic
, _itAimingSpeed = 0.2
, _itAimingRange = 0.5
, _itEquipPict = pictureWeaponOnAim $ (,) emptySH $ color cyan $ polygon $ rectNESW 5 5 (-5) (-5)
, _itEquipPict = pictureWeaponOnAim remoteLauncherSPic
, _itAttachment = ItScope (V2 0 0) 0 1 True
}
remoteLauncherSPic :: SPic
remoteLauncherSPic =
( colorSH cyan $ upperPrismPoly 7 $ rectNESW 5 5 (-5) (-5)
, mempty
)
hvAutoGun :: Item
hvAutoGun = defaultAutoGun
{ _itName = "AUTO-HV"
@@ -303,14 +317,17 @@ hvAutoGun = defaultAutoGun
, withMuzFlareI
]
, _wpRange = 20
, _itFloorPict = (,) emptySH $ onLayer FlItLayer hvAutoGunPic
, _itFloorPict = hvAutoGunPic
, _itAimingSpeed = 0.2
, _itAimingRange = 1
, _itEquipPict = pictureWeaponOnAim $ (,) emptySH hvAutoGunPic
, _itEquipPict = pictureWeaponOnAim hvAutoGunPic
, _wpAmmo = hvBullet
}
hvAutoGunPic :: Picture
hvAutoGunPic = color orange $ polygon $ rectNESW 5 12 (-5) (-12)
hvAutoGunPic :: SPic
hvAutoGunPic =
( colorSH orange $ upperPrismPoly 5 $ rectNESW 5 12 (-5) (-12)
, mempty
)
ltAutoGun :: Item
ltAutoGun = defaultAutoGun
{ _itName = "AUTO-LT"
@@ -334,19 +351,19 @@ ltAutoGun = defaultAutoGun
]
, _wpSpread = 0.5
, _wpRange = 20
, _itFloorPict = (,) emptySH $ onLayer FlItLayer ltAutoGunPic
, _itFloorPict = ltAutoGunPic
, _itAimingSpeed = 1
, _itAimingRange = 0
, _itZoom = defaultItZoom
, _itEquipPict = pictureWeaponOnAim $ (,) emptySH ltAutoGunPic
, _itEquipPict = pictureWeaponOnAim ltAutoGunPic
, _itAimStance = OneHand
, _wpAmmo = ltBullet
}
ltAutoGunPic :: Picture
ltAutoGunPic = color green $ pictures
[polygon $ rectNSWE 5 (-5) (-5) 0
,circleSolid 5
]
ltAutoGunPic :: SPic
ltAutoGunPic =
( colorSH green $ upperPrismPoly 5 $ mirrorXAxis [V2 (-5) 5, V2 5 5, V2 10 0]
, mempty
)
miniGun :: Item
miniGun = defaultAutoGun
{ _itName = "MINI-G"
@@ -393,10 +410,10 @@ miniGun = defaultAutoGun
, withSmoke 1 black 20 200 5
]
, _wpRange = 20
, _itFloorPict = (,) emptySH $ onLayer FlItLayer miniGunPict
, _itFloorPict = miniGunPict
, _itAimingSpeed = 0.4
, _itAimingRange = 1
, _itEquipPict = pictureWeaponOnAim $ (,) emptySH miniGunPict
, _itEquipPict = pictureWeaponOnAim miniGunPict
, _wpAmmo = basicBullet
}
where
@@ -411,11 +428,13 @@ miniGun = defaultAutoGun
[ 0.25, 0.5, 0.9]
--[ 0.75, 0.5, 0.25]
--[ 0, 0, 0]
miniGunPict :: Picture
miniGunPict = pictures
[ translate 5 0 . color red $ polygon $ rectNESW 9 7 (-9) (-5)
, color red . polygon $ rectNESW 4 12 (-4) (-12)
]
miniGunPict :: SPic
miniGunPict =
( (translateSHf 5 0 . colorSH red $ upperPrismPoly 10 $ rectNESW 9 7 (-9) (-5))
++ (colorSH red . upperPrismPoly 5 $ rectNESW 4 12 (-4) (-12))
, mempty
)
spreadGun :: Item
spreadGun = defaultGun
{ _itName = "SPREAD"
@@ -443,7 +462,7 @@ spreadGun = defaultGun
, _itFloorPict = spreadGunPic
, _itAimingSpeed = 1
, _itAimingRange = 0
, _itEquipPict = pictureWeaponOnAim $ spreadGunPic
, _itEquipPict = pictureWeaponOnAim spreadGunPic
, _wpAmmo = basicBullet
, _wpNumBarrels = 50
}
@@ -475,28 +494,31 @@ multGun = defaultGun
]
, _wpSpread = spreadGunSpread
, _wpRange = 20
, _itFloorPict = (,) emptySH $ onLayer FlItLayer multGunPic
, _itFloorPict = multGunSPic
, _itAimingSpeed = 0.4
, _itAimingRange = 1
, _itZoom = defaultItZoom
, _itAimZoom = defaultItZoom {_itZoomFac = 1.5}
, _itEquipPict = pictureWeaponOnAim $ (,) emptySH multGunPic
, _itEquipPict = pictureWeaponOnAim multGunSPic
, _itAimStance = TwoHandTwist
, _wpAmmo = basicBullet
, _wpNumBarrels = 5
}
multGunPic :: Picture
multGunPic = color red $ pictures
[ polygon $ rectNESW 4 8 (-4) (-12)
, translate 8 0 $ pictures
[ polygon $ rectNSEW 12 8 2 (-2)
, polygon $ rectNSEW 7 3 2 (-2)
, polygon $ rectNSEW 2 (-2) 2 (-2)
, polygon $ rectNSEW (-3) (-7) 2 (-2)
, polygon $ rectNSEW (-8) (-12) 2 (-2)
, polygon $ map toV2 [(-1.5,12),(-2,12),(-2,-12),(-1.5,-12)]
]
]
multGunSPic :: SPic
multGunSPic =
( colorSH red $
upperPrismPoly 2 (rectNESW 4 8 (-4) (-12)) ++
translateSHf 8 0 (mconcat
[ upperPrismPoly 5 $ rectNSEW 12 8 2 (-2)
, upperPrismPoly 5 $ rectNSEW 7 3 2 (-2)
, upperPrismPoly 5 $ rectNSEW 2 (-2) 2 (-2)
, upperPrismPoly 5 $ rectNSEW (-3) (-7) 2 (-2)
, upperPrismPoly 5 $ rectNSEW (-8) (-12) 2 (-2)
, upperPrismPoly 2 $ map toV2 [(-1.5,12),(-2,12),(-2,-12),(-1.5,-12)]
]
)
, mempty
)
longGun :: Item
longGun = defaultGun
{ _itName = "LONGGUN"
@@ -520,20 +542,23 @@ longGun = defaultGun
, withMuzFlareI
]
, _wpRange = 200
, _itFloorPict = (,) emptySH $ onLayer FlItLayer longGunPic
, _itFloorPict = longGunSPic
, _itAimingSpeed = 0.2
, _itAimingRange = 1
, _itZoom = defaultItZoom
, _itAimZoom = defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5}
, _itEquipPict = pictureWeaponOnAim $ (,) emptySH longGunPic
, _itEquipPict = pictureWeaponOnAim longGunSPic
, _itScroll = zoomLongGun
, _itAttachment = ItScope (V2 0 0) 0 1 False
, _itEffect = itemLaserScopeEffect
, _wpAmmo = hvBullet
, _itAimStance = TwoHandTwist
}
longGunPic :: Picture
longGunPic = pictures [color orange $ polygon $ rectNESW 2 12 (-2) (-12) ]
longGunSPic :: SPic
longGunSPic =
( colorSH orange $ upperPrismPoly 5 $ rectNESW 2 12 (-2) (-12)
, mempty
)
zoomLongGun :: Float -> Creature -> Item -> Item
zoomLongGun x _
@@ -591,19 +616,21 @@ flamer = defaultAutoGun
]
, _wpSpread = 0
, _wpRange = 8
, _itFloorPict = (,) emptySH $ onLayer FlItLayer flamerPic
, _itFloorPict = flamerPic
, _itAimingSpeed = 0.5
, _itAimingRange = 0
, _itZoom = defaultItZoom
, _itAimZoom = defaultItZoom {_itZoomMax = 5, _itZoomMin = 1.5}
, _itEquipPict = pictureWeaponOnAim $ (,) emptySH flamerPic
, _itEquipPict = pictureWeaponOnAim flamerPic
, _itAttachment = NoItAttachment
}
flamerPic :: Picture
flamerPic = color yellow $ pictures
[ translate (negate 5) (negate 7) $ circleSolid 5
, polygon $ rectNESW 2 9 (-2) (-9)
]
flamerPic :: SPic
flamerPic =
( colorSH yellow $
translateSHf (negate 5) (negate 7) (upperPrismPoly 3 $ polyCirc 3 5)
++ upperPrismPoly 5 (rectNESW 2 9 (-2) (-9))
, mempty
)
blinkGun :: Item
blinkGun = defaultGun
{ _itName = "BLINKER"
+8 -6
View File
@@ -6,7 +6,6 @@ import Dodge.Default.Weapon
import Dodge.Default.Shell
import Dodge.SoundLogic.LoadSound
import Dodge.WorldEvent.Explosion
import Dodge.Picture.Layer
import Dodge.Item.Data
import Dodge.Item.Draw
import Dodge.Item.Weapon.Shell
@@ -22,7 +21,7 @@ import Geometry.Vector3D
import Picture
import qualified IntMapHelp as IM
import Padding
--import ShapePicture
import ShapePicture
import Shape
import Data.Maybe
@@ -50,10 +49,10 @@ launcher = defaultGun
]
, _wpSpread = 0.02
, _wpRange = 20
, _itFloorPict = (,) emptySH $ onLayer FlItLayer launcherPic
, _itFloorPict = launcherPic
, _itAimingSpeed = 0.2
, _itAimingRange = 0.5
, _itEquipPict = pictureWeaponOnAim $ (,) emptySH launcherPic
, _itEquipPict = pictureWeaponOnAim launcherPic
, _itHammer = NoHammer
, _itEffect = NoItEffect
, _wpAmmo = defaultShellAmmo
@@ -65,8 +64,11 @@ launcher = defaultGun
, _itAimStance = TwoHandTwist
}
launcherPic :: Picture
launcherPic = color cyan $ polygon $ rectNESW 5 10 (-5) (-10)
launcherPic :: SPic
launcherPic =
( colorSH cyan $ upperPrismPoly 7 $ rectNESW 5 10 (-5) (-10)
, mempty
)
basicAmPjMoves :: [PjParam]
basicAmPjMoves =
+8
View File
@@ -25,6 +25,7 @@ import Geometry.Vector
import Geometry.LHS
--import Geometry.Zone
import Data.Maybe
import Data.List
-- | Return a point a distance away from a first point towards a second point.
-- Does not go past the second point.
@@ -64,6 +65,13 @@ rectNSWE !n !s !w !e = [V2 w n, V2 w s, V2 e s, V2 e n]
-- | Draw a rectangle around the origin with given height and width
rectWdthHght :: Float -> Float -> [Point2]
rectWdthHght w h = rectNSWE h (-h) (-w) w
mirrorXAxis :: [Point2] -> [Point2]
mirrorXAxis ps = orderPolygon $ ps ++ mapMaybe f ps
where
f (V2 _ 0) = Nothing
f (V2 x y) = Just $ V2 x (-y)
-- | Test whether a point is in a polygon or on the polygon border.
-- Supposes the points in the
-- polygon are listed in anticlockwise order.
+11 -11
View File
@@ -117,13 +117,13 @@ preloadRender = do
let silEBO = EBO {_ebo = silEBOname, _eboPtr = silEBOptr}
shEdgeVAO = VAO { _vao = shEdgeVAOname, _vaoVBO = shVBO }
-- lighting shaders
wsShad <- makeShader "lighting/occlude" [vert,geom,frag] [4] EPoints
lightingOccludeShad <- makeShaderUsingVAO "lighting/occlude" [vert,geom,frag] EPoints wpVAO
>>= addUniforms ["lightPos"]
lightingCapShad
<- makeShader "lighting/cap" [vert,geom,frag] [3] ETriangles
<- makeShaderUsingVAO "lighting/cap" [vert,geom,frag] ETriangles shPosVAO
>>= addUniforms ["lightPos"]
lightingLineShadowShad
<- makeShader "lighting/lineShadow" [vert,geom,frag] [3] ELinesAdjacency
<- makeShaderUsingVAO "lighting/lineShadow" [vert,geom,frag] ELinesAdjacency shEdgeVAO
>>= addUniforms ["lightPos"]
-- 2D draw shaders
bslist <- makeShader "dualTwoD/basic" [vert,frag] [3,4] ETriangles
@@ -150,9 +150,9 @@ preloadRender = do
>>= addUniforms ["lightPos","lumRad"]
barrelShad <- makeShader "texture/barrel" [vert,geom,frag] [2,2,2,1] EPoints
-- blank wallShader
wlBlank <- makeShader "wall/blank" [vert,geom,frag] [4,4] EPoints
wallBlankShad <- makeShaderUsingVAO "wall/blank" [vert,geom,frag] EPoints wpColVAO
-- textured wallShader
wlTexture <- makeShader "wall/texture" [vert,geom,frag] [4,4] EPoints
wallTextureShad <- makeShaderUsingVAO "wall/texture" [vert,geom,frag] EPoints wpColVAO
>>= addTexture "data/texture/grayscaleDirt.png"
---- texture array shader
textArrayShad <- makeShader "texture/arrayPos" [vert,frag] [3,3] ETriangles
@@ -200,12 +200,12 @@ preloadRender = do
, _shapeShader = bslista {_shadVAO = shPosColVAO }
, _shapeEBO = shEBO
, _silhouetteEBO = silEBO
, _lightingCapShader = lightingCapShad { _shadVAO = shPosVAO }
, _lightingLineShadowShader = lightingLineShadowShad {_shadVAO = shEdgeVAO}
, _lightingOccludeShader = wsShad {_shadVAO = wpVAO}
, _wallBlankShader = wlBlank { _shadVAO = wpColVAO }
, _wallTextureShader = wlTexture { _shadVAO = wpColVAO }
, _windowShader = wlBlank { _shadVAO = winColVAO }
, _lightingCapShader = lightingCapShad
, _lightingLineShadowShader = lightingLineShadowShad
, _lightingOccludeShader = lightingOccludeShad
, _wallBlankShader = wallBlankShad
, _wallTextureShader = wallTextureShad
, _windowShader = wallBlankShad { _shadVAO = winColVAO }
, _textureArrayShader = textArrayShad
, _fullscreenShader = fsShad
, _fullLightingShader = fullLightingShad
+18
View File
@@ -4,6 +4,7 @@ module Shader.Compile
, makeByteStringShaderUsingVAO
, makeShaderSized
, makeShaderUsingShaderVAO
, makeShaderUsingVAO
, makeSourcedShader
, setupVAO
, setupVertexAttribPointer
@@ -67,6 +68,23 @@ makeByteStringShaderUsingVAO s shaderlist pm fs = do
, _shadUnis = []
}
-- | Takes the VAO from elsewhere
makeShaderUsingVAO
:: String -- ^ First part of the name of the shader
-> [ShaderType] -- ^ Filetype extensions
-> EPrimitiveMode
-> VAO
-> IO FullShader
makeShaderUsingVAO s shaderlist pm theVAO = do
prog <- makeSourcedShader s shaderlist
return $ FullShader
{ _shadProg = prog
, _shadVAO = theVAO
, _shadPrim = pm
, _shadTex = Nothing
, _shadUnis = []
}
-- | Takes the VAO from another shader
makeShaderUsingShaderVAO
:: String -- ^ First part of the name of the shader