mx_ramp4
Performs bilinear interpolation across four corner values (order: top-left, top-right, bottom-left, bottom-right). Uses UV by default (x/y clamped to [0,1]) and returns the same type as inputs (float/vec2/vec3/vec4).
Core Advantages
One-call 2D ramp/table interpolation; type-generic with auto clamping, removing manual weight math and edge handling for cleaner, reusable code.
Common Uses
2D color gradients across a surface.
Two-axis parameter blending (e.g., metalness × roughness control plane).
Smooth transition of four sampled values (including textures).
Lightweight 2×2 LUT/heatmap from two scalars to color/coeff.
Quadrant masks and layered ramps driven by UV/screen coordinates.
How to adjust
Change the four corner inputs to reshape the ramp. Replace texcoord with any vec2 (e.g., uv(1), screenUV, remapped positionWorld.xy) to alter direction/range. Pre-warp texcoord (mul/scale, rotate, pow, smoothstep, fract) to control transition width or distribution. For textures, sample each first and pass the four results.
Code Examples
1
2// Bilinear color ramp driven by UV
3const rampColor = mx_ramp4(
4 color( 0xff3b30 ), // tl
5 color( 0x34c759 ), // tr
6 color( 0x007aff ), // bl
7 color( 0xffcc00 ), // br
8 uv()
9);
10
11// Apply to a standard material
12material.colorNode = rampColor;
13
14// Or rely on default UV when mixing scalars
15// material.roughnessNode = mx_ramp4( 0.1, 0.4, 0.6, 0.9 );
16