I want to rewrite a ShaderMaterial to StandardNodeMaterial, here is the glsl segment code in ShaderMaterial.
float gridX = mod(uv.x, size.x + emptySize.x);
float gridY = mod(uv.y, size.y + emptySize.y);
if (gridX < size.x && gridY < size.y) {
float modX = mod(uv.x + time * speed, size.x);
if (modX < size.x * 0.5) {
float a = (speed >= .0) ? (.5 - modX / size.x) : (modX / size.x);
if (a < .0) {
a = .0;
}
diffuseColor *= vec4(color, a);
}
else {
if (flag > 0.) {
discard;
}
}
}
else {
discard;
}
Now, I have already use some Nodes to rewrite the codes above, however I cannot figure it out that how to replace if
with cond()
, and how to replace discard
with discard()
const gridX = mod(uv().x, add(size.x, emptySize.x));
const gridY = mod(uv().y, add(size.y, emptySize.y));
cond(
and(lessThan(gridX, size.x), lessThan(gridY, size.y)),
(
const modX = mod(add(uv().x, mul(time, speed)), size.x);
cond(
lessThan(modX, mul(size.x, 0.5)),
(
let a = cond(greaterThan(speed, .0), div(sub(.5, modX, size.x), div(modX, size.x));
a = cond(lessThan(a, 0), 0, a);
this.colorNode *= vec4(1.0, a);
),
discard()
)
),
discard()
)
This kind of coding is even clearly fail with JavaScript pattern, but I have no idea how should I write the code. Hope some guy could help me.