1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-24 21:09:57 +01:00

Change function API

This commit is contained in:
Miloslav Číž 2019-06-17 00:20:43 +02:00
parent 20c66f36d7
commit 47b672e259
3 changed files with 17 additions and 30 deletions

View file

@ -150,13 +150,13 @@ void drawPixel(S3L_PixelInfo *p)
S3L_Vec4 reflected; S3L_Vec4 reflected;
S3L_Unit blend = 0; S3L_Unit blend = 0;
position.x = S3L_interpolateBarycentric(v0.x,v1.x,v2.x,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[0],p->barycentric[1],p->barycentric[2]); position.y = S3L_interpolateBarycentric(v0.y,v1.y,v2.y,p->barycentric);
position.z = S3L_interpolateBarycentric(v0.z,v1.z,v2.z,p->barycentric[0],p->barycentric[1],p->barycentric[2]); 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.x = S3L_interpolateBarycentric(n0.x,n1.x,n2.x,p->barycentric);
normal.y = S3L_interpolateBarycentric(n0.y,n1.y,n2.y,p->barycentric[0],p->barycentric[1],p->barycentric[2]); normal.y = S3L_interpolateBarycentric(n0.y,n1.y,n2.y,p->barycentric);
normal.z = S3L_interpolateBarycentric(n0.z,n1.z,n2.z,p->barycentric[0],p->barycentric[1],p->barycentric[2]); normal.z = S3L_interpolateBarycentric(n0.z,n1.z,n2.z,p->barycentric);
toCameraDirection.x = scene.camera.transform.translation.x - position.x; toCameraDirection.x = scene.camera.transform.translation.x - position.x;
toCameraDirection.y = scene.camera.transform.translation.y - position.y; toCameraDirection.y = scene.camera.transform.translation.y - position.y;

View file

@ -253,11 +253,8 @@ void drawPixel(S3L_PixelInfo *p)
{ {
S3L_Unit uv[2]; S3L_Unit uv[2];
uv[0] = S3L_interpolateBarycentric(uv0[0],uv1[0],uv2[0], uv[0] = S3L_interpolateBarycentric(uv0[0],uv1[0],uv2[0],p->barycentric);
p->barycentric[0], p->barycentric[1], p->barycentric[2]); uv[1] = S3L_interpolateBarycentric(uv0[1],uv1[1],uv2[1],p->barycentric);
uv[1] = S3L_interpolateBarycentric(uv0[1],uv1[1],uv2[1],
p->barycentric[0], p->barycentric[1], p->barycentric[2]);
sampleTexture(uv[0] / 4,uv[1] / 4,&r,&g,&b); sampleTexture(uv[0] / 4,uv[1] / 4,&r,&g,&b);
@ -280,14 +277,9 @@ void drawPixel(S3L_PixelInfo *p)
{ {
S3L_Vec4 n; S3L_Vec4 n;
n.x = S3L_interpolateBarycentric(n0.x,n1.x,n2.x, n.x = S3L_interpolateBarycentric(n0.x,n1.x,n2.x,p->barycentric);
p->barycentric[0], p->barycentric[1], p->barycentric[2]); n.y = S3L_interpolateBarycentric(n0.y,n1.y,n2.y,p->barycentric);
n.z = S3L_interpolateBarycentric(n0.z,n1.z,n2.z,p->barycentric);
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]);
S3L_normalizeVec3(&n); S3L_normalizeVec3(&n);
@ -327,8 +319,7 @@ void drawPixel(S3L_PixelInfo *p)
if (light) if (light)
{ {
int16_t l = S3L_interpolateBarycentric(l0,l1,l2, int16_t l = S3L_interpolateBarycentric(l0,l1,l2,p->barycentric);
p->barycentric[0], p->barycentric[1], p->barycentric[2]);
r = S3L_clamp((((int16_t) r) * l) / S3L_FRACTIONS_PER_UNIT,0,255); 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); g = S3L_clamp((((int16_t) g) * l) / S3L_FRACTIONS_PER_UNIT,0,255);

View file

@ -556,9 +556,7 @@ static inline S3L_Unit S3L_interpolateBarycentric(
S3L_Unit value0, S3L_Unit value0,
S3L_Unit value1, S3L_Unit value1,
S3L_Unit value2, S3L_Unit value2,
S3L_Unit barycentric0, S3L_Unit barycentric[3]);
S3L_Unit barycentric1,
S3L_Unit barycentric2);
static inline void S3L_mapProjectionPlaneToScreen( static inline void S3L_mapProjectionPlaneToScreen(
S3L_Vec4 point, S3L_Vec4 point,
@ -1517,15 +1515,13 @@ static inline S3L_Unit S3L_interpolateBarycentric(
S3L_Unit value0, S3L_Unit value0,
S3L_Unit value1, S3L_Unit value1,
S3L_Unit value2, S3L_Unit value2,
S3L_Unit barycentric0, S3L_Unit barycentric[3])
S3L_Unit barycentric1,
S3L_Unit barycentric2)
{ {
return return
( (
(value0 * barycentric0) + (value0 * barycentric[0]) +
(value1 * barycentric1) + (value1 * barycentric[1]) +
(value2 * barycentric2) (value2 * barycentric[2])
) / S3L_FRACTIONS_PER_UNIT; ) / S3L_FRACTIONS_PER_UNIT;
} }