- Home /
Question by
markthemark · May 18, 2020 at 01:45 AM ·
unity 5shadershaderswaves
How to make a 2d shader with edge waves
I'm trying to make a shader that creates sine like waves at the edges of a sprite or 2d mesh. The effect I'm trying to do looks like this:
How would I go about creating this? So far I have the following code:
float cutoffBottom = sin((IN.uv.x + speed*_Time)*period) * amp + amp;
float edge1 = cutoffBottom + 0.05;
if(IN.uv.y < edge1 && IN.uv.y > cutoffBottom){
col.r = 1;
col.g = 1;
col.b = 0;
}
if(IN.uv.y < cutoffBottom)
col.a = 0;
The above code creates a sine wave at the bottom of the sprite that looks like this bottom edge wave. I could do the same for the other 3 sides to make a square surrounded by sine waves. However I'd like to accomplish this for any arbitrary shape, not just squares. In the linked image there are sine waves that travel diagonally.
In order to recreate this, I would likely need to figure out the direction of the edges in the shader. How would I do this? Is this even the best way of making this effect? Any ideas?
Comment