From c7575fc330a5b5d5367938593df37820c8241995 Mon Sep 17 00:00:00 2001 From: archibate <17721388340@163.com> Date: Tue, 25 Feb 2020 17:23:41 +0800 Subject: [PATCH] [skip ci] glsl raw_mod fixed --- taichi/backends/codegen_opengl.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/taichi/backends/codegen_opengl.cpp b/taichi/backends/codegen_opengl.cpp index 803eac2b70017..7e71e98510578 100644 --- a/taichi/backends/codegen_opengl.cpp +++ b/taichi/backends/codegen_opengl.cpp @@ -479,6 +479,11 @@ int _rand_i32()\n\ emit("{} {} = {}(floor((float({}) * (1 + sign({} * {}) * 1e-6)) / float({})));", dt_name, bin_name, dt_name, lhs_name, lhs_name, rhs_name, rhs_name); return; + } else if (bin->op_type == BinaryOpType::mod) { + // NOTE: the GLSL built-in function `mod()` is a pythonic mod: x - y * floor(x / y) + emit("{} {} = {} - {} * int({} / {});", dt_name, bin_name, lhs_name, rhs_name, + lhs_name, rhs_name); + return; } const auto binop = binary_op_type_symbol(bin->op_type); if (is_opengl_binary_op_infix(bin->op_type)) {