shithub: libgraphics

Download patch

ref: 0abc1ca44de64a689f5877e4b7e194c43a1ddcd8
parent: b6a336aff26fbc94e7803719a8aeb8fa29eddb9b
author: rodri <rgl@antares-labs.eu>
date: Wed Oct 2 16:46:39 EDT 2024

shorten Shadertab prop names. add quaternion sandwich product utils.

--- a/graphics.h
+++ b/graphics.h
@@ -233,9 +233,9 @@
 struct Shadertab
 {
 	char *name;
-	Point3 (*vshader)(Shaderparams*);	/* vertex shader */
-	Color (*fshader)(Shaderparams*);	/* fragment shader */
-	Vertexattrs;				/* uniforms */
+	Point3 (*vs)(Shaderparams*);	/* vertex shader */
+	Color (*fs)(Shaderparams*);	/* fragment shader */
+	Vertexattrs;			/* uniforms */
 };
 
 struct Rendertime
@@ -446,6 +446,8 @@
 Point3 minpt3(Point3, Point3);
 Point3 maxpt3(Point3, Point3);
 int eqpt3(Point3, Point3);
+Quaternion qsandwich(Quaternion, Quaternion);
+Point3 qsandwichpt3(Quaternion, Point3);
 Memimage *rgba(ulong);
 Memimage *dupmemimage(Memimage*);
 
--- a/render.c
+++ b/render.c
@@ -207,7 +207,7 @@
 
 		fsp.v = &prim->v[0];
 		fsp.p = p;
-		c = params->stab->fshader(&fsp);
+		c = params->stab->fs(&fsp);
 		if(c.a == 0)			/* discard non-colors */
 			break;
 		if(ropts & RODepth)
@@ -273,7 +273,7 @@
 			lerpvertex(fsp.v, &prim->v[0], &prim->v[1], perc);
 
 			fsp.p = p;
-			c = params->stab->fshader(&fsp);
+			c = params->stab->fs(&fsp);
 			if(c.a == 0)			/* discard non-colors */
 				goto discard;
 			if(ropts & RODepth)
@@ -327,7 +327,7 @@
 			berpvertex(fsp.v, &prim->v[0], &prim->v[1], &prim->v[2], bc);
 
 			fsp.p = p;
-			c = params->stab->fshader(&fsp);
+			c = params->stab->fs(&fsp);
 			if(c.a == 0)			/* discard non-colors */
 				continue;
 			if(ropts & RODepth)
@@ -482,7 +482,7 @@
 
 				vsp.v = &p->v[0];
 				vsp.idx = 0;
-				p->v[0].p = params->stab->vshader(&vsp);
+				p->v[0].p = params->stab->vs(&vsp);
 
 				if(!isvisible(p->v[0].p))
 					break;
@@ -517,7 +517,7 @@
 
 					vsp.v = &p->v[i];
 					vsp.idx = i;
-					p->v[i].p = params->stab->vshader(&vsp);
+					p->v[i].p = params->stab->vs(&vsp);
 				}
 
 				if(!isvisible(p->v[0].p) || !isvisible(p->v[1].p)){
@@ -563,7 +563,7 @@
 
 					vsp.v = &p->v[i];
 					vsp.idx = i;
-					p->v[i].p = params->stab->vshader(&vsp);
+					p->v[i].p = params->stab->vs(&vsp);
 				}
 
 				if(!isvisible(p->v[0].p) || !isvisible(p->v[1].p) || !isvisible(p->v[2].p)){
--- a/util.c
+++ b/util.c
@@ -91,6 +91,21 @@
 	return vec3len(subpt3(a, b)) < ε2;
 }
 
+Quaternion
+qsandwich(Quaternion q, Quaternion p)
+{
+	return mulq(mulq(q, p), invq(q));
+}
+
+Point3
+qsandwichpt3(Quaternion q, Point3 p)
+{
+	Quaternion r;
+
+	r = qsandwich(q, Quatvec(0, p));
+	return Pt3(r.i, r.j, r.k, p.w);
+}
+
 void
 memsetf(void *dp, float v, usize len)
 {