X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Frasterize;a=blobdiff_plain;f=tri.h;h=3c028be33390cffea358d340eb6e4c5ae35e621f;hp=ce0977b5c7382d7d61867b4f463c99d641effda1;hb=3955aa40277c4b86a43b21e78d55d2fea7b643ce;hpb=95850b98f73ad7033af60a30e324e9c3cda55389 diff --git a/tri.h b/tri.h index ce0977b..3c028be 100644 --- a/tri.h +++ b/tri.h @@ -191,6 +191,19 @@ vec_t tri_normal2(tri_t t, scal_t b[3]) return vec_normalize(vec_interp(t.a.n, t.b.n, t.c.n, b)); } +/* + * Calculate an interpolated texture coordinate. + */ +INLINE_MAYBE +vec_t tri_tcoord(tri_t t, scal_t b[3]) +{ +#if PERSPECTIVE_FIX + return vec_tinterp(t.a.t, t.b.t, t.c.t, b); +#else + return vec_interp(t.a.t, t.b.t, t.c.t, b); +#endif +} + /* * Calculate an entirely new vertex within the triangle based on barycentric * coordinates. @@ -201,6 +214,7 @@ vert_t tri_interp(tri_t t, scal_t b[3]) vert_t v = vert_new(tri_point(t, b)); v.c = color_interp2(t.a.c, t.b.c, t.c.c, b); v.n = tri_normal2(t, b); + v.t = tri_tcoord(t, b); return v; }