One thing I’ve never been able to get out of a shader is the feel of something moving over time. The best I can do is animate a UV offset over time.
Let’s say I wanted to create a shader for a night sky. Stars are fine, they can sparkle with some random noise, and gradually move with UV offset. But what if I want an occasional shooting star to go by? Every frame, it needs to move a little more in some direction, ideally leaving behind a trail that diminishes over time.
Or if I wanted a shader that resembled an ant walking around, somewhat randomly, where each frame he moved a little more.
Those approaches seem to require some overall memory of what came before it. I can imagine doing this outside of the shader, and providing the material/shader with an array of data it uses for this task. But is there some whole concept I’m missing, where things like this could be done 100% within the shader itself?
You could derive everything from time, if you want to have a motion that seems to have a history. i.e. Like a particle traveling through space, or some object(s) moving around, like your example ants. You could also fake trails etc. this way, instead of storing the previous frame and then accumulating changes on it.
That seems to be the extremely tricky part. But, thinking about what you said a bit, I guess I can imagine incrementally more complex movement, with “history”, based on simple, deterministic functions. Maybe the simplest would be a dot moving across the screen, leaving a fading trail behind it. In that case, the pixel would be full color at x = t, lerping down to black at x - 1 = t.
So, I guess conceptually that does make sense. The next step would be determining functions that “move” over time. I guess I’ll look into that.
I think you can probably find good examples at shadertoy.com.
But I cooked up a quick test, something like this is definitely doable.
The snaky forms with trail fly around the space and leave a trail. This does not require any history to be saved. Video would be more obvious but I didn’t have time to upload one.
Anyway, you can build this with a nested loop, inner creates the particles and moves them, and the outer loop offsets the time.
(This specific shader draft I made was really inefficient, I just cooked up something quick but you could definitely optimize this be reducing the amount of “clones” and so on.)