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

unshaded mesh is brighter than albedo set in fragment shader with vulkan renderer #70797

Closed
jmdejong opened this issue Jan 1, 2023 · 7 comments

Comments

@jmdejong
Copy link

jmdejong commented Jan 1, 2023

Godot version

v4.0.beta10.official.d0398f62f

System information

archlinux; vulkan on dedicated NVIDIA GeForce RTX 3060 Laptop GPU; opengl3 on integrated AMD Radeon Graphics (renoir, LLVM 14.0.6, DRM 3.49, 6.1.1-arch1-1)

Issue description

When using the fragment shader to set an albedo then the color that is rendered much too bright, even when the mesh is unshaded.
This happens with the vulkan renderer, but it does not seem to happen with the opengl3 renderer.

With vulkan renderer :
too bright texture from vulkan renderer

With the opengl3 renderer this does not occur:
texture with correct brightness but missing interpolation from opengl3 renderer
(The lack of interpolation seems to be a different problem)

Used texture: original grass texture

Shader:

render_mode world_vertex_coords, unshaded;

uniform sampler2D tex;

void fragment() {
	ALBEDO = texture(tex, UV).xyz;
}

This example uses the render mode unshaded for simplicity, but when lightning calculations do occur then this shader still shows a brighter color than expected

Steps to reproduce

View a mesh that uses the shader above and is given a texture as parameter in a project with the vulkan renderer

Minimal reproduction project

texturebrightness.zip

@jmdejong
Copy link
Author

jmdejong commented Jan 1, 2023

I just found out that this does not seem to be related to textures: setting the albedo to vec3(0.0, 0.5, 0.0) will result in the mesh having color #00bc00 in the vulkan renderer. With the opengl3 renderer it is #008000, which I would expect.

@jmdejong jmdejong changed the title Rendering a texture in fragment shader makes texture too bright unshaded mesh is brighter than albedo set in fragment shader in vulkan renderer Jan 1, 2023
@jmdejong jmdejong changed the title unshaded mesh is brighter than albedo set in fragment shader in vulkan renderer unshaded mesh is brighter than albedo set in fragment shader with vulkan renderer Jan 1, 2023
@Calinou
Copy link
Member

Calinou commented Jan 1, 2023

This is likely a sRGB-to-linear conversion issue.

You can fix this by adding : source_color; as a hint to the texture uniform: uniform sampler2D tex : source_color;

@jmdejong
Copy link
Author

jmdejong commented Jan 1, 2023

Yes, adding that fixed the difference in color

@jmdejong
Copy link
Author

jmdejong commented Jan 1, 2023

When setting the albedo without a texture there is still a difference in color.

albedo_squares
The left square is a standardmaterial that is unshaded and has albedo #008000 while the right square is from a shader that sets the albedo to vec3(0.0, 0.5, 0.0). On the opengl3 backend both squares are the same color, but on vulkan the right one is brighter.

Is this something that can be fixed? Or should it be documented and accepted? (for me it was not yet clear from the documentation that this could happen)

used shader:

render_mode unshaded;

void fragment() {
	ALBEDO = vec3(0.0, 0.5, 0.0);
}

Minimal reproduction project:
albedobrightness.zip

@clayjohn
Copy link
Member

This isn't a bug, you are just forgetting the source_color hint when you set your uniform sampler2D See the docs for uniforms here:
https://docs.godotengine.org/en/latest/tutorials/shaders/shader_reference/shading_language.html#uniforms

In the second MRP you are setting the quads to two different colors. The quad on the left is in sRGB space while the quad on the right is in linear space.

@clayjohn clayjohn closed this as not planned Won't fix, can't repro, duplicate, stale Jan 14, 2023
@github-project-automation github-project-automation bot moved this from To Assess to Done in 4.x Priority Issues Jan 14, 2023
@clayjohn clayjohn removed this from the 4.0 milestone Jan 14, 2023
@kb173
Copy link

kb173 commented Mar 14, 2024

I hope it's okay to add something here because this issue was a top search result while debugging a similar problem I had:

Even with source_color or no custom shader (just a standard material with an Albedo texture), my texture appeared too bright in the editor. I set the material to unshaded and compared screenshots with the original texture to confirm that it was quite a bit too bright.

The reason was that Godot's viewport is set to the Filmic tonemap by default. It can be changed to Linear here:

image

I know this is intended, but I figured adding a comment here might help people with the same problem in the future.

@souplamp
Copy link
Contributor

souplamp commented Jul 8, 2024

I know this is intended, but I figured adding a comment here might help people with the same problem in the future.

I am from the future. Thank you.

PS. If anyone is trying to use source_color (as mentioned above) in the VisualShader editor, make sure to go to your Texture2D node dropdown where it says "Data" and change it to "Color".

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