summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-04-30 00:04:53 -0400
committerJoe Crayne <joe@jerkface.net>2019-04-30 00:04:53 -0400
commit2052faa3ffb11490e41972d65df54ae0bbef8b9c (patch)
tree6b987c5fd115af2b24c85bc2c373cda17948b4fd
parentc9c0db44f79c5ad13c0937d8e36fa828447f9585 (diff)
skybox shader code.
-rw-r--r--MeshSketch.hs2
-rw-r--r--hello_obj2.lc12
2 files changed, 13 insertions, 1 deletions
diff --git a/MeshSketch.hs b/MeshSketch.hs
index 7f01d4d..70493bd 100644
--- a/MeshSketch.hs
+++ b/MeshSketch.hs
@@ -160,7 +160,7 @@ deg30 = pi/6
160 160
161whirlingCamera :: State -> Animation 161whirlingCamera :: State -> Animation
162whirlingCamera st = Animation $ \_ t -> do 162whirlingCamera st = Animation $ \_ t -> do
163 let tf = realToFrac (t/10.0) :: Float 163 let tf = realToFrac t :: Float
164 rot = rotMatrixZ (-tf) <> rotMatrixX (-tf) 164 rot = rotMatrixZ (-tf) <> rotMatrixX (-tf)
165 modifyIORef (stCamera st) $ \cam -> cam 165 modifyIORef (stCamera st) $ \cam -> cam
166 { camUp = rot #> fromList [0,1,0] 166 { camUp = rot #> fromList [0,1,0]
diff --git a/hello_obj2.lc b/hello_obj2.lc
index 52d4a52..db28333 100644
--- a/hello_obj2.lc
+++ b/hello_obj2.lc
@@ -7,6 +7,10 @@ blendplane = -- NoBlending -- BlendLogicOp Xor
7 ((OneBF,SrcAlpha),(DstAlpha,DstAlpha)) 7 ((OneBF,SrcAlpha),(DstAlpha,DstAlpha))
8 (V4 0 0 0 0) 8 (V4 0 0 0 0)
9 9
10point :: Vec 3 Float -> Vec 4 Float
11point p = V4 p%x p%y p%z 1
12
13
10makeFrame (cubemap :: Texture) 14makeFrame (cubemap :: Texture)
11 (skybox :: PrimitiveStream Triangle ((Vec 3 Float))) 15 (skybox :: PrimitiveStream Triangle ((Vec 3 Float)))
12 (cameraPosition :: Vec 3 Float) 16 (cameraPosition :: Vec 3 Float)
@@ -18,6 +22,14 @@ makeFrame (cubemap :: Texture)
18 22
19 = imageFrame (emptyDepthImage 1, emptyColorImage (V4 0 0 0.4 1)) 23 = imageFrame (emptyDepthImage 1, emptyColorImage (V4 0 0 0.4 1))
20 `overlay` 24 `overlay`
25 skybox
26 & mapPrimitives (\((p)) -> let texcoord = V3 p%x (p%y) (p%z)
27 p' = cam *. point (p + cameraPosition)
28 in (p', texcoord))
29 & rasterizePrimitives (TriangleCtx CullNone PolygonFill NoOffset LastVertex) ((Smooth))
30 & mapFragments (\((d)) -> ((texture2D (Sampler PointFilter MirroredRepeat cubemap) d%xy )))
31 & accumulateWith (DepthOp Always False, ColorOp NoBlending (V4 True True True True))
32 `overlay`
21 prims 33 prims
22 & mapPrimitives (\(p,n,uvw) -> ( coordmap cam p, V2 uvw%x (1 - uvw%y) )) 34 & mapPrimitives (\(p,n,uvw) -> ( coordmap cam p, V2 uvw%x (1 - uvw%y) ))
23 & rasterizePrimitives (TriangleCtx CullBack PolygonFill NoOffset LastVertex) ((Smooth)) 35 & rasterizePrimitives (TriangleCtx CullBack PolygonFill NoOffset LastVertex) ((Smooth))