godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.27k stars 21.04k forks source link

Can't change color space of vertex colors in GLES2 using a SpatialMaterial #30701

Open MightyPrinny opened 5 years ago

MightyPrinny commented 5 years ago

Godot version: 3.1 stable

OS/device including version: GNU/Linux x64

Issue description: Vertex colors look very different in GLES2 and the "Is Srgb" toggle in the material doesn't do anything

Note: the "Is Srgb" toggle does make a difference in GLES3, but the colors look right when it's off.

Edit: This happens when I export the model in the gltf2 format, when I export it in .dae with the default collada exporter it looks bad in gles3 without "Is Srgb" turned on so I guess the issue is that you can't change the color space of vertex colors in GLES2.

Comparisons:

Blender image

Godot(GLES2) image

Godot(GLES3) image

Ace-Dragon commented 5 years ago

"Is Srgb" works for me in a recent 3.2 build using GLES3, so it could be another bug specific to that backend.

A possible workaround would be to use a ShaderMaterial and string the color output through a math operation (power set to 2.2).

clayjohn commented 5 years ago

@MightyPrinny Can you post an image comparison? Right now you are not providing enough information for anyone to help you.

MightyPrinny commented 5 years ago

@clayjohn updated with pictures

clayjohn commented 5 years ago

Here is the relevant lines of code:

https://github.com/godotengine/godot/blob/e44041ae41c6b76678f52f772abb5e4834ed40a1/scene/resources/material.cpp#L599-L604

When is_srgb is checked the code is added. But the code only runs in GLES3 as OUTPUT_IS_SRGB is always true in GLES2 and false in GLES3.

So, it looks like this is intended behaviour, but I am not sure why. The previous behaviour was that it always applied but then it was changed in 65fd37c

MightyPrinny commented 5 years ago

I don't think it's a mistake, but i'ts not generating code to convert non srgb colors to srgb in GLES2, I tried the code from the OP here https://gamedev.stackexchange.com/questions/92015/optimized-linear-to-srgb-glsl on a shader and that makes the model use the right colors.

DDru commented 4 years ago

I have same problem with vertex color on GLES2 and windows 10. In Blender (and unity) 111 In Godot v3.2.2.beta2.official 112

MightyPrinny commented 4 years ago

This should be easy to fix but nobody has done it, you can fix it yourself in a shader for now

akien-mga commented 2 years ago

Is this still reproducible in recent 3.x releases? A minimal reproduction project would be useful if it is.

yikescloud commented 1 year ago

Still has this issue in godot 3.5.2

Calinou commented 1 year ago

So, it looks like this is intended behaviour, but I am not sure why. The previous behaviour was that it always applied but then it was changed in 65fd37c

Note that we have another instance of this in the grid shader now: https://github.com/godotengine/godot/blob/fe7ed984b5a187f0fbdf531fa72f7b7479778d79/editor/plugins/spatial_editor_plugin.cpp#L5674-L5680

I'm surprised you'd need vertex colors to be handled as sRGB when rendering in GLES2. The point of Godot handling this for you is that it doesn't need a manual conversion.

clayjohn commented 1 year ago

Maybe the issue is that the vertex colors are baked in linear space and need to be converted to srgb?

yikescloud commented 1 year ago

image Seems GLTF and FBX have different behavior here, and the is_SRGB checkbox on material won't change anything Here is the minimal reproduce project VertexColorSpace.zip

clayjohn commented 1 year ago

@yikescloud The difference between FBZ and GLTF looks like an importer bug. The difference exists in the GLES3 renderer as well, and isn't fixed by toggling is_srgb

yikescloud commented 1 year ago

image In GLES3, gltf looks correct and FBX looks brighter(is_SRGB off) if turn on is_srgb on , then it looks same as GLTF2

yikescloud commented 1 year ago

@clayjohn I import gltf and fbx as separate .mesh file, and I found that it seems importer apply a srgb_to_linear() on GLTF vertex color cause the issue, while the GLTF vertex color is linear. But I haven't found where the issue code is located. image