ref: 11087295a24b0a8d08897824c7ee9676026fa159
parent: af0338b7ba4d9c6011caaf10f4fd363da4651a42
author: rodri <[email protected]>
date: Sat Aug 31 10:42:15 EDT 2024
omit references section. add a very rough example.
--- a/readme.md
+++ b/readme.md
@@ -104,7 +104,62 @@
Point3 viewport2world(Point3); /* Point3 viewport2world(Camera*, Point3); */
Point3 world2model(Point3); /* Point3 world2model(Entity*, Point3); */
-## References
+## Examples
+
+in libgraphics:
+
+ Point3
+ phongvshader(VSparams *sp)
+ {
+ Point3 pos;
+ Color a, d, s;
+ double ss;
+
+ sp->v->n = model2world(sp->su->entity, sp->v->n);
+ sp->v->p = model2world(sp->su->entity, sp->v->p);
+ pos = sp->v->p;
+ addvattr(sp->v, "pos", VAPoint, &pos);
+ if(sp->v->mtl != nil && sp->v->mtl->normalmap != nil && sp->v->uv.w != 0){
+ sp->v->tangent = model2world(sp->su->entity, sp->v->tangent);
+ addvattr(sp->v, "tangent", VAPoint, &sp->v->tangent);
+ }
+ if(sp->v->mtl != nil){
+ a = sp->v->mtl->ambient;
+ d = sp->v->mtl->diffuse;
+ s = sp->v->mtl->specular;
+ ss = sp->v->mtl->shininess;
+ addvattr(sp->v, "ambient", VAPoint, &a);
+ addvattr(sp->v, "diffuse", VAPoint, &d);
+ addvattr(sp->v, "specular", VAPoint, &s);
+ addvattr(sp->v, "shininess", VANumber, &ss);
+ }
+ return world2clip(sp->su->camera, pos);
+ }
+
+in semblance:
+
+ out point pos;
+ out vector tangent;
+ out color ambient;
+ out color diffuse;
+ out color specular;
+ out double shininess;
+
+ vs phong() {
+ normal = model2world(normal);
+ position = model2world(position);
+ pos = position;
+ if(material != nil){
+ if(material->normalmap && uv.w != 0)
+ tangent = model2world(tangent);
+ ambient = material.ambient;
+ diffuse = material.diffuse;
+ specular = material.specular;
+ shininess = material.shininess;
+ }
+ return world2clip(pos);
+ }
+
[1]: https://shithub.us/rodri/libgraphics
[2]: https://shithub.us/rodri/renderfs