4 ms·
I think that instead of this, my solution would be to have each function that depends on dt to accumulate the dt themselves, and reset it at their individual pe
by webkike 5y ago
I think that instead of this, my solution would be to have each function that depends on dt to accumulate the dt themselves, and reset it at their individual periods.
A Rust trait with an associated const would help with this:
trait TimeDependentFn {
const PERIOD: f32;
type Output;
fn call(&self, dt: f32) -> Self::Output;
}
- nmilo 5y agoBut then you would need a local dt for each time-dependent function, and shaders don't really have packaged-up member variables in structs like you think they would if you come from Rust. That means you would have to maintain a massive list of dt's for each time-dependent function your shader calls, and then change this list everytime you introduce or remove a time-dependent function to the shader code. It's a solution that only works in a language that can hide the complexity from the programmer like Rust.
- ruined 5y agothis is about shaders, which have no persistent memory even pixel-to-pixel on the same frame. there is no way to accumulate over time. and calculating outside of the shader would miss the point. so you're stuck doing it from scratch every pixel. that's fine, shaders are fast. at most it might make sense to calculate a truncated time globally per frame and provide that as a uniform.