diff options
author | Joe Crayne <joe@jerkface.net> | 2019-04-11 20:07:27 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-04-11 20:07:27 -0400 |
commit | 5b8cf0fcb93c5d6e288e4426189a1564e318927a (patch) | |
tree | 2655c83d67075942557a544fca414f144ddefda2 /hello_obj2.lc | |
parent | 318f170b71923849c6f93af83da85eb974f96332 (diff) |
Modified version of HelloOBJ that renders transparent grid plane.
Diffstat (limited to 'hello_obj2.lc')
-rw-r--r-- | hello_obj2.lc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/hello_obj2.lc b/hello_obj2.lc new file mode 100644 index 0000000..a6c40ff --- /dev/null +++ b/hello_obj2.lc | |||
@@ -0,0 +1,47 @@ | |||
1 | coordmap (time::Float) (p::Vec 4 Float) | ||
2 | = perspective 0.1 100 30 1 | ||
3 | *. lookat (V3 0 0 5) (V3 0 0 0) (V3 0 1 0) | ||
4 | *. rotMatrixX time | ||
5 | *. rotMatrixZ time | ||
6 | *. p | ||
7 | |||
8 | blendplane = -- NoBlending -- BlendLogicOp Xor | ||
9 | Blend (FuncAdd,FuncAdd) | ||
10 | ((OneBF,SrcAlpha),(DstAlpha,DstAlpha)) | ||
11 | (V4 0 0 0 0) | ||
12 | |||
13 | makeFrame (time :: Float) | ||
14 | (color :: Vec 4 Float) | ||
15 | (texture :: Texture) | ||
16 | (prims :: PrimitiveStream Triangle (Vec 4 Float, Vec 3 Float, Vec 3 Float)) | ||
17 | (plane :: PrimitiveStream Triangle ((Vec 4 Float))) | ||
18 | |||
19 | = imageFrame (emptyDepthImage 1, emptyColorImage (V4 0 0 0.4 1)) | ||
20 | `overlay` | ||
21 | prims | ||
22 | & mapPrimitives (\(p,n,uvw) -> ( coordmap time p, V2 uvw%x (1 - uvw%y) )) | ||
23 | & rasterizePrimitives (TriangleCtx CullBack PolygonFill NoOffset LastVertex) ((Smooth)) | ||
24 | & mapFragments (\((uv)) -> ((color * texture2D (Sampler PointFilter MirroredRepeat texture) uv ))) | ||
25 | & accumulateWith (DepthOp Less True, ColorOp NoBlending (V4 True True True True)) | ||
26 | `overlay` | ||
27 | plane | ||
28 | & mapPrimitives (\((p)) -> (coordmap time p, p%xy )) | ||
29 | & rasterizePrimitives (TriangleCtx CullNone PolygonFill NoOffset LastVertex) ((Smooth)) | ||
30 | -- & mapFragments (\((uv)) -> ((texture2D (Sampler PointFilter MirroredRepeat texture) uv ))) | ||
31 | -- & mapFragments (\((uv)) -> ((V4 uv%x uv%y 0 1))) -- ((rgb 1 0 0))) | ||
32 | & mapFragments (\((uv)) -> let k=cos(g *! (8 * pi / 4)) | ||
33 | g=uv -- *! (1 + sqrt (abs (t%x * t%y))) | ||
34 | t=normalize uv | ||
35 | c=k -- *! ( t%x * t%y) -- /! ((k%x + k%y) / k%x) | ||
36 | r = V4 1 1 1 0 *! smoothstepS 0.99 1.0 (max c%x c%y) | ||
37 | in ((r + V4 0 0 0 (0.8)))) | ||
38 | & accumulateWith (DepthOp Less True, ColorOp blendplane (V4 True True True True)) | ||
39 | |||
40 | |||
41 | main = renderFrame $ | ||
42 | makeFrame (Uniform "time") | ||
43 | (Uniform "diffuseColor") | ||
44 | (Texture2DSlot "diffuseTexture") | ||
45 | (fetch "objects" (Attribute "position", Attribute "normal", Attribute "uvw")) | ||
46 | (fetch "plane" ((Attribute "position"))) | ||
47 | |||