1
$\begingroup$

In my vertex shader I am using a sin function to offset vertices. But as I change the frequency of my sin function I notice some "flickering" or "jumps". I guess that this comes from the fact that the phase is not synchronised any more.

float s = sin(frequency * _Time);

Is there a way to avoid those flickering effect while changing the frequency ?

$\endgroup$
4
$\begingroup$

You could go the calculus way and have an explicit rate of change that is outside your shader

float frequency = getFrequency();
sineTime += frequency * deltaTime;

(sineTime could be a float that is scoped right outside of your render loop, so that it retains its value)

And if you pass sineTime into your shader you can just do

float s = sin(sineTime);
$\endgroup$
  • $\begingroup$ I already thought about that solution but I wanted to do stick everything inside the shader. I'll keep this as a backup solution, I guess :) $\endgroup$ – MaT Feb 15 '18 at 17:30
  • 2
    $\begingroup$ @MaT: If you want everything inside the shader, then presumably the frequency is also computed within the shader as some function float frequency = f(_Time). Then you should do some calculus by hand to figure out $g(t) = \int_0^t f(\tau)\,\mathrm d\tau$ and implement that in the shader as well. Then you can do float s = sin(g(_Time)). $\endgroup$ – Rahul Feb 16 '18 at 3:15

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.