diff options
| author | tslil clingman <> | 2021-10-12 11:57:23 -0400 |
|---|---|---|
| committer | tslil clingman <> | 2021-10-12 12:07:01 -0400 |
| commit | 2463aa73cb926bee528e0882bea28b3c2dcf6e60 (patch) | |
| tree | a96f21ba58ad8aacf3c4cb3065b5a63851b3c046 /src/render.zig | |
| parent | 1a00dd2342292e545d3aa26c2c0eadc80caedf5c (diff) | |
Might as well also compute texel_y directly like texel_x for objects
and skip a multiplication in favour of addition
Diffstat (limited to 'src/render.zig')
| -rw-r--r-- | src/render.zig | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/render.zig b/src/render.zig index 00e65fd..47753f0 100644 --- a/src/render.zig +++ b/src/render.zig @@ -172,10 +172,10 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { const start = std.math.max(0, left); const end = @floatToInt(usize, std.math.min(left + width, PlaneWidth - 1)); - const inv_height = 1 / height; - + const tex_y_step = constants.TextureDim / height; const tex_x_step = constants.TextureDim / width; const toff = obj.texture * @floatToInt(c_uint, constants.TextureDim); + const thresh = top - height; const constrained_bottom = std.math.min(top, PlaneHeight); const pix_y = @floatToInt(usize, std.math.ceil(std.math.max(PlaneHeight - constrained_bottom - 1, 0))); @@ -189,14 +189,14 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { }) { const tx = @floatToInt(c_uint, tex_x); var pix_index = @floatToInt(usize, PlaneWidth) * pix_y + col; - var texel_y = (top - bottom) / height; + var texel_y = constants.TextureDim * (top - bottom) / height; while (pix_index < PlanePixels and bottom > thresh) : ({ bottom -= 1; - texel_y += inv_height; + texel_y += tex_y_step; pix_index += @floatToInt(usize, PlaneWidth); }) { if (self.z_buffer[pix_index] > scaled_perp_distance) { - const ty = @floatToInt(c_uint, texel_y * constants.TextureDim); + const ty = @floatToInt(c_uint, texel_y); const texel = objects_image.getPixel(.{ .x = toff + tx, .y = ty }); // TODO: Decide whether being accurate is as important as being fast pixels[pix_index] = fasterColourBlend(pixels[pix_index], texel); @@ -318,8 +318,8 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { // height of a unit-height wall at this distance const nominal_length = PlaneDist / distance; - const inv_nom_len = distance / PlaneDist; // used for texel indexing + const inv_nom_len = distance / PlaneDist; const td = @floatToInt(c_uint, constants.TextureDim); if (draw_lower) { @@ -335,9 +335,7 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { var texel_y: f32 = std.math.max((top_of_floor - constrained_top) / nominal_length, 0); // now we have what we need to draw the face, - // and update the z-buffer. Note that it doesn't - // matter which way we write to the z_buffer - // here, walls are vertical! + // and update the z-buffer. while (pix_index < stop) : ({ pix_index += @floatToInt(usize, PlaneWidth); texel_y += inv_nom_len; @@ -354,7 +352,7 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { if (draw_upper) { const proj_default_end = PlaneHeight / 2 + PlaneDist * (level.Cell.DEFAULT_HEIGHT - pheight) / distance; const constrained_top = std.math.min(lowest_drawn, proj_default_end); - const constrained_bottom = std.math.max(bottom_of_ceiling, highest_drawn); + const constrained_bottom = std.math.ceil(std.math.max(bottom_of_ceiling, highest_drawn)); const stop = @floatToInt(usize, PlaneWidth * (PlaneHeight - constrained_bottom)) + col; const t_upper_off = cell.upper_texture * td; const pix_y = @floatToInt(usize, std.math.ceil(std.math.max(PlaneHeight - constrained_top - 1, 0))); @@ -396,7 +394,7 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type { if (next_top > highest_drawn) { const toff = cell.floor_texture * @floatToInt(c_uint, constants.TextureDim); - top_of_floor = std.math.min(std.math.min(next_top, lowest_drawn), PlaneHeight / 2 - 1); + top_of_floor = std.math.ceil(std.math.min(std.math.min(next_top, lowest_drawn), PlaneHeight / 2 - 1)); const thresh = std.math.ceil(highest_drawn); const itop = @floatToInt(usize, std.math.max(top_of_floor, 0)); |
