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

Interpolate to 511 instead 512

This commit is contained in:
Miloslav Číž 2019-06-11 00:24:45 +02:00
parent 1866d11bed
commit 6e6bdf0c77
2 changed files with 31 additions and 15 deletions

View file

@ -11,7 +11,7 @@
#define S3L_FLAT 0 #define S3L_FLAT 0
#define S3L_STRICT_NEAR_CULLING 0 #define S3L_STRICT_NEAR_CULLING 0
#define S3L_PERSPECTIVE_CORRECTION 2 #define S3L_PERSPECTIVE_CORRECTION 1
#define S3L_SORT 2 #define S3L_SORT 2
#define S3L_STENCIL_BUFFER 1 #define S3L_STENCIL_BUFFER 1
#define S3L_Z_BUFFER 0 #define S3L_Z_BUFFER 0
@ -78,6 +78,18 @@ S3L_Unit uv0[2], uv1[2], uv2[2];
void drawPixel(S3L_PixelInfo *p) void drawPixel(S3L_PixelInfo *p)
{ {
/*
if (p->barycentric[0] < 0 || p->barycentric[0] > 512)
printf("%d %d %d\n",p->barycentric[0],p->barycentric[1],p->barycentric[2]);
if (p->barycentric[1] < 0 || p->barycentric[1] > 512)
printf("%d %d %d\n",p->barycentric[0],p->barycentric[1],p->barycentric[2]);
if (p->barycentric[2] < 0 || p->barycentric[2] > 512)
printf("%d %d %d\n",p->barycentric[0],p->barycentric[1],p->barycentric[2]);
*/
if (p->triangleIndex != previousTriangle) if (p->triangleIndex != previousTriangle)
{ {
int16_t index; int16_t index;

View file

@ -145,6 +145,8 @@ BE REDEFINED, so rather don't do it (otherwise things may overflow etc.). */
#define S3L_FRACTIONS_PER_UNIT 512 #define S3L_FRACTIONS_PER_UNIT 512
#define S3L_UNIT_MINUS_ONE (S3L_FRACTIONS_PER_UNIT - 1)
typedef int16_t S3L_ScreenCoord; typedef int16_t S3L_ScreenCoord;
typedef uint16_t S3L_Index; typedef uint16_t S3L_Index;
@ -446,8 +448,10 @@ typedef struct
S3L_Unit barycentric[3]; /**< Barycentric coords corresponds to the three S3L_Unit barycentric[3]; /**< Barycentric coords corresponds to the three
vertices. These serve to locate the pixel on a vertices. These serve to locate the pixel on a
triangle and interpolate values between it's triangle and interpolate values between it's
three points. The sum of the three coordinates three points. Each one goes from 0 to
will always be exactly S3L_FRACTIONS_PER_UNIT. */ S3L_UNIT_MINUS_ONE (inclidung) and the sum of the
three coordinates will always be exactly
S3L_UNIT_MINUS_ONE. */
S3L_Index triangleIndex; ///< Triangle index. S3L_Index triangleIndex; ///< Triangle index.
S3L_Index modelIndex; S3L_Index modelIndex;
S3L_Unit depth; ///< Depth (only if depth is turned on). S3L_Unit depth; ///< Depth (only if depth is turned on).
@ -1651,9 +1655,9 @@ void S3L_drawTriangle(
#if S3L_FLAT #if S3L_FLAT
p.depth = (tPointPP->z + lPointPP->z + rPointPP->z) / 3; p.depth = (tPointPP->z + lPointPP->z + rPointPP->z) / 3;
*barycentric0 = S3L_FRACTIONS_PER_UNIT / 3; *barycentric0 = S3L_UNIT_MINUS_ONE / 3;
*barycentric1 = S3L_FRACTIONS_PER_UNIT / 3; *barycentric1 = S3L_UNIT_MINUS_ONE / 3;
*barycentric2 = S3L_FRACTIONS_PER_UNIT - 2 * (S3L_FRACTIONS_PER_UNIT / 3); *barycentric2 = S3L_UNIT_MINUS_ONE - 2 * (S3L_UNIT_MINUS_ONE / 3);
#endif #endif
p.triangleSize[0] = rPointSx - lPointSx; p.triangleSize[0] = rPointSx - lPointSx;
@ -1735,12 +1739,12 @@ void S3L_drawTriangle(
s##Dx = p2##PointSx - p1##PointSx;\ s##Dx = p2##PointSx - p1##PointSx;\
s##Dy = p2##PointSy - p1##PointSy;\ s##Dy = p2##PointSy - p1##PointSy;\
initDepthFLS(s,p1,p2)\ initDepthFLS(s,p1,p2)\
s##SideFLS.stepScaled = (S3L_FRACTIONS_PER_UNIT << S3L_FAST_LERP_QUALITY)\ s##SideFLS.stepScaled = (S3L_UNIT_MINUS_ONE << S3L_FAST_LERP_QUALITY)\
/ (s##Dy != 0 ? s##Dy : 1);\ / (s##Dy != 0 ? s##Dy : 1);\
s##SideFLS.valueScaled = 0;\ s##SideFLS.valueScaled = 0;\
if (!down)\ if (!down)\
{\ {\
s##SideFLS.valueScaled = S3L_FRACTIONS_PER_UNIT << S3L_FAST_LERP_QUALITY;\ s##SideFLS.valueScaled = S3L_UNIT_MINUS_ONE << S3L_FAST_LERP_QUALITY;\
s##SideFLS.stepScaled *= -1;\ s##SideFLS.stepScaled *= -1;\
}\ }\
s##Inc = s##Dx >= 0 ? 1 : -1;\ s##Inc = s##Dx >= 0 ? 1 : -1;\
@ -1815,7 +1819,7 @@ void S3L_drawTriangle(
S3L_Unit *tmp = barycentric##b0;\ S3L_Unit *tmp = barycentric##b0;\
barycentric##b0 = barycentric##b1;\ barycentric##b0 = barycentric##b1;\
barycentric##b1 = tmp;\ barycentric##b1 = tmp;\
s0##SideFLS.valueScaled = (S3L_FRACTIONS_PER_UNIT\ s0##SideFLS.valueScaled = (S3L_UNIT_MINUS_ONE\
<< S3L_FAST_LERP_QUALITY) - s0##SideFLS.valueScaled;\ << S3L_FAST_LERP_QUALITY) - s0##SideFLS.valueScaled;\
s0##SideFLS.stepScaled *= -1;\ s0##SideFLS.stepScaled *= -1;\
manageSplitPerspective(s0,s1) manageSplitPerspective(s0,s1)
@ -1922,7 +1926,7 @@ void S3L_drawTriangle(
S3L_FastLerpState depthPC, b0PC, b1PC; S3L_FastLerpState depthPC, b0PC, b1PC;
depthPC.valueScaled = depthPC.valueScaled =
((S3L_FRACTIONS_PER_UNIT * S3L_FRACTIONS_PER_UNIT) / ((S3L_UNIT_MINUS_ONE * S3L_FRACTIONS_PER_UNIT) /
S3L_nonZero(S3L_interpolate(lRecipZ,rRecipZ,i,rowLength))) S3L_nonZero(S3L_interpolate(lRecipZ,rRecipZ,i,rowLength)))
<< S3L_FAST_LERP_QUALITY; << S3L_FAST_LERP_QUALITY;
@ -1953,7 +1957,7 @@ void S3L_drawTriangle(
#if S3L_COMPUTE_DEPTH #if S3L_COMPUTE_DEPTH
#if S3L_PERSPECTIVE_CORRECTION == 1 #if S3L_PERSPECTIVE_CORRECTION == 1
p.depth = (S3L_FRACTIONS_PER_UNIT * S3L_FRACTIONS_PER_UNIT) / p.depth = (S3L_UNIT_MINUS_ONE * S3L_FRACTIONS_PER_UNIT) /
S3L_nonZero(S3L_interpolate(lRecipZ,rRecipZ,i,rowLength)); S3L_nonZero(S3L_interpolate(lRecipZ,rRecipZ,i,rowLength));
#elif S3L_PERSPECTIVE_CORRECTION == 2 #elif S3L_PERSPECTIVE_CORRECTION == 2
if (rowCount >= S3L_PC_APPROX_LENGTH) if (rowCount >= S3L_PC_APPROX_LENGTH)
@ -1964,7 +1968,7 @@ void S3L_drawTriangle(
S3L_Unit nextDepth = S3L_Unit nextDepth =
( (
(S3L_FRACTIONS_PER_UNIT * S3L_FRACTIONS_PER_UNIT) / (S3L_UNIT_MINUS_ONE * S3L_FRACTIONS_PER_UNIT) /
S3L_nonZero(S3L_interpolate(lRecipZ,rRecipZ,nextI,rowLength)) S3L_nonZero(S3L_interpolate(lRecipZ,rRecipZ,nextI,rowLength))
) << S3L_FAST_LERP_QUALITY; ) << S3L_FAST_LERP_QUALITY;
@ -2028,7 +2032,7 @@ void S3L_drawTriangle(
#endif #endif
*barycentric2 = *barycentric2 =
S3L_FRACTIONS_PER_UNIT - *barycentric0 - *barycentric1; S3L_UNIT_MINUS_ONE - *barycentric0 - *barycentric1;
#endif #endif
S3L_PIXEL_FUNCTION(&p); S3L_PIXEL_FUNCTION(&p);
} }