Could you use a non-float integer instead? Do GPUs have cheap int % float -> float operations?
A Shader Trick
11–20 of 56 posts
Re: A Shader Trick
#12Why limit one’s self to absolutely having to describe it in a single integer value? Why not some wrapper around a handful of integer values that can handle a much bigger max?
Would this have a meaningful performance cost?
Re: A Shader Trick
#13I 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; }
Re: A Shader Trick
#14seeing it delivered as a clever trick in a blog post makes me wonder if i'm more competent than i thought, or if everyone else is generally less competent than i thought.
Re: A Shader Trick
#15The blog suggests that you need to use integers to describe time because floats have problems. Granted. Why limit one’s self to absolutely having to describe it in a single integer value? Why not some wrapper around a handful of integer values that can handle a much bigger max? Would this have a meaningful performance cost?
Re: A Shader Trick
#16Could you use a non-float integer instead? Do GPUs have cheap int % float -> float operations?
I'm confused why you need a global total game-time anyways, or if you have one why it has to be precise. Could you use your precise time in float, and then increment a larger but less-precise total gametime value every 10 minutes?
Re: A Shader Trick
#17Earlier quoted context omitted.
I'm confused why you need a global total game-time anyways, or if you have one why it has to be precise. Could you use your precise time in float, and then increment a larger but less-precise total gametime value every 10 minutes?
It doesn't have to be game time, as the article says it could be time since level or some other trigger. It's basically about any time based counter you need for a time based effect, such as a predefined cyclical wind effect on trees or waves in water. The article also explains why it has to be precise, looping effects will behave oddly if the loop is not occurring precisely. Splitting the number into a large part an…
Re: A Shader Trick
#18i have been doing this for a while playing around with shadertoy. i don't think i learned it from anywhere, i just wanted some things to match up and repeat over hours and it was obvious that sin/cos are periodic, and cycling the time value would improve the imprecision at the seam. seeing it delivered as a clever trick in a blog post makes me wonder if i'm more competent than i thought, or if everyone else is genera…
Re: A Shader Trick
#19I think I've read that minecraft behaves differently depending on how far away you are standing from the origin for similar reasons: [1] https://minecraft.fandom.com/wiki/Bedrock_Edition_distance_e... [2] https://minecraft.fandom.com/wiki/Java_Edition_distance_effe...
Re: A Shader Trick
#20I 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; }
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.