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

<pre><code>float frequency = getFrequency();
sineTime += frequency * deltaTime;
</code></pre>

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

<p>And if you pass <code>sineTime</code> into your shader you can just do</p>

<pre><code>float s = sin(sineTime);
</code></pre>

CC BY-SA 3.0
2018-02-15T17:30:37.923Z
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 :)
MaT
CC BY-SA 3.0
2018-02-15T16:37:13.300Z
2018-02-15T16:37:13.300Z
Sebastián Mestre
<p>In my vertex shader I am using a <code>sin</code> function to offset vertices. But as I change the frequency of my <code>sin</code> function I notice some "flickering" or "jumps". I guess that this comes from the fact that the phase is not synchronised any more.</p>

<pre><code>float s = sin(frequency * _Time);
</code></pre>

<p>Is there a way to avoid those flickering effect while changing the frequency ?</p>

<shader><glsl><mathematics><hlsl>
Changing sin frequency smoothly in shader
MaT
# Changing sin frequency smoothly in shader

(Asked by: username_0 on 2018-02-15)

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 ?

**Tags:** shader, glsl, mathematics, hlsl


---

## 1 answers

### Answer by username_1 on 2018-02-15. Score: 3 | Accepted answer

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);

```

> **Comments:**
> **username_0**: 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 :)  

---

