Godot: 3.0 Shader Language: increments (++) does not work

Created on 26 Aug 2017  Â·  16Comments  Â·  Source: godotengine/godot

Operating system or device, Godot version, GPU Model and driver (if graphics related):
windows 64, 73132c9, nvidia

i was trying to implement blur shader today. editor crashed multiple times while i was writing this. and finally it doesn't work (but works on shadertoy for example)

putting this on the Sprite (with standard icon as texture) and uncommenting last line will crash the editor. and there is while instead of for, because fors just don't work (known issue tho). but why is it crashing the editor??? nothing is written into the console, so i have no idea what is happening.

shader_type canvas_item;

float SCurve (float x) {
    x = x * 2.0 - 1.0;
    return -x * abs(x) * 0.5 + x + 0.5;
    //return dot(vec3(-x, 2.0, 1.0 ),vec3(abs(x), x, 1.0)) * 0.5; // possibly faster version
}

vec4 BlurH (sampler2D source, vec2 size, vec2 uv, float radius) {
    if (radius >= 1.0) {
        vec4 A = vec4(0.0); 
        vec4 C = vec4(0.0); 
        float width = 1.0 / size.x;
        float divisor = 0.0; 
        float weight = 0.0;
        float radiusMultiplier = 1.0 / radius;
        float x = -radius;
        while (x <= radius) {
            A = texture(source, uv + vec2(x * width, 0.0));
            weight = SCurve(1.0 - (abs(x) * radiusMultiplier)); 
            C += A * weight; 
            divisor += weight;
            x++;
        }
        return vec4(C.r / divisor, C.g / divisor, C.b / divisor, 1.0);
    }
    return texture(source, uv);
}

void fragment() {
    //COLOR = BlurH(TEXTURE, vec2(64.0, 64.0), UV, 20.0); //crashes even with 2.0 radius
}
bug editor

Most helpful comment

so the minimal code is now

shader_type canvas_item;

void fragment() {
    float i = 0;
    i++;
}

All 16 comments

Is it freezing or crashing with "doesn't respond"? Because, an insanely expensive shader can also look like a crash since it would slow down the editor enough to be frozen :p

leaving the crash aside (need to check it)..

I was thinking of adding an option to the texture importer plugin to
generate gaussian blurred mipmaps, this way you can blur sprites easily by
just using textureLod()

On Sat, Aug 26, 2017 at 5:01 PM, Marc notifications@github.com wrote:

Is it freezing or crashing with "doesn't respond"? Because, an insanely
expensive shader can also look like a crash since it would slow down the
editor enough to be frozen :p

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/10661#issuecomment-325158734,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AF-Z22xr---X6QjqZH4kt3A662oc-Zchks5scHmWgaJpZM4PDjs-
.

Linux, https://github.com/godotengine/godot/commit/53c0010932f9c1becb63c16243f3a00ede359989, Intel HD4000 here.

I tried your shader code and uncommented the last line but it doesn't crash or slow down the editor for me. However, the only thing that happens to the icon sprite is that it becomes invisible...

it is not expensive, because it crashes also with 4 iterations (2 radius). on windows 10 it iw like windows goes black for a few seconds and then appears standard window with running progressbar that tells that godot engine stopped working and asks whether i want to close it or debug.

Looks like you have a driver or system issue @curly-brace ..

Win7 64 bit, GTX 770, driver 385.41. This shader crashed godot and my graphics driver.

update here. i've found out the minimal shader code that will crash the editor:

shader_type canvas_item;

void fragment() {
    float i = 0.0; //will be same with int too
    while (i < 2.0) {
       i++; //crashes with and without this
    }
}

Lol, then this is probably a duplicate of #10560, as you're creating an infinite loop... ^^

@groud oh i've forgot about increment, lol. but even with increment it crashes (tested it now)

What about with i = i+1 instead of i++?

@groud yeah. works with i+=1. so there are two issues with loops - deadloop problem and ++ problem. mine here concerns increment.

@groud yeah. works with i+=1. so there are two issues with loops - deadloop problem and ++ problem. mine here concerns increment.

Awesome, could you rename the issue with something like "++ operators in shader crashes the editor" ?
We can keep the other issue for the infinite loop.

so the minimal code is now

shader_type canvas_item;

void fragment() {
    float i = 0;
    i++;
}

It's the same cause as #10687 I think, #10590 broke operators. @hpvb was looking into it.

Edit: Actually no, that PR was merged after this issue was opened.

just found out that preincrement (++x) actually works

actually preincrement does not work, it just does not crash the editor, but shader is invalid and produces white screen.

Was this page helpful?
0 / 5 - 0 ratings