summaryrefslogtreecommitdiff
path: root/testdata/editor-examples/RecursiveTexture.lc
blob: 69d5444774700da1b92db7c156a6512b263ab6d9 (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
clear = imageFrame (emptyDepthImage 1, emptyColorImage teal)

triangleRasterCtx = TriangleCtx CullNone PolygonFill NoOffset LastVertex
colorFragmentCtx = (DepthOp Less True, ColorOp NoBlending (V4 True True True True))

cubeVertexStream = fetch "stream4" (Attribute "position4" :: Vec 4 Float, Attribute "vertexUV" :: Vec 2 Float)
time = Uniform "Time" :: Float
rotMatrix = 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)

setAlpha v = v * V4 1.0 1 1 0 + V4 0 0 0 1

cube' res (n :: Float) fb =
       clear
   `overlay`
       cubeVertexStream
     & mapPrimitives (\(v, u) -> (rotMatrix *. scale 0.4 (rotMatrixX (n/10) *. v), u))
     & rasterizePrimitives triangleRasterCtx ((Smooth))
     & mapFragments (\((a)) -> ((setAlpha $ (a%yyyx *! 0.5 + texture2D sampler a) *! 0.7)))
     & accumulateWith colorFragmentCtx
  where
    sampler = Sampler LinearFilter MirroredRepeat $ Texture2D (V2 res res) (PrjImageColor fb)

main :: Output
main = ScreenOut $ snd $ iterate (\(n, f) -> (n+1, cube' 256 n f)) (0, clear) !! 15