怎么把这个Shader函数翻译成JS呢?

How to translate this Shader function to JS?

所以我在 Shader vec2 cmp = step(t_max.xy, t_max.yx); 中发现了这个非常有用的代码和平。我需要将其翻译成 JavaScript。但是不知道怎么办。

Vec2 我简单地假设为二维数组,其中索引 0 是 x,1 是 y。

var cmp = step([t_max[0], t_max[1]], [t_max[1], t_max[0]]);

但是步骤部分对我来说很难。即使检查 https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/step.xhtml

step,如 GLSL 中所定义,只需要两个参数:edgex(或 input)。它 returns 0.0 当 x < edge 和 1.0 时相反。要将它与 vec2(大小为 2 的数组 - 而不是二维数组)一起使用,您可以定义这样的函数:

function step(edge, input) {
    x = edge[0] > input[0] ? 0.0 : 1.0;
    y = edge[1] > input[1] ? 0.0 : 1.0;
    return [x, y]
}