aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/rtw
diff options
context:
space:
mode:
Diffstat (limited to 'src/rtw')
-rw-r--r--src/rtw/perlin.zig18
-rw-r--r--src/rtw/texture.zig12
2 files changed, 15 insertions, 15 deletions
diff --git a/src/rtw/perlin.zig b/src/rtw/perlin.zig
index c60bb34..39173cd 100644
--- a/src/rtw/perlin.zig
+++ b/src/rtw/perlin.zig
@@ -53,9 +53,9 @@ pub const Perlin = struct {
const v_ = v * v * (3 - 2 * v);
const w_ = w * w * (3 - 2 * w);
- const i = @floatToInt(i32, @floor(p.x));
- const j = @floatToInt(i32, @floor(p.y));
- const k = @floatToInt(i32, @floor(p.z));
+ const i = @as(i32, @intFromFloat(@floor(p.x)));
+ const j = @as(i32, @intFromFloat(@floor(p.y)));
+ const k = @as(i32, @intFromFloat(@floor(p.z)));
var c: [2][2][2]Vec3 = undefined;
@@ -65,9 +65,9 @@ pub const Perlin = struct {
while (dj < 2) : (dj += 1) {
var dk: usize = 0;
while (dk < 2) : (dk += 1) {
- const ix = @intCast(usize, i + @intCast(i32, di)) & 255;
- const iy = @intCast(usize, j + @intCast(i32, dj)) & 255;
- const iz = @intCast(usize, k + @intCast(i32, dk)) & 255;
+ const ix = @as(usize, @intCast(i + @as(i32, @intCast(di)))) & 255;
+ const iy = @as(usize, @intCast(j + @as(i32, @intCast(dj)))) & 255;
+ const iz = @as(usize, @intCast(k + @as(i32, @intCast(dk)))) & 255;
c[di][dj][dk] = perlin.randomVec.items[
perlin.permX.items[ix] ^ perlin.permY.items[iy] ^ perlin.permZ.items[iz]
];
@@ -109,9 +109,9 @@ pub const Perlin = struct {
while (j < 2) : (j += 1) {
var k: usize = 0;
while (k < 2) : (k += 1) {
- const ti = @intToFloat(f64, i);
- const tj = @intToFloat(f64, j);
- const tk = @intToFloat(f64, k);
+ const ti = @as(f64, @floatFromInt(i));
+ const tj = @as(f64, @floatFromInt(j));
+ const tk = @as(f64, @floatFromInt(k));
const weight = Vec3{ .x = u - ti, .y = v - tj, .z = w - tk };
accum +=
(ti * u + (1.0 - ti) * (1.0 - u)) *
diff --git a/src/rtw/texture.zig b/src/rtw/texture.zig
index aabc18d..4095a9c 100644
--- a/src/rtw/texture.zig
+++ b/src/rtw/texture.zig
@@ -130,18 +130,18 @@ pub const ImageTexture = struct {
// Clamp input texture coordinates to [0, 1] x [1, 0]
const u_ = std.math.clamp(u, 0.0, 1.0);
const v_ = 1.0 - std.math.clamp(v, 0.0, 1.0); // Flip v to image coordinates
- const i = @floatToInt(usize, u_ * @intToFloat(f64, tx.image.width));
- const j = @floatToInt(usize, v_ * @intToFloat(f64, tx.image.height));
+ const i = @as(usize, @intFromFloat(u_ * @as(f64, @floatFromInt(tx.image.width))));
+ const j = @as(usize, @intFromFloat(v_ * @as(f64, @floatFromInt(tx.image.height))));
// Clamp integer mapping, since actual coordinates should be less than 1.0
const i_ = @min(i, tx.image.width - 1);
const j_ = @min(j, tx.image.width - 1);
const color_scale = 1.0 / 255.0;
const pixels = tx.image.pixels.asBytes();
const offset = j_ * tx.image.width * 4 + i_ * 4;
- const r = @intToFloat(f64, pixels[offset + 0]);
- const g = @intToFloat(f64, pixels[offset + 1]);
- const b = @intToFloat(f64, pixels[offset + 2]);
- const a = @intToFloat(f64, pixels[offset + 3]);
+ const r = @as(f64, @floatFromInt(pixels[offset + 0]));
+ const g = @as(f64, @floatFromInt(pixels[offset + 1]));
+ const b = @as(f64, @floatFromInt(pixels[offset + 2]));
+ const a = @as(f64, @floatFromInt(pixels[offset + 3]));
if (a == 0) {
// Ocean
return rgb(0, 0, 1.0);