summaryrefslogtreecommitdiff
path: root/testdata/recursivetexture01.lc
blob: 913dd2185c9c1465fc2ab0b74202f7fcc0f9a3d8 (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
clear = imageFrame (DepthImage @1 1000, ColorImage @1 black)   -- ...

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

cubeVertexStream = fetch "stream4" Triangle (Attribute "position4" :: Vec 4 Float, Attribute "vertexUV" :: Vec 2 Float)

rotate' v = (Uniform "MVP" :: Mat 4 4 Float) *. v

setAlpha v = v * V4 1.0 1.0 1 0 + V4 0 0 0 1 --V4 v%x v%y v%z 1.0

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

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