Shader doesn't work, only a white rectangle is drawn

kow__kow__ Posts: 24Member

I'm trying to make a shader that smoothly changes the hue of one of my sprites. To do that, I'm converting COLOR to HSV, changing the hue and then reconverting to RGB.

I'm using Godot 3.0.2 stable.

The problem is that in the editor only a white rectangle in the top-right part of the scene is shown, and when I try to run the game I get errors and, again, only the white rectangle is drawn.

!

The error is: "error C1111: non l-value actual parameter #2 cannot be out parameter "ip""

My code is:

shader_type canvas_item;

uniform float speed = 1.0;


void fragment()
{
    vec4 color = COLOR;

    float c_max = max(max(color.r, color.g), color.b);
    float c_min = min(min(color.r, color.g), color.b);
    float delta = c_max - c_min;

    float h;
    float s;
    float v;

    if (delta == 0.0){
        h = 0.0;
    } else if (c_max == color.r) {
        h = modf((color.g - color.b) / delta, 6.0) / 6.0;
    } else if (c_max == color.g) {
        h = ((color.b - color.r) / delta + 2.0) / 6.0;
    } else {
        h = ((color.r - color.g) / delta + 4.0) / 6.0;
    }

    if (delta == 0.0) {s = 0.0;}
    else {s = delta / c_max;}

    v = c_max;

    h += modf(TIME * speed, 1.0);

    int i = int(floor(h * 6.0));
    float f = h * 6.0 - float(i);
    float p = v * (1.0 - s);
    float q = v = (1.0 - f * s);
    float t = v * (1.0 - (1.0 - f) * s);

    if (i == 0) {
        COLOR.r = v;
        COLOR.g = t;
        COLOR.b = p;
    } else if (i == 1) {
        COLOR.r = q;
        COLOR.g = v;
        COLOR.b = p;
    } else if (i == 2) {
        COLOR.r = p;
        COLOR.g = v;
        COLOR.b = t;
    } else if (i == 3) {
        COLOR.r = p;
        COLOR.g = q;
        COLOR.b = v;
    } else if (i == 4) {
        COLOR.r = t;
        COLOR.g = p;
        COLOR.b = v;
    } else {
        COLOR.r = v;
        COLOR.g = p;
        COLOR.b = q;
    }
}

Thanks in advance for your help.

Answers

  • kow__kow__ Posts: 24Member
    Answer ✓

    I fixed the error. For anyone who has the same problem, COLOR is just an output value. You get the pixel color with texture(TEXTURE, UV).

Sign In or Register to comment.