ref: 764afe37e2438498bcace9de56b9618565b7cd34
parent: 2b19d1a580c0e281010fd200128081b8e3f4af7f
author: rodri <rgl@antares-labs.eu>
date: Thu Mar 21 07:58:10 EDT 2024
use the new libgeometry berp routines. add a frame counter to the camstats.
--- a/camera.c
+++ b/camera.c
@@ -17,6 +17,7 @@
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
--- a/graphics.h
+++ b/graphics.h
@@ -210,6 +210,7 @@
struct {
uvlong min, avg, max, acc, n, v;
+ uvlong nframes;
} stats;
};
@@ -256,6 +257,7 @@
Memimage *rgb(ulong);
/* shadeop */
+double sign(double);
double step(double, double);
double smoothstep(double, double, double);
--- a/render.c
+++ b/render.c
@@ -323,7 +323,7 @@
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 @@
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 */
--- a/shadeop.c
+++ b/shadeop.c
@@ -9,6 +9,12 @@
#include "internal.h"
double
+sign(double n)
+{
+ return n == 0? 0: n < 0? -1: 1;
+}
+
+double
step(double edge, double n)
{
if(n < edge)
--- a/vertex.c
+++ b/vertex.c
@@ -76,18 +76,9 @@
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 @@
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);
}
}