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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# semblance
Semblance wants to be a shading language.
The idea is for it to have a translator that turns semblance shaders
into C that can be used with [libgraphics][1], and later turn it into a
VM that runs in [renderfs][2].
It's largely influenced by the [RSL][3] and [GLSL][4] languages.
## Syntax
- declare and use custom structs
- new types
vector → Point3 (x,y,z,0)
point → Point3 (x,y,z,w)
point2 → Point2 (x,y,w)
pointN → PointN (x,y,[w|z,w]) | N ∈ {2,3} ???
normal → Point3 (x,y,z,0) | {x,y,z} ∈ [0,1]
color → Color
matrix → Matrix[23] ???
quat → Quaternion
- new operators
Matrix3 m, n;
Point3 a, b;
double s;
b = b * a; /* b = modulatept3(a, b); */
b = b * s; /* b = mulpt3(b, s); */
b = b * m; /* xform3(b, m); */
b = b × a; /* b = crossvec3(b, a); */
b = b · a; /* b = dotvec3(b, a); */
m = m * n; /* mulm3(m, n); */
Matrix3 m2:
m2 = m * n; /* identity3(m2); mulm3(m2, m); mulm3(m2, n); */
/* alt.: memmove(m2, m, 4*4*sizeof(double)); mulm3(m2, n); */
- function polymorphism
Point3 a, b;
double c, d;
a = lerp(a, b, 0.4); /* lerp3(2); */
c = lerp(c, d, 0.1); /* flerp(2); */
Texture *tex;
Cubemap *cm;
Point3 dir;
Point2 uv;
Color c;
c = sample(tex, uv, nearest); /* sampletexture(2) */
c = sample(cm, dir, bilinear); /* samplecubemap(2) */
int a, b;
double c, d;
Point3 p0, p1;
a = min(a, b);
c = min(c, d);
p0 = min(p0, p1); /* component-wise */
- stage-dependent shader parameters
- vertex
| in shader | in libgraphics |
+--------------------------------+
position → sp->v->p
normal → sp->v->n
color → sp->v->c
uv → sp->v->uv
material → sp->v->mtl
tangent → sp->v->tangent
<attr> → sp->v->attrs["<attr>"]
- fragment
| in shader | in libgraphics |
+--------------------------------+
position → sp->v.p
color → sp->v.c
<attr> → sp->v.attrs["<attr>"]
- swizzles
Point3 p;
Color c;
c.rgba = p.xyzw;
c.rgb = p.xyz;
p.zyx = c.rgb;
- builtins
In the following cases the absent parameters are replaced by:
Entity* → sp->su->entity
Camera* → sp->su->camera
Framebuf* → sp->su->fb
when translated for libgraphics.
Point3 model2world(Point3) /* Point3 model2world(Entity*, Point3); */
Point3 world2vcs(Point3) /* Point3 world2vcs(Camera*, Point3); */
Point3 vcs2clip(Point3); /* Point3 vcs2clip(Camera*, Point3); */
Point3 world2clip(Point3); /* Point3 world2clip(Camera*, Point3); */
Point3 clip2ndc(Point3); /* Point3 clip2ndc(Point3); */
Point3 ndc2viewport(Point3); /* Point3 ndc2viewport(Framebuf*, Point3); */
Point3 viewport2ndc(Point3); /* Point3 viewport2ndc(Framebuf*, Point3); */
Point3 ndc2vcs(Point3); /* Point3 ndc2vcs(Camera*, Point3); */
Point3 viewport2vcs(Point3); /* Point3 viewport2vcs(Camera*, Point3); */
Point3 vcs2world(Point3); /* Point3 vcs2world(Camera*, Point3); */
Point3 viewport2world(Point3); /* Point3 viewport2world(Camera*, Point3); */
Point3 world2model(Point3); /* Point3 world2model(Entity*, Point3); */
## References
[1]: https://shithub.us/rodri/libgraphics
[2]: https://shithub.us/rodri/renderfs
[3]: https://renderman.pixar.com/resources/RenderMan_20/shadingLanguage.html
[4]: https://www.khronos.org/files/opengles_shading_language.pdf
|