Bob Up and Down

Bob up and down to create a floating effect. Very simple shader, use with Sprite2d or TextureRect. 

Does not cross texture bounds – leave some transparent space above and below

Shader code
shader_type canvas_item;

uniform float amplitude : hint_range(0.0, 50.0) = 10.0;  // The height of the bobbing
uniform float speed : hint_range(0.0, 10.0) = 1.0;       // The speed of the bobbing

void fragment() {
    float offsetY = amplitude * sin(TIME * speed);
    COLOR = texture(TEXTURE, UV + vec2(0.0, offsetY) / 500.0);
}
Tags
bob, down, float, up
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from Rupti

Cracked Glass

Related shaders

2D Top-Down Shadows (Tilemap Ready)

vortex and shrink

Jupiter and Io

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments