atomicMax
Performs a thread-safe atomic maximum comparison and write operation on a value in shared memory (usually a Storage Buffer), ensuring the final stored value is the maximum among all candidates from many competing parallel threads.
Core Advantages
Guarantees the atomicity of the 'read-compare-write' operation at the hardware level, enabling efficient and correct parallel max reduction. It simplifies the complex 'many compete, one wins' logic into a single function call.
Common Uses
Finding and recording the furthest depth value per pixel for volumetric fog or post-processing effects.
Tracking the maximum velocity or pressure experienced by each grid cell in fluid or particle simulations.
Generating influence maps by comparing a packed 'strength + ID' value to determine the strongest influence at each point.
How to adjust
Its effect is adjusted by changing the `valueNode` (the candidate value). For example, when generating a heightmap, the `valueNode` is the object's height. If you change it to the material's metalness, `atomicMax` will instead find and record the most metallic visible material at each pixel, producing a metalness map instead of a heightmap. It's a general-purpose 'find the champion' tool, where `valueNode` defines the 'competition'.
Code Examples
1// Convert the world Z position (height) to an integer
2const world_z_as_int = int( positionWorld.z * 100.0 );
3// Compare with the current max in the buffer and atomically write the new max
4atomicMax( heightmapBuffer.element( screenIndex ), world_z_as_int );