mx_contrast
Programmatically adjusts the contrast of an input value (color or float) by expanding or compressing its tonal range around a central pivot point.
Core Advantages
Allows for real-time, dynamic control over visual contrast directly within the shader, eliminating the need to swap texture assets, which greatly simplifies art workflows and enables interactive or animated visual effects.
Common Uses
As a post-processing effect to adjust the mood of the entire rendered scene, such as for a dramatic or faded look.
To enhance texture details, making elements like wood grain, rock surfaces, or fabric patterns 'pop' with more definition.
To sharpen the output of procedural noise, creating more defined black and white areas for generating masks or patterns.
How to adjust
Adjusted primarily via the `amount` and `pivot` parameters. An `amount` greater than 1 increases contrast, while a value between 0 and 1 decreases it (making the image 'flatter'). Negative values invert the tones (a 'negative' effect). The `pivot` (default 0.5) sets the central point of the transformation that remains unchanged.
Code Examples
1// Enhance the contrast of a base color by 2.5x, pivoting around mid-gray (0.5)
2const contrastedColor = mx_contrast(baseColor, 2.5, 0.5);