diff options
author | rodri <rgl@antares-labs.eu> | 2023-12-16 21:19:17 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2023-12-16 21:19:17 +0000 |
commit | 23b6132d75675d71e98ef8cc61aa7c0c04c78179 (patch) | |
tree | 091562f08d40cf1dcd88c2f854eaecb87c974906 | |
parent | 79a8452ad57167a94d3be991a666b8f96d6fb5b4 (diff) | |
download | tinyrend-23b6132d75675d71e98ef8cc61aa7c0c04c78179.tar.gz tinyrend-23b6132d75675d71e98ef8cc61aa7c0c04c78179.tar.bz2 tinyrend-23b6132d75675d71e98ef8cc61aa7c0c04c78179.zip |
added a toon shader.
-rw-r--r-- | main.c | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -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); } |