From af0338b7ba4d9c6011caaf10f4fd363da4651a42 Mon Sep 17 00:00:00 2001 From: rodri Date: Fri, 30 Aug 2024 20:31:32 +0000 Subject: initial dump of ideas. --- readme.md | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 readme.md (limited to 'readme.md') diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..0bec29f --- /dev/null +++ b/readme.md @@ -0,0 +1,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 + → sp->v->attrs[""] + - fragment + | in shader | in libgraphics | + +--------------------------------+ + position → sp->v.p + color → sp->v.c + → sp->v.attrs[""] + - 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 -- cgit v1.2.3