with this shader
if(UV.x > 0.5)ALBEDO = vec3(0.2, 0.3, 0.8);
else ALBEDO = abs(colorEmpty.rgb );
and this gdscript
$MeshInstance3D.material_override.set_shader_parameter("colorEmpty", Color(0.2, 0.3, 0.8))
I got 2 different colors

is this a bug?

  • MikeCL replied to this.
  • I got this answer to my own question:

    This behavior is not a bug, but an intended color conversion. Depending on renderer (Vulkan, OpenGL) and config (2D, 3D) the colors can be in linear or SRGB color space. In this case Color(0.2, 0.3, 0.8) will go though color conversion when setting the uniform parameter. There are a few ways to change this, for example use Vector3 instead of Color

    Basically for me it was: "do not mix Vector3 and Color type"

    the project is a very simple one with one scene

    [gd_scene load_steps=6 format=3 uid="uid://cc0umri7ybott"]

    [ext_resource type="Script" path="res://Progress.gd" id="1_3kb6r"]
    [ext_resource type="Shader" path="res://box_progress.gdshader" id="2_b0e74"]

    [sub_resource type="ShaderMaterial" id="ShaderMaterial_erl4x"]
    render_priority = 0
    shader = ExtResource("2_b0e74")
    shader_parameter/colorEmpty = null

    [sub_resource type="QuadMesh" id="QuadMesh_t2los"]

    [sub_resource type="Environment" id="Environment_83blf"]
    background_mode = 1
    ambient_light_source = 2
    ambient_light_color = Color(1, 1, 1, 1)
    reflected_light_source = 1

    [node name="Node3D" type="Node3D"]
    script = ExtResource("1_3kb6r")

    [node name="MeshInstance3D" type="MeshInstance3D" parent="."]
    material_override = SubResource("ShaderMaterial_erl4x")
    mesh = SubResource("QuadMesh_t2los")

    [node name="Camera3D" type="Camera3D" parent="."]
    transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1.16659)
    environment = SubResource("Environment_83blf")
    projection = 1
    current = true

    progress.gd :

    extends Node3D

    func _ready():
    $MeshInstance3D.material_override.set_shader_parameter("colorEmpty", Color(0.2, 0.3, 0.8))

    shader:

    shader_type spatial;

    uniform vec4 colorEmpty;

    void fragment()
    {
    if(UV.x > 0.5)ALBEDO = vec3(0.2, 0.3, 0.8);
    else ALBEDO = abs(colorEmpty.rgb );

    }

    I think it's with this here:

    if(UV.x > 0.5)ALBEDO = vec3(0.2, 0.3, 0.8);

    try changing the 0.5 to 0.2 and see if that changes it to an 20/80 split. if that works then that is causing the issue.

    *this is just a guess as i'm a bit rusty in my shader skills at the moment.

      ucmRich UX.x > 0.5 is just a way to have 2 different behaviour and shows that the color are different even if they should not

        stephanematiz Hi, I'm not sure if this is a project or you asking for help? If it's simply trying to solve a bug, then perhaps tag it under "Help" instead of "Project"

        Update: Re-tagged to "Godot Help" due to this asking for help rather than showing a project.

        22 days later
        10 days later

        I got this answer to my own question:

        This behavior is not a bug, but an intended color conversion. Depending on renderer (Vulkan, OpenGL) and config (2D, 3D) the colors can be in linear or SRGB color space. In this case Color(0.2, 0.3, 0.8) will go though color conversion when setting the uniform parameter. There are a few ways to change this, for example use Vector3 instead of Color

        Basically for me it was: "do not mix Vector3 and Color type"