diff options
-rw-r--r-- | camera.c | 1 | ||||
-rw-r--r-- | graphics.h | 2 | ||||
-rw-r--r-- | render.c | 4 | ||||
-rw-r--r-- | shadeop.c | 6 | ||||
-rw-r--r-- | vertex.c | 22 |
5 files changed, 16 insertions, 19 deletions
@@ -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 @@ -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); @@ -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 */ @@ -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) @@ -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); } } |