3 ms·
GPU shaders have time? As for game logic-it does make sense. Tying logic and rendering to a system timer / frame counter leads to all kinds of issues.
by baxuz 4y ago
GPU shaders have time?
As for game logic-it does make sense. Tying logic and rendering to a system timer / frame counter leads to all kinds of issues.
- skrebbel 4y agoGPU shaders don't "have" time but you can cheaply send them the current frame's time wrt some start time as a uniform input variable.
- Drakim 4y agoIt's extremely common to send a time input to GPU shaders, although this time input doesn't need to be tied to anything like a system timer or frame counter, it can be arbitrary and adjusted at will. Think of it like this: Imagine you have an expensive tween animation for particles, and every frame you have to use your CPU to calculate where the particle should have moved as part of it's animation, and send those updated coordinates to the GPU. Imagine you have millions of such objects, so it's quite the burden for the CPU, both in terms of calculating the tween animation, but also in terms of constantly updating every particle's x,y values over and over. Instead, you could seed each particle on the GPU with x1,y1,x2,y2 values, and then just provide a global "time" value for them all to share. When you update time = time + 1, all particles on the GPU will recalculate their position without needing to be helped by the CPU. The trick is that they don't save this new position though, instead, they do the job all over again from scratch at time = time + 2, which is a lot cheaper since we didn't need to "save" our previous result, which is hard work on the GPU.
- baxuz 4y agoGreat explanation, thanks!