From 29e5a8b0805d318c91fdd425b95ad883c9755151 Mon Sep 17 00:00:00 2001 From: gered Date: Tue, 4 Apr 2023 21:06:10 -0400 Subject: [PATCH] some similar changes in indexed triangle_2d drawing --- ggdt/src/graphics/bitmap/indexed/triangles.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ggdt/src/graphics/bitmap/indexed/triangles.rs b/ggdt/src/graphics/bitmap/indexed/triangles.rs index 53fb164..2fbc98d 100644 --- a/ggdt/src/graphics/bitmap/indexed/triangles.rs +++ b/ggdt/src/graphics/bitmap/indexed/triangles.rs @@ -53,29 +53,29 @@ impl IndexedBitmap { ) } SolidTextured { position, texcoord, bitmap } => { - let inverse_area = 1.0 / edge_function(position[0], position[1], position[2]); + let area = edge_function(position[0], position[1], position[2]); per_pixel_triangle_2d( self, // position[0], position[1], position[2], |dest_pixels, w0, w1, w2| { - let u = (w0 * texcoord[0].x + w1 * texcoord[1].x + w2 * texcoord[2].x) * inverse_area; - let v = (w0 * texcoord[0].y + w1 * texcoord[1].y + w2 * texcoord[2].y) * inverse_area; + let u = (w0 * texcoord[0].x + w1 * texcoord[1].x + w2 * texcoord[2].x) / area; + let v = (w0 * texcoord[0].y + w1 * texcoord[1].y + w2 * texcoord[2].y) / area; *dest_pixels = bitmap.sample_at(u, v); }, ) } SolidTexturedBlended { position, texcoord, bitmap, blendmap } => { - let inverse_area = 1.0 / edge_function(position[0], position[1], position[2]); + let area = edge_function(position[0], position[1], position[2]); per_pixel_triangle_2d( self, // position[0], position[1], position[2], |dest_pixels, w0, w1, w2| { - let u = (w0 * texcoord[0].x + w1 * texcoord[1].x + w2 * texcoord[2].x) * inverse_area; - let v = (w0 * texcoord[0].y + w1 * texcoord[1].y + w2 * texcoord[2].y) * inverse_area; + let u = (w0 * texcoord[0].x + w1 * texcoord[1].x + w2 * texcoord[2].x) / area; + let v = (w0 * texcoord[0].y + w1 * texcoord[1].y + w2 * texcoord[2].y) / area; let texel = bitmap.sample_at(u, v); *dest_pixels = if let Some(blended) = blendmap.blend(texel, *dest_pixels) { blended } else { texel };