compute
The `compute` node is the core of General-Purpose GPU (GPGPU) computing in TSL. It allows developers to leverage the GPU's massive parallel processing power for large-scale computational tasks, like physics simulations and particle systems, independently of the traditional rendering pipeline.
Core Advantages
Unlocks the parallel power of the GPU's thousands of cores, delivering orders-of-magnitude performance gains for complex simulations. It runs independently of the rendering pipeline and offers flexible data read/write via Storage Buffers, making it key for high-performance particle systems, physics, and procedural content generation.
Common Uses
Large-Scale Particle Systems
Physics Simulation (Cloth, Fluids)
High-Performance Image Processing
Procedural Geometry Generation
How to adjust
Adjustments are made in two main ways: 1. By changing `uniform` global variables passed to the compute logic, such as modifying a `forceStrength` variable to control simulated forces in real-time. 2. By altering the `count` parameter to increase or decrease the number of simulated elements (e.g., particles). The final visual result depends on how the rendering pipeline uses the updated buffer data.
Code Examples
1// Define the logic: get the buffer element for the current thread and assign it a new value
2// The new value is determined by the element's index and time
3const computeLogic = myBuffer.element(instanceIndex).assign(
4 instanceIndex.mul(0.01).add(timerLocal())
5);
6
7// Create the compute node, bundling the logic and the total element count
8const particleUpdater = compute(computeLogic, PARTICLE_COUNT);