Skip to content

CanvasItem shaders provide texture color in COLOR variable contrary to the documentation #8280

@derkork

Description

@derkork

Godot version

v4.1.stable.mono.official [970459615]

System information

Windows 11, Forward+, Nvidia GTX 4080, driver version 537.58

Issue description

The documentation for CanvasItem fragment shaders states:

Certain Nodes (for example, Sprite2Ds) display a texture by default. However, when a custom fragment function is attached to these nodes, the texture lookup needs to be done manually. Godot does not provide the texture color in the COLOR built-in variable; to read the texture color for such nodes, use ...

However both the visual and the text based shader allow multiplying the COLOR variable with some other color and getting the correct result without a texture lookup.

image

So either the documentation is no longer up-to-date or the engine is behaving differently from what is documented. I cannot say which is the intended behaviour.

Steps to reproduce

Make a Sprite2D from the default icon by dragging the icon into the scene view. Then assign a shader with this code to its material:

shader_type canvas_item;


void fragment() {
	COLOR.rgb = COLOR.rgb * vec3(1.0,0.0,0.0);
}

The result will be a red-tinted default icon, while according to the documentation it should not be since we never do a texture lookup in the shader.

Minimal reproduction project

example.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:manualIssues and PRs related to the Manual/Tutorials section of the documentationbugtopic:shaders

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions