summaryrefslogtreecommitdiff
path: root/hello_obj.lc
blob: baf0edd8c8d1c8c51f8339295b9377bb3855b23b (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
makeFrame (time :: Float)
          (color :: Vec 4 Float)
          (texture :: Texture)
          (prims :: PrimitiveStream Triangle (Vec 4 Float, Vec 3 Float, Vec 3 Float))

    = imageFrame (emptyDepthImage 1, emptyColorImage (V4 0 0 0.4 1))
  `overlay`
      prims
    & mapPrimitives (\(p,n,uvw) ->
        ( perspective 0.1 100 45 1
          *. lookat (V3 0 0 5) (V3 0 0 0) (V3 0 1 0)
          *. rotMatrixX time
          *. rotMatrixZ time
          *. p
        , V2 uvw%x (1 - uvw%y) ))
    & rasterizePrimitives (TriangleCtx CullBack PolygonFill NoOffset LastVertex) ((Smooth))
    & mapFragments (\((uv)) -> ((color * texture2D (Sampler PointFilter MirroredRepeat texture) uv )))
    & accumulateWith (DepthOp Less True, ColorOp NoBlending (V4 True True True True))

main = renderFrame $
   makeFrame (Uniform "time")
             (Uniform "diffuseColor")
             (Texture2DSlot "diffuseTexture")
             (fetch "objects" (Attribute "position", Attribute "normal", Attribute "uvw"))