0 votes

The following 2D shader is used to distort a 2D object as seen is this video:

Sample image at: https://www.dropbox.com/s/3l1f26r59hp7g1h/fear-me-2.gif?dl=0

shader_type canvas_item;

render_mode blend_mix;

uniform float speed = 2.0;
uniform float minStrength : hint_range(0.0, 1.0) = 0.5;
uniform float maxStrength : hint_range(0.0, 1.0) = 1.0;
uniform float strengthScale = 100.0;
uniform float interval = 3.5;
uniform float detail = 1.0;
uniform float distortion : hint_range(0.0, 1.0) = 0.5;
uniform float heightOffset = 0;

float getWind(vec2 vertex, vec2 uv, float timer){
    vec2 pos = mix(vec2(1.0), vertex, distortion).xy;
    float time = timer * speed + pos.x * pos.y;
    float diff = pow(maxStrength - minStrength, 2.0);
    float strength = clamp(minStrength + diff + sin(time / interval) * diff, minStrength, maxStrength) * strengthScale;
    float wind = (sin(time) + cos(time * detail)) * strength * max(0.0, (1.0-uv.y) - heightOffset);

    return wind;
    }

void vertex() {
    VERTEX.y += getWind(VERTEX.xy, UV, TIME);
}

It is working great on-screen in the editor when I play an animation that turns the shader on by setting the HeightOffset from 1.0 to 0.1, and then a character interacts with the object being distorted by the shader.

However, when I run the scene using F6 to test it externally, or do an export build, the shader starts appropriately, then stutters and freezes though there are no errors shown in the console window.

I tried increasing the shader render priority but it did not make any difference.

Godot version 3.3.2 Stable Official on Windows 7 64 bit pro
in Engine by (16 points)

Very odd... did you tried deactivate the shader and reactivate it gradually? This will show you where it breaks.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.