Add line shadow shader

This commit is contained in:
2021-06-26 22:20:41 +02:00
parent 726cd425f2
commit 06f22a3ea5
21 changed files with 128 additions and 74 deletions
+6
View File
@@ -0,0 +1,6 @@
#version 430 core
out vec4 fColor;
void main()
{
fColor = vec4 (0.9,0.5,0,0);
}
+19
View File
@@ -0,0 +1,19 @@
#version 430 core
layout (lines) in;
layout (triangle_strip, max_vertices = 4) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
uniform vec3 lightPos;
vec4 shift (vec4 p) { return (vec4 (p.xyz + (2000*(p.xyz-lightPos)), 1));}
vec4 f (vec4 p) {return (theMat * p);}
void main()
{
vec4 p0 = gl_in[0].gl_Position;
gl_Position = f(p0); EmitVertex();
vec4 p1 = gl_in[1].gl_Position;
gl_Position = f(p1); EmitVertex();
vec4 p2 = shift(p0);
gl_Position = f(p2); EmitVertex();
vec4 p3 = shift(p1);
gl_Position = f(p3); EmitVertex();
EndPrimitive();
}
+6
View File
@@ -0,0 +1,6 @@
#version 430 core
layout (location = 0) in vec3 pos;
void main()
{
gl_Position = vec4(pos,1);
}
+7 -7
View File
@@ -5,7 +5,7 @@ layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
uniform vec3 lightPos; uniform vec3 lightPos;
vec4 shift (vec4 p) vec4 shift (vec4 p)
{ return vec4 (p.xy + (200 * (p.xy-lightPos.xy)), 0.1 , 1); { return vec4 (p.xy + (200 * (p.xy-lightPos.xy)), (-1) , 1);
} }
float isLHS (vec2 startV, vec2 testV) float isLHS (vec2 startV, vec2 testV)
{ {
@@ -14,16 +14,16 @@ float isLHS (vec2 startV, vec2 testV)
// construct a box with openings on bottom face and face away from wall // construct a box with openings on bottom face and face away from wall
void main() void main()
{ {
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0.1,1); vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0.1,1); vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1);
if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0) if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0)
{ {
vec4 p3 = vec4 (p1.xy,-0.5,1); vec4 p3 = vec4 (p1.xy,100,1);
vec4 p4 = vec4 (p2.xy,-0.5,1); vec4 p4 = vec4 (p2.xy,100,1);
vec4 p5 = shift(p1); vec4 p5 = shift(p1);
vec4 p6 = shift(p2); vec4 p6 = shift(p2);
vec4 p7 = vec4 (p6.xy,-0.5,1); vec4 p7 = vec4 (p6.xy,100,1);
vec4 p8 = vec4 (p5.xy,-0.5,1); vec4 p8 = vec4 (p5.xy,100,1);
vec4 a1 = theMat * p1; vec4 a1 = theMat * p1;
vec4 a2 = theMat * p2; vec4 a2 = theMat * p2;
+8 -8
View File
@@ -14,15 +14,15 @@ vec4 shiftCloser (vec4 v)
{ return vec4 (v.xy , v.z-0.0001 , v.w) ; } { return vec4 (v.xy , v.z-0.0001 , v.w) ; }
void main() void main()
{ {
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0.1,1); vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0.1,1); vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1);
if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0) if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0)
{ {
lum = radLum.y; lum = radLum.y;
float rad = radLum.x; float rad = radLum.x;
vec4 p3 = vec4 (p1.xy,-0.3,1); vec4 p3 = vec4 (p1.xy,100,1);
vec4 p4 = vec4 (p2.xy,-0.3,1); vec4 p4 = vec4 (p2.xy,100,1);
vec2 d1 = p1.xy - lightPos.xy; vec2 d1 = p1.xy - lightPos.xy;
vec2 d2 = p2.xy - lightPos.xy; vec2 d2 = p2.xy - lightPos.xy;
@@ -32,16 +32,16 @@ if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0)
vec4 a3 = shiftCloser( theMat * p3 ); vec4 a3 = shiftCloser( theMat * p3 );
vec4 a4 = shiftCloser( theMat * p4 ); vec4 a4 = shiftCloser( theMat * p4 );
dField = vec3( d1.x/rad, d1.y/rad, 100.0/rad); dField = (p1.xyz - lightPos) / rad;
gl_Position = a1; gl_Position = a1;
EmitVertex(); EmitVertex();
dField = vec3( d1.x/rad, d1.y/rad, -300.0/rad); dField = (p3.xyz - lightPos) / rad;
gl_Position = a3; gl_Position = a3;
EmitVertex(); EmitVertex();
dField = vec3( d2.x/rad, d2.y/rad, 100.0/rad); dField = (p2.xyz - lightPos) / rad;
gl_Position = a2; gl_Position = a2;
EmitVertex(); EmitVertex();
dField = vec3( d2.x/rad, d2.y/rad, -300.0/rad); dField = (p4.xyz - lightPos) / rad;
gl_Position = a4; gl_Position = a4;
EmitVertex(); EmitVertex();
+2 -5
View File
@@ -20,12 +20,9 @@ void main()
vec4 a1 = theMat * p1; vec4 a1 = theMat * p1;
vec4 a2 = theMat * p2; vec4 a2 = theMat * p2;
// if (0 > isLHS (a1.xy - a2.xy, a1.xy - "viewFromPoint")) { // if (0 > isLHS (a1.xy - a2.xy, a1.xy - "viewFromPoint")) {
vec4 p3 = vec4 (p1.xy,150,1);
vec4 p3 = vec4 (p1.xy,-0.5,1); vec4 p4 = vec4 (p2.xy,150,1);
vec4 p4 = vec4 (p2.xy,-0.5,1);
vec4 a3 = theMat * p3; vec4 a3 = theMat * p3;
vec4 a4 = theMat * p4; vec4 a4 = theMat * p4;
+4 -4
View File
@@ -15,10 +15,10 @@ void main()
{ {
gColor = vColor[0]; gColor = vColor[0];
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0.1,1); vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0.1,1); vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1);
vec4 p3 = vec4 (p1.xy,-0.5,1); vec4 p3 = vec4 (p1.xy,150,1);
vec4 p4 = vec4 (p2.xy,-0.5,1); vec4 p4 = vec4 (p2.xy,150,1);
vec4 a1 = theMat * p1; vec4 a1 = theMat * p1;
vec4 a2 = theMat * p2; vec4 a2 = theMat * p2;
+1
View File
@@ -11,6 +11,7 @@ data RenderData = RenderData
, _lightingOccludeShader :: FullShader , _lightingOccludeShader :: FullShader
, _lightingWallShader :: FullShader , _lightingWallShader :: FullShader
, _lightingSurfaceShader :: FullShader , _lightingSurfaceShader :: FullShader
, _lightingLineShadowShader :: FullShader
, _wallBlankShader :: FullShader , _wallBlankShader :: FullShader
, _wallTextureShader :: FullShader , _wallTextureShader :: FullShader
, _textureShader :: FullShader , _textureShader :: FullShader
+7 -6
View File
@@ -33,17 +33,16 @@ lamp = defaultInanimate
} }
lampPic :: Picture lampPic :: Picture
lampPic = pictures lampPic = pictures
[ setDepth (0.09) $ color white $ p [ setDepth (0.049) $ color white $ polygon $ rectNSEW 5 (-5) 5 (-5)
, setDepth (0) $ color yellow $ p , setDepth (0) $ color white $ circleSolid 3
] ]
where
p = pictures [circleSolid 3, polygon $ rectNSEW 5 0 5 0]
initialiseLamp :: CRUpdate initialiseLamp :: CRUpdate
initialiseLamp w (f,g) cr = ( (addLS . f , g), Just $ cr & crUpdate .~ updateLamp i) initialiseLamp w (f,g) cr = ( (addLS . f , g), Just $ cr & crUpdate .~ updateLamp i)
where where
i = IM.newKey $ _lightSources $ f w -- to give different lights different keys i = IM.newKey $ _lightSources $ f w -- to give different lights different keys
addLS = over lightSources (IM.insert i (lightAt (_crPos cr) i)) addLS = over lightSources (IM.insert i (lightAt (x,y,0) i))
(x,y) = _crPos cr
updateLamp :: Int -> CRUpdate updateLamp :: Int -> CRUpdate
updateLamp i = unrandUpdate handleLS internalUpdate updateLamp i = unrandUpdate handleLS internalUpdate
@@ -65,6 +64,7 @@ barrel = defaultInanimate
, _crHP = 500 , _crHP = 500
, _crPict = picAtCrPos $ onLayer CrLayer $ pictures , _crPict = picAtCrPos $ onLayer CrLayer $ pictures
[ color orange $ circleSolid 10 [ color orange $ circleSolid 10
, setDepth 0.049 . color (greyN 0.5) $ circleSolid 8
, color (greyN 0.5) $ circleSolid 8 , color (greyN 0.5) $ circleSolid 8
] ]
, _crState = defaultState , _crState = defaultState
@@ -77,8 +77,9 @@ explosiveBarrel :: Creature
explosiveBarrel = defaultInanimate explosiveBarrel = defaultInanimate
{ _crUpdate = updateExpBarrel { _crUpdate = updateExpBarrel
, _crHP = 400 , _crHP = 400
, _crPict = picAtCrPos $ onLayer CrLayer $ pictures , _crPict = picAtCrPos $ pictures
[ color red $ circleSolid 8 [ color red $ circleSolid 8
, setDepth 0.049 . color (greyN 0.5) $ circleSolid 10
, color orange $ circleSolid 10 , color orange $ circleSolid 10
] ]
, _crState = defaultState , _crState = defaultState
+19 -18
View File
@@ -12,7 +12,7 @@ import Dodge.Creature.State.Data
import Dodge.Creature.Stance.Data import Dodge.Creature.Stance.Data
import Dodge.Creature.Test import Dodge.Creature.Test
--import Dodge.Creature.AlertLevel.Data --import Dodge.Creature.AlertLevel.Data
import Dodge.Picture.Layer --import Dodge.Picture.Layer
import Dodge.Item.Data import Dodge.Item.Data
import Picture import Picture
import Geometry import Geometry
@@ -27,7 +27,8 @@ basicCrPict
-> Picture -> Picture
basicCrPict col cr w = pictures $ basicCrPict col cr w = pictures $
targetingPic ++ targetingPic ++
[ tr . piercingMod $ bluntScale $ naked col cr [ tr . setDepth 0 $ color yellow $ circleSolid 10
, tr . piercingMod $ bluntScale $ naked col cr
, tr $ waist col , tr $ waist col
, trFeet $ feet cr , trFeet $ feet cr
, tr $ arms col cr , tr $ arms col cr
@@ -55,7 +56,7 @@ basicCrPict col cr w = pictures $
pastDams = _crPastDamage $ _crState cr pastDams = _crPastDamage $ _crState cr
waist :: Color -> Picture waist :: Color -> Picture
waist col = setDepth 0.025 . color (light4 col) . scale 0.5 1 $ circleSolid 8 waist col = setDepth 10 . color (light4 col) . scale 0.5 1 $ circleSolid 8
feet :: Creature -> Picture feet :: Creature -> Picture
feet cr = case cr ^? crStance . carriage of feet cr = case cr ^? crStance . carriage of
@@ -73,7 +74,7 @@ feet cr = case cr ^? crStance . carriage of
] ]
where where
--setL = onLayerL [levLayer CrLayer, -5] . color (greyN 0.3) . pictures --setL = onLayerL [levLayer CrLayer, -5] . color (greyN 0.3) . pictures
setL = setDepth 0.049 . color (greyN 0.3) . pictures setL = setDepth 1 . color (greyN 0.3) . pictures
off = 5 off = 5
sLen = _strideLength $ _crStance cr sLen = _strideLength $ _crStance cr
f i = 6 * fromIntegral (sLen - i) / fromIntegral sLen f i = 6 * fromIntegral (sLen - i) / fromIntegral sLen
@@ -92,7 +93,7 @@ arms col cr
where where
sc = scale 1 1 sc = scale 1 1
--setL = onLayerL [levLayer CrLayer, -4] . color (light4 col) . pictures --setL = onLayerL [levLayer CrLayer, -4] . color (light4 col) . pictures
setL = setDepth 0.02 . color (light4 col) . pictures setL = setDepth 20 . color (light4 col) . pictures
off = 8 off = 8
sLen = _strideLength $ _crStance cr sLen = _strideLength $ _crStance cr
f i = negate 2 + negate 6 * fromIntegral (sLen - i) / fromIntegral sLen f i = negate 2 + negate 6 * fromIntegral (sLen - i) / fromIntegral sLen
@@ -102,30 +103,30 @@ arms col cr
naked :: Color -> Creature -> Picture naked :: Color -> Creature -> Picture
naked col cr naked col cr
| strikeMelee = onCrL . color white $ circleSolid $ _crRad cr | strikeMelee = shoulderH . color white $ circleSolid $ _crRad cr
| pdam > 200 = onCrL . color red $ circleSolid $ _crRad cr | pdam > 200 = shoulderH . color red $ circleSolid $ _crRad cr
| pdam > 99 = onCrL . color white $ circleSolid $ _crRad cr | pdam > 99 = shoulderH . color white $ circleSolid $ _crRad cr
| aimingOneHand = rotate (negate twistA * 0.5) $ pictures | aimingOneHand = rotate (negate twistA * 0.5) $ pictures
[ translate (0.25 * crad) 0 fhead [ translate (0.25 * crad) 0 fhead
, onCrL . translate 8 (-8) . color col' $ circleSolid 4 , shoulderH . translate 8 (-8) . color col' $ circleSolid 4
, translate 0 3 . rotate (negate 0.2) . scale 0.5 1 $ color col' $ circleSolid $ _crRad cr , translate 0 3 . rotate (negate 0.2) . scale 0.5 1 $ color col' $ circleSolid $ _crRad cr
, translate 0 (negate 3) . rotate 0.2 . scale 0.5 1 $ color col' $ circleSolid $ _crRad cr , translate 0 (negate 3) . rotate 0.2 . scale 0.5 1 $ color col' $ circleSolid $ _crRad cr
] ]
| aimingTwist = translate 0 (0.5* crad) . rotate twistA $ pictures | aimingTwist = translate 0 (0.5* crad) . rotate twistA $ pictures
[ translate (negate 0.25 * crad) 0.25 fhead [ translate (negate 0.25 * crad) 0.25 fhead
, onCrL . translate 12 4 . color col' $ circleSolid 4 , shoulderH . translate 12 4 . color col' $ circleSolid 4
, onCrL . translate 4 (-10) . color col' $ circleSolid 4 , shoulderH . translate 4 (-10) . color col' $ circleSolid 4
, onCrL . rotate (negate 0.2) . translate 2 3 . rotate (negate 0.4) . scale 0.5 1 $ color col' $ circleSolid $ _crRad cr , shoulderH . rotate (negate 0.2) . translate 2 3 . rotate (negate 0.4) . scale 0.5 1 $ color col' $ circleSolid $ _crRad cr
, onCrL . rotate (negate 0.2) . translate 0 (negate 3) . rotate 0.2 . scale 0.5 1 $ color col' $ circleSolid $ _crRad cr , shoulderH . rotate (negate 0.2) . translate 0 (negate 3) . rotate 0.2 . scale 0.5 1 $ color col' $ circleSolid $ _crRad cr
] ]
| otherwise = onCrL $ pictures | otherwise = pictures
[ translate (0.25 * crad) 0 fhead [ translate (0.25 * crad) 0 fhead
, translate 0 3 . rotate (negate 0.2) . scale 0.5 1 $ color col' $ circleSolid $ _crRad cr , shoulderH . translate 0 3 . rotate (negate 0.2) . scale 0.5 1 $ color col' $ circleSolid $ _crRad cr
, translate 0 (negate 3) . rotate 0.2 . scale 0.5 1 $ color col' $ circleSolid $ _crRad cr , shoulderH . translate 0 (negate 3) . rotate 0.2 . scale 0.5 1 $ color col' $ circleSolid $ _crRad cr
] ]
where where
fhead = setDepth (negate 0.01) $ circleSolid $ crad * 0.5 fhead = setDepth 30 $ circleSolid $ crad * 0.5
onCrL = setDepth 0 shoulderH = setDepth 20
twistA = negate 1 twistA = negate 1
aimingOneHand = crIsAiming' cr && crIt ^? itAimStance == Just OneHand aimingOneHand = crIsAiming' cr && crIt ^? itAimStance == Just OneHand
aimingTwist = crIsAiming' cr && crIt ^? itAimStance == Just TwoHandTwist aimingTwist = crIsAiming' cr && crIt ^? itAimStance == Just TwoHandTwist
+2 -1
View File
@@ -99,7 +99,8 @@ escapeMap w = w & carteDisplay .~ False
dropLight :: World -> World dropLight :: World -> World
dropLight w = placeLS ls dec pos 0 w dropLight w = placeLS ls dec pos 0 w
where --(rot, g) = randomR (-pi,pi) $ _randGen w where --(rot, g) = randomR (-pi,pi) $ _randGen w
pos = _crPos(you w) (x,y) = _crPos(you w)
pos = (x,y,0)
ls = lightAt pos 0 ls = lightAt pos 0
dec = onLayer PtLayer $ color white $ circleSolid 8 dec = onLayer PtLayer $ color white $ circleSolid 8
+2 -2
View File
@@ -21,8 +21,8 @@ initializeWorld w = w
firstWorld :: IO World firstWorld :: IO World
firstWorld = do firstWorld = do
i <- randomRIO (0,5000) -- i <- randomRIO (0,5000)
-- let i = 2 let i = 2
putStrLn $ "Seed for level generation: " ++ show ( i :: Int) putStrLn $ "Seed for level generation: " ++ show ( i :: Int)
return $ generateLevelFromRoomList levx $ initialWorld {_randGen = mkStdGen i} return $ generateLevelFromRoomList levx $ initialWorld {_randGen = mkStdGen i}
+8 -6
View File
@@ -19,6 +19,7 @@ import Dodge.LevelGen.TriggerDoor
import Dodge.LevelGen.Switch import Dodge.LevelGen.Switch
import Dodge.LevelGen.Data import Dodge.LevelGen.Data
import Geometry import Geometry
import Geometry.Data
import Picture import Picture
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
@@ -70,7 +71,7 @@ placeSpot ps w = case _psType ps of
PutButton bt -> placeBt bt p rot w PutButton bt -> placeBt bt p rot w
PutFlIt itm -> placeFlIt itm p rot w PutFlIt itm -> placeFlIt itm p rot w
PutCrit cr -> placeCr cr p rot w PutCrit cr -> placeCr cr p rot w
PutLS ls dec -> placeLS ls dec p rot w PutLS ls dec -> placeLS ls dec p' rot w
PutPressPlate pp -> placePressPlate pp p rot w PutPressPlate pp -> placePressPlate pp p rot w
RandPS rgen -> placeSpot (set psType evaluatedType ps) (set randGen g w) RandPS rgen -> placeSpot (set psType evaluatedType ps) (set randGen g w)
where where
@@ -97,7 +98,8 @@ placeSpot ps w = case _psType ps of
PutID _ -> w PutID _ -> w
--_ -> w --_ -> w
where where
p = _psPos ps p@(px,py) = _psPos ps
p' = (px,py,0)
rot = _psRot ps rot = _psRot ps
-- TODO: remove this typeclass -- TODO: remove this typeclass
@@ -188,14 +190,14 @@ placeCr crF p rot = over creatures addCr
(crF {_crPos = p,_crOldPos = p,_crDir = rot,_crID = IM.newKey crs}) (crF {_crPos = p,_crOldPos = p,_crDir = rot,_crID = IM.newKey crs})
crs crs
placeLS :: LightSource -> Picture -> Point2 -> Float -> World -> World placeLS :: LightSource -> Picture -> Point3 -> Float -> World -> World
placeLS ls dec p@(x,y) rot w = over lightSources addLS $ over decorations addDec w placeLS ls dec (x,y,z) rot w = over lightSources addLS $ over decorations addDec w
where where
addLS lss = IM.insert addLS lss = IM.insert
(IM.newKey lss) (IM.newKey lss)
(ls {_lsPos = (x,y,0),_lsDir = rot,_lsID = IM.newKey lss}) (ls {_lsPos = (x,y,z),_lsDir = rot,_lsID = IM.newKey lss})
lss lss
addDec decs = IM.insert addDec decs = IM.insert
(IM.newKey decs) (IM.newKey decs)
(uncurry translate p $ rotate (negate rot) dec) (translate x y $ rotate (negate rot) dec)
decs decs
+6 -5
View File
@@ -5,21 +5,22 @@ import Dodge.Picture.Layer
import Dodge.LevelGen.Data import Dodge.LevelGen.Data
--import Geometry --import Geometry
import Picture import Picture
import Geometry.Data
--import qualified Data.IntMap.Strict as IM --import qualified Data.IntMap.Strict as IM
lightAt :: Point2 -> Int -> LightSource lightAt :: Point3 -> Int -> LightSource
lightAt (x,y) i = lightAt (x,y,z) i =
LS {_lsID = i LS {_lsID = i
,_lsPos = (x,y,0) ,_lsPos = (x,y,z)
,_lsDir = 0 ,_lsDir = 0
,_lsRad = 600 ,_lsRad = 500
,_lsIntensity = 0.75 ,_lsIntensity = 0.75
} }
basicLS :: PSType basicLS :: PSType
basicLS = PutLS ls dec basicLS = PutLS ls dec
where where
ls = lightAt (0,0) 0 ls = lightAt (0,0,0) 0
dec = onLayer PtLayer $ color white $ circleSolid 8 dec = onLayer PtLayer $ color white $ circleSolid 8
tLightFade :: Int -> Float -> (Int -> Float) -> Point2 -> TempLightSource tLightFade :: Int -> Float -> (Int -> Float) -> Point2 -> TempLightSource
-1
View File
@@ -65,7 +65,6 @@ doDrawing pdata w = do
$ polyToTris $ map addC $ screenPolygon w ] $ polyToTris $ map addC $ screenPolygon w ]
bindShaderBuffers [_lightingSurfaceShader pdata] [nsurfVs] bindShaderBuffers [_lightingSurfaceShader pdata] [nsurfVs]
depthFunc $= Just Less depthFunc $= Just Less
-- draw the lightmap. Probably changes the bound framebufferObject -- draw the lightmap. Probably changes the bound framebufferObject
createLightMap pdata (w ^. config . shadow_resolution) wallPoints lightPoints viewFroms createLightMap pdata (w ^. config . shadow_resolution) wallPoints lightPoints viewFroms
+8 -8
View File
@@ -46,15 +46,15 @@ diagonalLinesRect pa pb w d ang = zip lhsPoints $ map findDiPoint lhsPoints
highPipe :: Point2 -> Point2 -> Picture highPipe :: Point2 -> Point2 -> Picture
highPipe x y = pictures highPipe x y = pictures
[setDepth (-0.2) $ thickLine [x,y] 10 [setDepth 100 $ thickLine [x,y] 10
,setDepth (-0.19) $ color orange $ thickLine [x,y] 10 ,setDepth 90 $ color orange $ thickLine [x,y] 10
,verticalPipe 5 orange x 0 (-0.2) ,verticalPipe 5 orange x 0 100
,verticalPipe 5 orange y 0 (-0.2) ,verticalPipe 5 orange y 0 100
,verticalPipe 5 orange (0.5 *.* (x +.+ y)) (-0.1) (-0.2) ,verticalPipe 5 orange (0.5 *.* (x +.+ y)) 50 100
] ]
girderZ :: Float -> Point2 -> Point2 -> Picture girderZ :: Float -> Point2 -> Point2 -> Picture
girderZ w x y = setDepth (-0.1) $ color red $ pictures $ girderZ w x y = setDepth 50 $ color red $ pictures $
[ thickLine [xt,yt] 3 [ thickLine [xt,yt] 3
, thickLine [xb,yb] 3 , thickLine [xb,yb] 3
] ]
@@ -70,7 +70,7 @@ girderZ w x y = setDepth (-0.1) $ color red $ pictures $
ps' = map (\p -> intersectSegLine' xt yt p (p +.+ dia)) ps ps' = map (\p -> intersectSegLine' xt yt p (p +.+ dia)) ps
ls = catMaybes $ zipWith (fmap . (,)) ps ps' ls = catMaybes $ zipWith (fmap . (,)) ps ps'
girderV :: Color -> Float -> Point2 -> Point2 -> Picture girderV :: Color -> Float -> Point2 -> Point2 -> Picture
girderV col w x y = setDepth (-0.1) $ color col $ pictures $ girderV col w x y = setDepth 50 $ color col $ pictures $
[ thickLine [xt,yt] 3 [ thickLine [xt,yt] 3
, thickLine [xb,yb] 3 , thickLine [xb,yb] 3
] ]
@@ -89,7 +89,7 @@ girderV col w x y = setDepth (-0.1) $ color col $ pictures $
bs' = catMaybes $ zipWith (fmap . (,)) as $ f (3*pi/4) as bs' = catMaybes $ zipWith (fmap . (,)) as $ f (3*pi/4) as
girder :: Color -> Float -> Point2 -> Point2 -> Picture girder :: Color -> Float -> Point2 -> Point2 -> Picture
girder col w x y = pictures $ girder col w x y = pictures $
setDepth (-0.1) (color col $ pictures $ setDepth 50 (color col $ pictures $
[ thickLine [xt,yt] 3 [ thickLine [xt,yt] 3
, thickLine [xb,yb] 3 , thickLine [xb,yb] 3
] ]
+1 -1
View File
@@ -23,7 +23,7 @@ startRoom = do
w <- state $ randomR (100,400) w <- state $ randomR (100,400)
h <- state $ randomR (200,400) h <- state $ randomR (200,400)
let fground = sPS (0,0) 0 $ PutForeground $ pictures let fground = sPS (0,0) 0 $ PutForeground $ pictures
[ highPipe (0,h/2) (w, h/2) [ highPipe (0,h/3) (w, h/3)
, girderV cola 10 (0,3*h/4) (w, 3*h/4) , girderV cola 10 (0,3*h/4) (w, 3*h/4)
, girder colb 5 (0,5*h/8) (w, 5*h/8) , girder colb 5 (0,5*h/8) (w, 5*h/8)
] ]
+16
View File
@@ -25,6 +25,8 @@ perspectiveMatrixb rot zoom (tranx,trany) (winx,winy) (viewFromx,viewFromy) =
!*! transMat (viewFromx-tranx,viewFromy-trany) !*! transMat (viewFromx-tranx,viewFromy-trany)
!*! perMat !*! perMat
!*! transMat (-viewFromx,-viewFromy) !*! transMat (-viewFromx,-viewFromy)
!*! vertScale
!*! vertTrans
perspectiveMatrixc perspectiveMatrixc
:: Float -- ^ Rotation :: Float -- ^ Rotation
@@ -72,3 +74,17 @@ transMat (x,y) = V4
(V4 0 1 0 y) (V4 0 1 0 y)
(V4 0 0 1 0) (V4 0 0 1 0)
(V4 0 0 0 1) (V4 0 0 0 1)
vertScale :: V4 (V4 Float)
vertScale = V4
(V4 1 0 0 0)
(V4 0 1 0 0)
(V4 0 0 (negate 0.005) 0)
(V4 0 0 0 1)
vertTrans :: V4 (V4 Float)
vertTrans = V4
(V4 1 0 0 0)
(V4 0 1 0 0)
(V4 0 0 1 (negate 20))
(V4 0 0 0 1)
+4
View File
@@ -36,6 +36,9 @@ preloadRender = do
lightingSurfaceShad lightingSurfaceShad
<- makeShader "lighting/surface" [vert,frag] [3] Triangles poke3 <- makeShader "lighting/surface" [vert,frag] [3] Triangles poke3
>>= addUniforms ["lightPos","radLum"] >>= addUniforms ["lightPos","radLum"]
lightingLineShadowShad
<- makeShader "lighting/lineShadow" [vert,geom,frag] [3] Lines poke3
>>= addUniforms ["lightPos"]
-- 2D draw shaders -- 2D draw shaders
bslist <- makeShader "twoD/basic" [vert,frag] [3,4] Triangles pokeTriStrat bslist <- makeShader "twoD/basic" [vert,frag] [3,4] Triangles pokeTriStrat
lslist <- makeShader "twoD/basic" [vert,frag] [3,4] Lines pokeLineStrat lslist <- makeShader "twoD/basic" [vert,frag] [3,4] Lines pokeLineStrat
@@ -76,6 +79,7 @@ preloadRender = do
return $ RenderData return $ RenderData
{ _pictureShaders = [bslist,lslist,cslist,aslist,eslist,bezierQuadShader] { _pictureShaders = [bslist,lslist,cslist,aslist,eslist,bezierQuadShader]
, _lightingSurfaceShader = lightingSurfaceShad , _lightingSurfaceShader = lightingSurfaceShad
, _lightingLineShadowShader = lightingLineShadowShad
, _lightingFloorShader = lightingFloorShad , _lightingFloorShader = lightingFloorShad
, _lightingOccludeShader = wsShad , _lightingOccludeShader = wsShad
, _lightingWallShader = wlLightShad , _lightingWallShader = wlLightShad
+1 -1
View File
@@ -119,7 +119,7 @@ compileAndCheckShader str (theShaderType,sourceCode) = do
success <- compileStatus theShader success <- compileStatus theShader
unless success $ do unless success $ do
infoLog <- get (shaderInfoLog theShader) infoLog <- get (shaderInfoLog theShader)
putStrLn $ str ++ ": Shader compile: " ++ show theShaderType ++ " : " ++ show infoLog putStrLn $ str ++ ": Shader compile: " ++ show theShaderType ++ " :\n" ++ infoLog
return theShader return theShader
bufferOffset :: Integral a => a -> Ptr b bufferOffset :: Integral a => a -> Ptr b
+1 -1
View File
@@ -10,7 +10,7 @@ tToRender t = map Render3x3 $ polyToTris $ zip ps3 coords3
where where
ps = _tilePoly t ps = _tilePoly t
coords = map (calcTexCoord (_tileCenter t) (_tileX t) (_tileY t)) ps coords = map (calcTexCoord (_tileCenter t) (_tileX t) (_tileY t)) ps
ps3 = map (mkTrip 0.05) ps ps3 = map (mkTrip 0) ps
coords3 = map (mkTrip (_tileZ t)) coords coords3 = map (mkTrip (_tileZ t)) coords
mkTrip :: c -> (a,b) -> (a,b,c) mkTrip :: c -> (a,b) -> (a,b,c)