Godot: Shader language doesn't allow assigning constants with constant arithmetic

Created on 23 Nov 2019  路  3Comments  路  Source: godotengine/godot

Godot version: Git https://github.com/godotengine/godot/commit/80b1604fa95b048307815c5eee96426942dd207a

OS/device including version: Fedora 31, NVIDIA GeForce GTX 1080

Issue description:

The shader language doesn't seem to accept constants that use arithmetic operations. In comparison, this seems to work in raw GLSL (tested in SHADERed).

Steps to reproduce:

Paste the following shader into a ColorRect node's material:

shader_type canvas_item;

const float QUARTER_COLOR = 1.0 / 1024.0; // 0.0009765625

void fragment() {
    COLOR = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0);
    vec4 col = COLOR;

    // Increase/decrease the pixel colour values slightly in a 
    // chessboard pattern to achieve a simple dithering against banding.
    // Assume 8-bit RGB values and offset values a bit to affect rounding.
    if (mod(FRAGCOORD.x + FRAGCOORD.y, 2) == 1.0) {
        COLOR.rgb += vec3(QUARTER_COLOR);
    } else {
        COLOR.rgb -= vec3(QUARTER_COLOR);
    }
}

This will result in the error message: error(3): Expected constant expression after '='

Minimal reproduction project: test_dithering.zip

bug shaders

Most helpful comment

I will look to fix this...

All 3 comments

I will look to fix this...

This is still not fixed btw

@arthur109 Please open a new issue with a minimal reproduction project attached.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SleepProgger picture SleepProgger  路  3Comments

nunodonato picture nunodonato  路  3Comments

ducdetronquito picture ducdetronquito  路  3Comments

timoschwarzer picture timoschwarzer  路  3Comments

blurymind picture blurymind  路  3Comments