1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-21 20:39:57 +01:00
This commit is contained in:
Miloslav Číž 2019-06-22 22:56:17 +02:00
parent 80eb80b9bd
commit f2a9fd18f4

View file

@ -2102,6 +2102,8 @@ void S3L_drawTriangle(
int8_t rowCount = S3L_PC_APPROX_LENGTH; int8_t rowCount = S3L_PC_APPROX_LENGTH;
#endif #endif
S3L_Index zBufferIndex = p.y * S3L_RESOLUTION_X + lXClipped;
// draw the row -- inner loop: // draw the row -- inner loop:
for (S3L_ScreenCoord x = lXClipped; x < rXClipped; ++x) for (S3L_ScreenCoord x = lXClipped; x < rXClipped; ++x)
@ -2127,7 +2129,36 @@ void S3L_drawTriangle(
S3L_Unit nextI = i + S3L_PC_APPROX_LENGTH; S3L_Unit nextI = i + S3L_PC_APPROX_LENGTH;
if (nextI >= rowLength) if (nextI < rowLength)
{
S3L_Unit nextDepthScaled =
(
Z_RECIP_NUMERATOR /
S3L_nonZero(S3L_interpolate(lRecipZ,rRecipZ,nextI,rowLength))
) << S3L_FAST_LERP_QUALITY;
depthPC.stepScaled =
(nextDepthScaled - depthPC.valueScaled) / S3L_PC_APPROX_LENGTH;
S3L_Unit nextValue =
(
S3L_interpolateFrom0(rOverZ,nextI,rowLength)
* nextDepthScaled
) / (Z_RECIP_NUMERATOR / S3L_FRACTIONS_PER_UNIT);
b0PC.stepScaled =
(nextValue - b0PC.valueScaled) / S3L_PC_APPROX_LENGTH;
nextValue =
(
(lOverZ - S3L_interpolateFrom0(lOverZ,nextI,rowLength))
* nextDepthScaled
) / (Z_RECIP_NUMERATOR / S3L_FRACTIONS_PER_UNIT);
b1PC.stepScaled =
(nextValue - b1PC.valueScaled) / S3L_PC_APPROX_LENGTH;
}
else
{ {
/* A special case where we'd be interpolating outside the triangle. /* A special case where we'd be interpolating outside the triangle.
It seems like a valid approach at first, but it creates a bug It seems like a valid approach at first, but it creates a bug
@ -2158,35 +2189,6 @@ void S3L_drawTriangle(
b1PC.stepScaled = b1PC.stepScaled =
-1 * b1PC.valueScaled / maxI; -1 * b1PC.valueScaled / maxI;
} }
else
{
S3L_Unit nextDepthScaled =
(
Z_RECIP_NUMERATOR /
S3L_nonZero(S3L_interpolate(lRecipZ,rRecipZ,nextI,rowLength))
) << S3L_FAST_LERP_QUALITY;
depthPC.stepScaled =
(nextDepthScaled - depthPC.valueScaled) / S3L_PC_APPROX_LENGTH;
S3L_Unit nextValue =
(
S3L_interpolateFrom0(rOverZ,nextI,rowLength)
* nextDepthScaled
) / (Z_RECIP_NUMERATOR / S3L_FRACTIONS_PER_UNIT);
b0PC.stepScaled =
(nextValue - b0PC.valueScaled) / S3L_PC_APPROX_LENGTH;
nextValue =
(
(lOverZ - S3L_interpolateFrom0(lOverZ,nextI,rowLength))
* nextDepthScaled
) / (Z_RECIP_NUMERATOR / S3L_FRACTIONS_PER_UNIT);
b1PC.stepScaled =
(nextValue - b1PC.valueScaled) / S3L_PC_APPROX_LENGTH;
}
} }
p.depth = S3L_getFastLerpValue(depthPC); p.depth = S3L_getFastLerpValue(depthPC);
@ -2197,7 +2199,8 @@ void S3L_drawTriangle(
#endif #endif
#if S3L_Z_BUFFER #if S3L_Z_BUFFER
p.previousZ = S3L_zBuffer[p.y * S3L_RESOLUTION_X + p.x]; p.previousZ = S3L_zBuffer[zBufferIndex];
zBufferIndex++;
if (!S3L_zTest(p.x,p.y,p.depth)) if (!S3L_zTest(p.x,p.y,p.depth))
testsPassed = 0; testsPassed = 0;