Bounce / Wave

Make a sprite bounce or wave.

– Sine Amplitude determines the distance moved

– Sine speed determines who fast it moves in those directions

– Do Abs performs an absolute value on the vertex adjustment, so it’s more akin to a bounce

– Do Quantize quantizes the movement to the nearest value, based on quantize_to parameter.

  – E.G. Quantize to 1 will only move the sprite in units of 1. Quantize of 0.5, in units of half-pixels, etc.

Shader code
shader_type canvas_item;

group_uniforms Sine;
uniform bool do_abs;
uniform bool do_quantize;
uniform float quantize_to : hint_range(0, 2, 0.1) = 1;
uniform vec2 sine_amplitude = vec2(1.0, 0.0);
uniform vec2 sine_speed = vec2(1.0, 0.0);

void vertex() {
	vec2 s = sin(TIME * sine_speed);
	if (do_abs) {
		s = abs(s);
	}
	VERTEX += s * sine_amplitude;
	if (do_quantize) {
		VERTEX = round(VERTEX / quantize_to);
		VERTEX *= quantize_to;
	}
}
Tags
bounce, sine, wave
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 afrasier

Opacity Pulse

Related shaders

wave with rotate item

sine wave camera view shader

Gerstner Wave Ocean Shader

Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Talimpaa
12 days ago

nice

Llama_Overt_Lord
Llama_Overt_Lord
8 days ago

How do you make it move up and down, rather than side to side? Cant figure it out.