From 764afe37e2438498bcace9de56b9618565b7cd34 Mon Sep 17 00:00:00 2001 From: rodri Date: Thu, 21 Mar 2024 11:58:10 +0000 Subject: use the new libgeometry berp routines. add a frame counter to the camstats. --- camera.c | 1 + graphics.h | 2 ++ render.c | 4 ++-- shadeop.c | 6 ++++++ vertex.c | 22 +++++----------------- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/camera.c b/camera.c index 82d0b0b..eb6f181 100644 --- a/camera.c +++ b/camera.c @@ -17,6 +17,7 @@ updatestats(Camera *c, uvlong v) c->stats.avg = c->stats.acc/c->stats.n; c->stats.min = v < c->stats.min || c->stats.n == 1? v: c->stats.min; c->stats.max = v > c->stats.max || c->stats.n == 1? v: c->stats.max; + c->stats.nframes++; } static void diff --git a/graphics.h b/graphics.h index 94ce2ea..af8cdd0 100644 --- a/graphics.h +++ b/graphics.h @@ -210,6 +210,7 @@ struct Camera struct { uvlong min, avg, max, acc, n, v; + uvlong nframes; } stats; }; @@ -256,6 +257,7 @@ double fmax(double, double); Memimage *rgb(ulong); /* shadeop */ +double sign(double); double step(double, double); double smoothstep(double, double, double); diff --git a/render.c b/render.c index aba3d45..d88f6c3 100644 --- a/render.c +++ b/render.c @@ -323,7 +323,7 @@ rasterize(SUparams *params, Triangle t) if(bc.x < 0 || bc.y < 0 || bc.z < 0) continue; - z = t[0].p.z*bc.x + t[1].p.z*bc.y + t[2].p.z*bc.z; + z = fberp(t[0].p.z, t[1].p.z, t[2].p.z, bc); depth = fclamp(z, 0, 1); lock(¶ms->fb->zbuflk); if(depth <= params->fb->zbuf[p.x + p.y*Dx(params->fb->r)]){ @@ -334,7 +334,7 @@ rasterize(SUparams *params, Triangle t) unlock(¶ms->fb->zbuflk); /* interpolate z⁻¹ and get actual z */ - z = t[0].p.w*bc.x + t[1].p.w*bc.y + t[2].p.w*bc.z; + z = fberp(t[0].p.w, t[1].p.w, t[2].p.w, bc); z = 1.0/(z < 1e-5? 1e-5: z); /* perspective-correct attribute interpolation */ diff --git a/shadeop.c b/shadeop.c index c1484c3..c6080e3 100644 --- a/shadeop.c +++ b/shadeop.c @@ -8,6 +8,12 @@ #include "graphics.h" #include "internal.h" +double +sign(double n) +{ + return n == 0? 0: n < 0? -1: 1; +} + double step(double edge, double n) { diff --git a/vertex.c b/vertex.c index d18d9ac..bc7759f 100644 --- a/vertex.c +++ b/vertex.c @@ -76,18 +76,9 @@ berpvertex(Vertex *v, Vertex *v0, Vertex *v1, Vertex *v2, Point3 bc) Vertexattr va; int i; - v->n = addpt3(addpt3( - mulpt3(v0->n, bc.x), - mulpt3(v1->n, bc.y)), - mulpt3(v2->n, bc.z)); - v->c = addpt3(addpt3( - mulpt3(v0->c, bc.x), - mulpt3(v1->c, bc.y)), - mulpt3(v2->c, bc.z)); - v->uv = addpt2(addpt2( - mulpt2(v0->uv, bc.x), - mulpt2(v1->uv, bc.y)), - mulpt2(v2->uv, bc.z)); + v->n = berp3(v0->n, v1->n, v2->n, bc); + v->c = berp3(v0->c, v1->c, v2->c, bc); + v->uv = berp2(v0->uv, v1->uv, v2->uv, bc); v->mtl = v0->mtl != nil? v0->mtl: v1->mtl != nil? v1->mtl: v2->mtl; v->attrs = nil; v->nattrs = 0; @@ -95,12 +86,9 @@ berpvertex(Vertex *v, Vertex *v0, Vertex *v1, Vertex *v2, Point3 bc) va.id = v0->attrs[i].id; va.type = v0->attrs[i].type; if(va.type == VAPoint) - va.p = addpt3(addpt3( - mulpt3(v0->attrs[i].p, bc.x), - mulpt3(v1->attrs[i].p, bc.y)), - mulpt3(v2->attrs[i].p, bc.z)); + va.p = berp3(v0->attrs[i].p, v1->attrs[i].p, v2->attrs[i].p, bc); else - va.n = dotvec3(Vec3(v0->attrs[i].n, v1->attrs[i].n, v2->attrs[i].n), bc); + va.n = fberp(v0->attrs[i].n, v1->attrs[i].n, v2->attrs[i].n, bc); _addvattr(v, &va); } } -- cgit v1.2.3