summaryrefslogtreecommitdiff
path: root/testdata/gfx05.lc
blob: 6d5c8401375b76822340e3f144721476da8481d8 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
renderWire fb = let
  modelViewProj = Uniform "MVP2" :: Mat 4 4 Float
  blendFun x = Blend x ((SrcAlpha,OneMinusSrcAlpha),(SrcAlpha,OneMinusSrcAlpha)) (V4 1.0 1.0 1.0 1.0)
  blend'' = blendFun (FuncAdd,FuncAdd)
  blend = Blend (FuncSubtract,FuncAdd) ((SrcColor,SrcColor),(SrcColor,OneMinusSrcAlpha)) (V4 0.0 1.0 0.0 0.0)
  blend' = NoBlending
  polyMode          = PolygonLine 20.0
  polyMode'         = PolygonFill
  polyMode''        = PolygonPoint (PointSize 10.0)
  cull = CullNone
  cull' = CullFront
  rasterCtx         = TriangleCtx cull polyMode NoOffset FirstVertex
  fragmentCtx       = accumulationContext (DepthOp Always False, ColorOp blend' (V4 True True False False))
  vertexShader v    = let v2 = v3FToV4F v in PrimMulMatVec modelViewProj v2
  vertexStream      = fetch "stream" Triangle (Attribute "position" :: Vec 3 Float)
  primitiveStream   = mapPrimitives vertexShader vertexStream
  fragmentStream    = rasterizePrimitives rasterCtx () primitiveStream
  fragmentShader' =  \v -> (V4 1.0 0.4 0.0 0.2)
  fragmentShader =  \v -> (V4 0.0 0.4 0.0 1.0)
  frame             = accumulate fragmentCtx  fragmentShader fragmentStream fb
  in frame

render fb = let
  modelViewProj = Uniform "MVP2" :: Mat 4 4 Float
  blendFun x = Blend x ((SrcAlpha,OneMinusSrcAlpha),(SrcAlpha,OneMinusSrcAlpha)) (V4 1.0 1.0 1.0 1.0)
  blend'' = blendFun (FuncAdd,FuncAdd)
  blend = Blend (Max,FuncAdd) ((SrcColor,SrcColor),(SrcColor,OneMinusSrcAlpha)) (V4 0.0 1.0 0.0 0.0)
  blend' = NoBlending
  polyMode          = PolygonLine 20.0
  polyMode'         = PolygonFill
  polyMode''        = PolygonPoint (PointSize 10.0)
  cull = CullNone
  cull' = CullFront
  rasterCtx         = TriangleCtx cull polyMode' NoOffset FirstVertex
  fragmentCtx       = accumulationContext (DepthOp Less False, ColorOp blend' (V4 True True False False))
  vertexShader v    = let v2 = v3FToV4F v in (PrimMulMatVec modelViewProj v2, v2)
  vertexStream      = fetch "stream" Triangle (Attribute "position" :: Vec 3 Float)
  primitiveStream   = mapPrimitives vertexShader vertexStream
  fragmentStream    = rasterizePrimitives rasterCtx Smooth primitiveStream
  fragmentShader' =  \v -> (V4 1.0 0.4 0.0 0.2)
  fragmentShader =  \v -> (PrimAdd v (V4 1.0 1.4 1.0 0.6))
  frame             = accumulate fragmentCtx  fragmentShader fragmentStream fb
  in frame

clear = FrameBuffer (depthImage1 1000.0,colorImage1 (V4 0.1 0 0.3 1))
sampler = Sampler LinearFilter MirroredRepeat $ Texture2D (V2 1024 768) (PrjImageColor $ renderWire clear)

render' fb = let
  modelViewProj = Uniform "MVP" :: Mat 4 4 Float
  blendFun x = Blend x ((SrcAlpha,OneMinusSrcAlpha),(SrcAlpha,OneMinusSrcAlpha)) (V4 1.0 1.0 1.0 1.0)
  blend'' = blendFun (FuncAdd,FuncAdd)
  blend = Blend (FuncAdd,FuncAdd) ((SrcAlpha,OneMinusSrcAlpha),(SrcAlpha,OneMinusSrcAlpha)) (V4 1.0 1.0 1.0 1.0)
  blend' = NoBlending
  polyMode          = PolygonLine 20.0
  polyMode'         = PolygonFill
  polyMode''        = PolygonPoint (PointSize 10.0)
  cull = CullNone
  cull' = CullFront
  rasterCtx         = TriangleCtx cull polyMode' NoOffset LastVertex
  fragmentCtx       = accumulationContext (DepthOp Less False, ColorOp blend (V4 True True True True))
  vertexShader' v    = let v2 = v3FToV4F v in  (PrimMulMatVec modelViewProj v2, v2) -- Flat
  vertexShader (v,u) =  (PrimMulMatVec modelViewProj v, u)
  vertexStream      = fetch "stream4" Triangle (Attribute "position4" :: Vec 4 Float, Attribute "vertexUV" :: Vec 2 Float)
  primitiveStream   = mapPrimitives vertexShader vertexStream
  fragmentStream    = rasterizePrimitives rasterCtx Smooth primitiveStream
  fragmentShader' =  \v -> (texture2D sampler v%xy *! 0.7)
  fragmentShader =  \v -> (PrimMul v (V4 1.0 1.4 1.0 0.6))
  frame             = accumulate fragmentCtx  fragmentShader' fragmentStream fb
  in frame

main = let
  bgColor = V4 0.5 0.0 0.4 1.0
  bgColor' = V4 0.2 0.2 0.4 1.0
  emptyFB = FrameBuffer (depthImage1 1000.0,colorImage1 bgColor)
  modelViewProj = Uniform "MVP" :: Mat 4 4 Float
  --fx a = render modelViewProj a
  --out = fx (fx emptyFB)
  --out = fx emptyFB
  --out = render modelViewProj emptyFB
  out = renderWire (render (render' emptyFB))
  in ScreenOut out