From 070eb35dde54f8dcbffad8fb3d97367bb792b6b1 Mon Sep 17 00:00:00 2001 From: inspectredc <78732756+inspectredc@users.noreply.github.com> Date: Sat, 1 Jun 2024 04:16:19 +0100 Subject: [PATCH] Add Metal Float and Float4 Mod (#621) * Add metal float and float4 mod * tidy --- src/graphic/Fast3D/gfx_metal_shader.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/graphic/Fast3D/gfx_metal_shader.cpp b/src/graphic/Fast3D/gfx_metal_shader.cpp index af841f858..cd6ae2c09 100644 --- a/src/graphic/Fast3D/gfx_metal_shader.cpp +++ b/src/graphic/Fast3D/gfx_metal_shader.cpp @@ -254,11 +254,22 @@ MTL::VertexDescriptor* gfx_metal_build_shader(char buf[8192], size_t& num_floats append_line(buf, &len, "}"); // end vertex shader + append_line(buf, &len, "float mod(float a, float b) {"); + append_line(buf, &len, " return float(a - b * floor(a / b));"); + append_line(buf, &len, "}"); + append_line(buf, &len, "float3 mod(float3 a, float3 b) {"); append_line( buf, &len, " return float3(a.x - b.x * floor(a.x / b.x), a.y - b.y * floor(a.y / b.y), a.z - b.z * floor(a.z / b.z));"); append_line(buf, &len, "}"); + + append_line(buf, &len, "float4 mod(float4 a, float4 b) {"); + append_line(buf, &len, + " return float4(a.x - b.x * floor(a.x / b.x), a.y - b.y * floor(a.y / b.y), a.z - b.z * floor(a.z / " + "b.z), a.w - b.w * floor(a.w / b.w));"); + append_line(buf, &len, "}"); + append_line(buf, &len, "#define WRAP(x, low, high) mod((x)-(low), (high)-(low)) + (low)"); // fragment shader