Help with vertex shader

Godot Version

godot 4.2


Hi I’m new to shaders and I’m trying to create one that appears as a ball bouncing. So far i managed to get the effect I wanted but the issue is the bouncyness extends far beyond the actual borders of the image on the upper edge(see screenshot)
Is there a way to limit the extension on the upper side ? (image is 250x250)
I’ve tried using max() or clamp() on the y axis to -125 but i only seem to mess it up more cause I’m a noob and bad at math and logic

here’s the code:

void vertex() {
	if (VERTEX.y < 0.00){
		VERTEX += vec2(0, sin(TIME * 4.00) * 100.00);

thanks for the help!

I think you were almost there; is this more what you wanted?

shader_type canvas_item;

uniform float amount = 32.0;
uniform float speed = 10.0;

void vertex() {
	if (VERTEX.y < 0.1){
		VERTEX.y += (sin(TIME * speed) + 1.0) * amount;

Your issue was that sin() oscillates from -1 and 1. When it was negative, it overextended your image bounds. By adding 1 before multiplying by amount, we avoid negative offsets.

Hope that helps! :slight_smile:

1 Like

You are my savior!
Thank you so much. I’m a bit dumb with these things and this is exactly what I needed.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.