shithub: tinyrend

Download patch

ref: 23b6132d75675d71e98ef8cc61aa7c0c04c78179
parent: 79a8452ad57167a94d3be991a666b8f96d6fb5b4
author: rodri <[email protected]>
date: Sat Dec 16 16:19:17 EST 2023

added a toon shader.

--- a/main.c
+++ b/main.c
@@ -394,7 +394,7 @@
 }
 
 Memimage *
-fragshader(FSparams *sp)
+gouraudshader(FSparams *sp)
 {
 	double intens;
 
@@ -409,6 +409,23 @@
 	return sp->frag;
 }
 
+Memimage *
+toonshader(FSparams *sp)
+{
+	double intens;
+
+	intens = sp->su->var_intensity[0]*sp->bc.x;
+	intens += sp->su->var_intensity[1]*sp->bc.y;
+	intens += sp->su->var_intensity[2]*sp->bc.z;
+	intens = intens > 0.85? 1: intens > 0.60? 0.80: intens > 0.45? 0.60: intens > 0.30? 0.45: intens > 0.15? 0.30: 0;
+	sp->cbuf[1] = 0;
+	sp->cbuf[2] = 155*intens;
+	sp->cbuf[3] = 255*intens;
+	memfillcolor(sp->frag, *(ulong*)sp->cbuf);
+
+	return sp->frag;
+}
+
 void
 rasterize(SUparams *params, Triangle3 st, Triangle2 tt, Memimage *frag)
 {
@@ -746,7 +763,7 @@
 	uvlong t0, t1;
 
 	t0 = nanosec();
-	shade(fb, vertshader, fragshader);
+	shade(fb, vertshader, toonshader);
 	t1 = nanosec();
 	fprint(2, "shader took %lludns\n", t1-t0);
 }