storageTexture
Allows shaders (especially compute shaders) to read from and write to any arbitrary pixel of a texture. It transforms a texture from a read-only resource into a writable 'canvas' on the GPU, core to procedural generation and GPGPU simulations.
Core Advantages
Enables random-access writes to textures, allowing the GPU to directly and efficiently generate or modify image data. It provides a native data structure for complex spatial algorithms like fluid simulations.
Common Uses
Real-time procedural texture generation (e.g., noise, fractals)
Grid-based physics simulations (e.g., fluids, cloth)
High-performance image post-processing
How to adjust
The node's effect is adjusted by creatively constructing the content to write (`storeNode`) and the location to write it to (`uvNode`). For example, connecting a time-based `noise` node to `storeNode` generates dynamic noise textures. Creating a feedback loop by reading, processing, and writing back to the same location enables effects like temporal decay or iterative processing.
Code Examples
1// Get the pixel coordinate for the current compute thread
2const writeUV = globalInvocationID.xy;
3
4// Calculate a color value based on the coordinate
5const colorValue = vec4( writeUV.x.div( 512 ), writeUV.y.div( 512 ), 0.5, 1.0 );
6
7// Write the color value to the storageTexture at the specified coordinate
8storageTexture( myGpuTexture, writeUV, colorValue ).toStack();