summaryrefslogtreecommitdiff
path: root/testdata/editor-examples/Tetrahedron.lc
blob: cc7902187237e05c946f19660d6077c8aa4ab18f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
tetrahedron =
    [ V3 0 0 0, V3 1 0 0, V3 0 1 0
    , V3 1 0 0, V3 0 1 0, V3 0 0 1
    , V3 0 1 0, V3 0 0 1, V3 0 0 0
    , V3 0 0 1, V3 0 0 0, V3 1 0 0
    ]

f x = (x + sin x + sin (1.1 * x)) `mod` 4 * 2

makeFrame (time :: Float)
          (vertexstream :: PrimitiveStream Triangle ((Vec 4 Float)))

    =         imageFrame (emptyDepthImage 1, emptyColorImage navy)
    `overlay` accumulablefragments
  where
    projmat = perspective 0.1 100.0 (30 * pi / 180) 1.0
          .*. lookat (V3 3.0 1.3 0.3) (V3 0.0 0.0 0.0) (V3 0.0 1.0 0.0)
          .*. rotMatrixY (pi / 24.0 * time)

    accumulablefragments
        = vertexstream
        & mapPrimitives (\((x)) -> (scale 0.5 (projmat *. x), x))
        & rasterizePrimitives (TriangleCtx CullNone PolygonFill NoOffset LastVertex) ((Smooth))
        & filterFragments (\((x)) -> True)
        & mapFragments (\((x)) -> (((rotMatrixZ time *. rotMatrixY time *. x) *! f time)))
        & accumulateWith (DepthOp Less True, ColorOp NoBlending (V4 True True True True))

main = renderFrame $
   makeFrame (Uniform "Time")
             tetrahedronStream

tetrahedronStream = fetchArrays ((map (\v -> V4 v%x v%y v%z 1) tetrahedron))