Need Help Curving platforms

Godot Version

4.3

Question

Trying to curve platforms and the shader code Im using is not working. Can someone explain to me why and/or give me steps on how to fix it.

shader_type canvas_item;
uniform float curve_strength : hint_range(0.0, 1.0);

void fragment() {
    vec2 uv = FRAGCOORD.xy / SCREEN_PIXEL_SIZE; // Normalize coordinates
    vec2 center = vec2(0.5, 0.5); // Center of the texture

    // Calculate the distance from the center
    float dist = distance(uv, center);

    // Apply the curvature effect
    if (dist < 0.5) {
        float angle = acos(dist); // Get the angle
        float curve = sin(angle * 2.0) * curve_strength; // Curve effect
        uv.y += curve; // Adjust the UV based on the curve
    }

    // Set the final color
    COLOR = texture(TEXTURE, uv);
}

in what way is it not working. is it having an effect, but the wrong one? or is nothing happening?

nothing is happening

can you make something happen by just doing COLOR = vec4(1.0,0.0,1.0,1.0); like are you sure the shader is even applied to your canvas


I have it applied to the canvasitem and nothing still works

is that magenta color from the shader?

yes from the COLOR = vec4(1.0,0.0,1.0,1.0); line

okay so it looks like the shader is working in the material preview, are you actually putting this material onto anything though? like a canvas rectangle for example


I have it attached to the meshinstace of a staticbody2d

this shader you’ve posted above is a postprocessing shader, it needs to put put onto a canvas texture. or maybe what you really want here is a vertex shader if you just want to add curvature to this one platform

1 Like