Skip to content

Shader function overload with different inputs is dependent on order #107982

Closed
@Yulna

Description

@Yulna

Tested versions

  • Reproducible in; v4.4.1
    (Shader function overload was not available prior so no bug to test there)

System information

Godot v4.4.1.stable (49a5bc7) - Windows 10 (build 19045) - Multi-window, 2 monitors - Vulkan (Forward+) - dedicated AMD Radeon RX 6950 XT (Advanced Micro Devices, Inc.; 32.0.21013.1000) - AMD Ryzen 9 5900X 12-Core Processor (24 threads)

Issue description

Using function overload on shaders to use the same function name with diferent possible arguments, return options creates a shader error if the first function definition has more arguments than later ones.

The following code will create an error in shader stating the posterize needs 3 arguments if we try to use the second definition.

void posterize(in vec4 in_value, in vec4 steps, out vec4 out_value)
{
	out_value = floor(in_value * steps) / steps;
}

vec4 posterize(in vec4 in_value, in vec4 steps)
{
	return floor(in_value * steps) / steps;
}

Calling the second function (2 arguments) later in the fragment shader creates the following error

60 - Too few arguments for "posterize(vec4, vec4, vec4)" call. Expected at least 3 but received 2.

As a note the shader editor detects the 2 functions defined

Image

The code works fine sapping the order of the defintions, something like this code below will compile and work fine:

vec4 posterize(in vec4 in_value, in vec4 steps)
{
	return floor(in_value * steps) / steps;
}

void posterize(in vec4 in_value, in vec4 steps, out vec4 out_value)
{
	out_value = floor(in_value * steps) / steps;
}

Steps to reproduce

  • Create a shader function with 3 arguments.
  • Create the same shader function with 2 arguments, overloading the one you just created.
  • Try to use the second function in fragment shader.

Minimal reproduction project (MRP)

shaderoverloaderror.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions