Skip to content

Commit

Permalink
Optimized TriangleRasterizer
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Sep 29, 2024
1 parent 12fa480 commit d9edbad
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public void rasterize(final ImageBuffer colorBuffer, final float @Nullable [] de
if (sum == 0) {
continue;
}
final double pSum = (bc1 / w1) + (bc2 / w2) + (bc3 / w3);
final int rasterIndex = y * rasterWidth + x;

if (depthBuffer != null) {
Expand All @@ -124,6 +123,8 @@ public void rasterize(final ImageBuffer colorBuffer, final float @Nullable [] de
depthBuffer[rasterIndex] = z;
}

final double pSum = (bc1 / w1) + (bc2 / w2) + (bc3 / w3);

final int a = (int) ((bc1 * a1 + bc2 * a2 + bc3 * a3) / sum);
final int r = (int) ((bc1 * r1 + bc2 * r2 + bc3 * r3) / sum);
final int g = (int) ((bc1 * g1 + bc2 * g2 + bc3 * g3) / sum);
Expand All @@ -140,7 +141,9 @@ public void rasterize(final ImageBuffer colorBuffer, final float @Nullable [] de
color = ColorMixer.mix(color, texColor);
}

colorRaster[rasterIndex] = ColorMixer.blend(colorRaster[rasterIndex], color);
if ((color & 0xFF000000) != 0) {
colorRaster[rasterIndex] = ColorMixer.blend(colorRaster[rasterIndex], color);
}
}
}
}
Expand Down

0 comments on commit d9edbad

Please sign in to comment.