summaryrefslogtreecommitdiff
path: root/hello_obj2.lc
blob: ebee807384c69b4b207e9abd7f49489c63820cc5 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
deg30 = 0.5235987755982988 -- pi/6

coordmap (time::Float) (p::Vec 4 Float)
    = perspective 0.1 -- near plane
                  100 -- far plane
                deg30 -- y fov radians
                    1 -- aspect ratio w/h
                      *. lookat (V3 0 0 10) -- camera position
                                (V3 0 0 0)  -- target position
                                (V3 0 1 0)  -- upward direction
                      *. rotMatrixX time -- time = radians
                      *. rotMatrixZ time -- time = radians
                      *. p

blendplane = -- NoBlending -- BlendLogicOp Xor
    Blend (FuncAdd,FuncAdd)
          ((OneBF,SrcAlpha),(DstAlpha,DstAlpha))
          (V4 0 0 0 0)

makeFrame (time :: Float)
          (color :: Vec 4 Float)
          (texture :: Texture)
          (prims :: PrimitiveStream Triangle (Vec 4 Float, Vec 3 Float, Vec 3 Float))
          (plane :: PrimitiveStream Triangle ((Vec 4 Float)))

    = imageFrame (emptyDepthImage 1, emptyColorImage (V4 0 0 0.4 1))
  `overlay`
      prims
    & mapPrimitives (\(p,n,uvw) -> ( coordmap 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))
  `overlay`
      plane
    & mapPrimitives (\((p)) -> (coordmap time p, p%xy ))
    & rasterizePrimitives (TriangleCtx CullNone PolygonFill NoOffset LastVertex) ((Smooth))
    -- & mapFragments (\((uv)) -> ((texture2D (Sampler PointFilter MirroredRepeat texture) uv )))
    -- & mapFragments (\((uv)) -> ((V4 uv%x uv%y 0 1))) -- ((rgb 1 0 0)))
    & mapFragments (\((uv)) -> let k=cos(g *! (8 * pi / 4))
                                   g=uv -- *! (1 + sqrt (abs (t%x * t%y)))
                                   t=normalize uv
                                   c=k -- *! ( t%x * t%y) -- /! ((k%x + k%y) / k%x)
                                   r = V4 1 1 1 0 *! smoothstepS 0.99 1.0 (max c%x c%y)
                                in ((r + V4 0 0 0 (0.8))))
    & accumulateWith (DepthOp Less True, ColorOp blendplane (V4 True True True True))


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