From 47b672e259d92011d765ffe26f782af087d0adea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Mon, 17 Jun 2019 00:20:43 +0200 Subject: [PATCH] Change function API --- programs/hqOffline.c | 12 ++++++------ programs/modelViewer.c | 21 ++++++--------------- small3dlib.h | 14 +++++--------- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/programs/hqOffline.c b/programs/hqOffline.c index a9c42e9..861f779 100644 --- a/programs/hqOffline.c +++ b/programs/hqOffline.c @@ -150,13 +150,13 @@ void drawPixel(S3L_PixelInfo *p) S3L_Vec4 reflected; S3L_Unit blend = 0; - position.x = S3L_interpolateBarycentric(v0.x,v1.x,v2.x,p->barycentric[0],p->barycentric[1],p->barycentric[2]); - position.y = S3L_interpolateBarycentric(v0.y,v1.y,v2.y,p->barycentric[0],p->barycentric[1],p->barycentric[2]); - position.z = S3L_interpolateBarycentric(v0.z,v1.z,v2.z,p->barycentric[0],p->barycentric[1],p->barycentric[2]); + position.x = S3L_interpolateBarycentric(v0.x,v1.x,v2.x,p->barycentric); + position.y = S3L_interpolateBarycentric(v0.y,v1.y,v2.y,p->barycentric); + position.z = S3L_interpolateBarycentric(v0.z,v1.z,v2.z,p->barycentric); - normal.x = S3L_interpolateBarycentric(n0.x,n1.x,n2.x,p->barycentric[0],p->barycentric[1],p->barycentric[2]); - normal.y = S3L_interpolateBarycentric(n0.y,n1.y,n2.y,p->barycentric[0],p->barycentric[1],p->barycentric[2]); - normal.z = S3L_interpolateBarycentric(n0.z,n1.z,n2.z,p->barycentric[0],p->barycentric[1],p->barycentric[2]); + normal.x = S3L_interpolateBarycentric(n0.x,n1.x,n2.x,p->barycentric); + normal.y = S3L_interpolateBarycentric(n0.y,n1.y,n2.y,p->barycentric); + normal.z = S3L_interpolateBarycentric(n0.z,n1.z,n2.z,p->barycentric); toCameraDirection.x = scene.camera.transform.translation.x - position.x; toCameraDirection.y = scene.camera.transform.translation.y - position.y; diff --git a/programs/modelViewer.c b/programs/modelViewer.c index 76cbbc9..6ca2fba 100644 --- a/programs/modelViewer.c +++ b/programs/modelViewer.c @@ -253,11 +253,8 @@ void drawPixel(S3L_PixelInfo *p) { S3L_Unit uv[2]; - uv[0] = S3L_interpolateBarycentric(uv0[0],uv1[0],uv2[0], - p->barycentric[0], p->barycentric[1], p->barycentric[2]); - - uv[1] = S3L_interpolateBarycentric(uv0[1],uv1[1],uv2[1], - p->barycentric[0], p->barycentric[1], p->barycentric[2]); + uv[0] = S3L_interpolateBarycentric(uv0[0],uv1[0],uv2[0],p->barycentric); + uv[1] = S3L_interpolateBarycentric(uv0[1],uv1[1],uv2[1],p->barycentric); sampleTexture(uv[0] / 4,uv[1] / 4,&r,&g,&b); @@ -280,14 +277,9 @@ void drawPixel(S3L_PixelInfo *p) { S3L_Vec4 n; - n.x = S3L_interpolateBarycentric(n0.x,n1.x,n2.x, - p->barycentric[0], p->barycentric[1], p->barycentric[2]); - - n.y = S3L_interpolateBarycentric(n0.y,n1.y,n2.y, - p->barycentric[0], p->barycentric[1], p->barycentric[2]); - - n.z = S3L_interpolateBarycentric(n0.z,n1.z,n2.z, - p->barycentric[0], p->barycentric[1], p->barycentric[2]); + n.x = S3L_interpolateBarycentric(n0.x,n1.x,n2.x,p->barycentric); + n.y = S3L_interpolateBarycentric(n0.y,n1.y,n2.y,p->barycentric); + n.z = S3L_interpolateBarycentric(n0.z,n1.z,n2.z,p->barycentric); S3L_normalizeVec3(&n); @@ -327,8 +319,7 @@ void drawPixel(S3L_PixelInfo *p) if (light) { - int16_t l = S3L_interpolateBarycentric(l0,l1,l2, - p->barycentric[0], p->barycentric[1], p->barycentric[2]); + int16_t l = S3L_interpolateBarycentric(l0,l1,l2,p->barycentric); r = S3L_clamp((((int16_t) r) * l) / S3L_FRACTIONS_PER_UNIT,0,255); g = S3L_clamp((((int16_t) g) * l) / S3L_FRACTIONS_PER_UNIT,0,255); diff --git a/small3dlib.h b/small3dlib.h index 3293214..cedd772 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -556,9 +556,7 @@ static inline S3L_Unit S3L_interpolateBarycentric( S3L_Unit value0, S3L_Unit value1, S3L_Unit value2, - S3L_Unit barycentric0, - S3L_Unit barycentric1, - S3L_Unit barycentric2); + S3L_Unit barycentric[3]); static inline void S3L_mapProjectionPlaneToScreen( S3L_Vec4 point, @@ -1517,15 +1515,13 @@ static inline S3L_Unit S3L_interpolateBarycentric( S3L_Unit value0, S3L_Unit value1, S3L_Unit value2, - S3L_Unit barycentric0, - S3L_Unit barycentric1, - S3L_Unit barycentric2) + S3L_Unit barycentric[3]) { return ( - (value0 * barycentric0) + - (value1 * barycentric1) + - (value2 * barycentric2) + (value0 * barycentric[0]) + + (value1 * barycentric[1]) + + (value2 * barycentric[2]) ) / S3L_FRACTIONS_PER_UNIT; }