From 23b6132d75675d71e98ef8cc61aa7c0c04c78179 Mon Sep 17 00:00:00 2001 From: rodri Date: Sat, 16 Dec 2023 21:19:17 +0000 Subject: added a toon shader. --- main.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index c4a5535..8ce7131 100644 --- a/main.c +++ b/main.c @@ -394,7 +394,7 @@ vertshader(VSparams *sp) } Memimage * -fragshader(FSparams *sp) +gouraudshader(FSparams *sp) { double intens; @@ -409,6 +409,23 @@ fragshader(FSparams *sp) 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 @@ render(void) uvlong t0, t1; t0 = nanosec(); - shade(fb, vertshader, fragshader); + shade(fb, vertshader, toonshader); t1 = nanosec(); fprint(2, "shader took %lludns\n", t1-t0); } -- cgit v1.2.3