shithub: tinyrend

Download patch

ref: 752d971d8ff5ffa2afc250830b60c07ceeaba336
parent: 5d50d34ac95d2a63113697047afee180e5bd1e6c
author: rodri <rgl@antares-labs.eu>
date: Thu Dec 21 11:01:34 EST 2023

experiments with sdfs and texture mapping.

--- a/main.c
+++ b/main.c
@@ -770,20 +770,6 @@
 	chanfree(donec);
 }
 
-Point3
-ivshader(VSparams *sp)
-{
-	Matrix3 M, V;
-
-	identity3(M);
-	identity3(V);
-	mulm3(M, rota);
-	mulm3(V, view);
-	mulm3(V, M);
-
-	return xform3(*sp->p, V);
-}
-
 Memimage *
 triangleshader(FSparams *sp)
 {
@@ -819,7 +805,7 @@
 circleshader(FSparams *sp)
 {
 	Point2 uv;
-	double r;
+	double r, d;
 	uchar cbuf[4];
 
 	uv = Pt2(sp->p.x,sp->p.y,1);
@@ -826,9 +812,10 @@
 	uv.x /= Dx(sp->su->fb->r);
 	uv.y /= Dy(sp->su->fb->r);
 //	r = 0.3;
-	r = 0.3*sin(sp->su->uni_time/1e9);
+	r = 0.3*fabs(sin(sp->su->uni_time/1e9));
+	d = vec2len(subpt2(uv, Vec2(0.5,0.5)));
 
-	if(vec2len(subpt2(uv, Vec2(0.5,0.5))) > r)
+	if(d > r + r*0.05 || d < r - r*0.05)
 		return nil;
 
 	cbuf[0] = 0xFF;
@@ -898,6 +885,33 @@
 	return sp->frag;
 }
 
+Point3
+ivshader(VSparams *sp)
+{
+	Matrix3 M, V, S = {
+		scale, 0, 0, 0,
+		0, scale, 0, 0,
+		0, 0, scale, 0,
+		0, 0, 0, 1,
+	};
+
+	identity3(M);
+	identity3(V);
+	mulm3(M, rota);
+	mulm3(M, S);
+	mulm3(V, view);
+	mulm3(V, M);
+
+	return xform3(*sp->p, V);
+}
+
+Memimage *
+identshader(FSparams *sp)
+{
+	memfillcolor(sp->frag, *(ulong*)sp->cbuf);
+	return sp->frag;
+}
+
 Shader shadertab[] = {
 	{ "triangle", ivshader, triangleshader },
 	{ "circle", ivshader, circleshader },
@@ -905,6 +919,7 @@
 	{ "sf", ivshader, sfshader },
 	{ "gouraud", vertshader, gouraudshader },
 	{ "toon", vertshader, toonshader },
+	{ "ident", vertshader, identshader },
 };
 Shader *
 getshader(char *name)
--- a/mdl/def.obj
+++ b/mdl/def.obj
@@ -2,5 +2,9 @@
 v 100 -100 0
 v -100 100 0
 v 100 100 0
-f 1 2 3
-f 4 3 2
+vt 0 0
+vt 1 0
+vt 0 1
+vt 1 1
+f 1/1 2/2 3/3
+f 4/4 3/3 2/2