Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using set_shader_param with a color returns non-linear colors #28504

Open
nathanfranke opened this issue Apr 28, 2019 · 8 comments
Open

Using set_shader_param with a color returns non-linear colors #28504

nathanfranke opened this issue Apr 28, 2019 · 8 comments

Comments

@nathanfranke
Copy link
Contributor

nathanfranke commented Apr 28, 2019

Godot version: v3.1.stable.mono.official (LATEST)

OS/device including version: Ubuntu 18.04 bionic,
Kernel: x86_64 Linux 4.18.0-17-generic

Issue description:
If using colors to transfer values (Since sampler2d is our only array), The values seem to be offset by 0.05 and put through a square root function

If the red value is set to sqrt(0.55), the line seems to appear in the middle

image

Steps to reproduce:

  • Use set_shader_param('param_name', Color(0.5, 1.0, 1.0)) to set a specific color
  • When accessing the color in the shader, the values will be mutated

Minimal reproduction project:
GodotTestProject.zip

@clayjohn
Copy link
Member

What does it look like on the shader side? Are you using hint_color?

@nathanfranke
Copy link
Contributor Author

Shader:

shader_type spatial;
render_mode specular_disabled;

uniform vec4 param;

void fragment() {
	ROUGHNESS = 1.0;
	METALLIC = 0.0;
	SPECULAR = 0.0;
	
	ALBEDO = vec3(abs(param.x - UV.x) * 10.0);
}

I have not tried hint_color, but I won't be able to use it because my actual project uses sampler2D. I get the error "Color hint is for vec4 only"

@clayjohn
Copy link
Member

clayjohn commented May 1, 2019

Its because you are using a color. It looks like the engine is converting to sRGB for you because you are passing in a color instead of a vector. The problem goes away if you use a vector.

@nathanfranke
Copy link
Contributor Author

If I were to pass in a Vector instead of a Color, how would I specify alpha? Godot does not have a Vector4 implementation.

As for hint_color, I am not able to use this flag since my main project uses a sampler2D and I need to pass a variable amount of data

@clayjohn
Copy link
Member

Sampler2D won't have this problem as it is imported as linear by default unless you use hint_use_as_albedo

@Calinou
Copy link
Member

Calinou commented Oct 11, 2019

As a workaround, is this allowed in the shader language? I haven't tried.

ALBEDO = vec3(abs(param.x - UV.x) * 10.0);
ALBEDO.a = 0.5;

@nathanfranke
Copy link
Contributor Author

If I'm not mistaken, wouldn't this just make the mesh transparent? (If it had that flag enabled)

@nathanfranke nathanfranke changed the title Using set_shader_param with a color/vec4 uses square root values Using set_shader_param with a color returns non-linear colors Oct 16, 2019
@nathanfranke
Copy link
Contributor Author

nathanfranke commented Dec 2, 2019

As a workaround, you can convert all your data using this algorithm:
1.055 * pow(v, 1.0 / 2.4) - 0.055

Updated Test Project
GodotTestProject.zip

Neither "hint_color" nor "hint_albedo" fix the issue. Also, samplers do encounter this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants