mx_subtract
mx_subtract
MaterialX‑style subtraction wrapper: returns in1 − in2; when in2 is omitted it defaults to 0.
Core Advantages
Name matches MaterialX and is equivalent to TSL’s base math node sub; supports float/vec2/vec3/vec4 with automatic scalar‑to‑vector broadcasting for clear, readable graphs.
Common Uses
Subtract a threshold from a mask/noise to create hard/soft edges.
Apply relative coordinate offsets (e.g., uv − time·speed).
Use A − B as a building block for contrast or edge enhancement.
How to adjust
Tune in1/in2; default in2=0 (pass‑through). Combine with mul/abs/pow for thresholds, offsets, or difference amplification; mixed types (e.g., vec3 − float) broadcast automatically.
Code Examples
1
2// 1) float − float: simple fade
3const fade = mx_subtract( float( 1.0 ), time.mul( 0.25 ) ).saturate();
4
5// 2) vector − float (broadcast): attenuate AO
6const base = color( 0.9, 0.7, 0.2 );
7material.colorNode = mx_subtract( base, materialAO.mul( 0.3 ) );
8
9// 3) Rim factor: rim ≈ 1 − |N·V|
10const rim = mx_subtract( float( 1.0 ), normalView.dot( positionViewDirection ).abs() ).pow( 3.0 );
11material.emissiveNode = color( 0x44ccff ).mul( rim );
12