Hi. I have a custom EditorPanel that shows a few material albedo textures (in TextureRects). How come they are so dark compared to the original (right) and the unshaded 3d view? Is there anything I can do to fix this? The only import setting that made a difference is to set HDR to 'Force RGBE', but that makes the texture appear too bright in the 3d view. I also experimented with EditorResourcePreview, but that puts the material on a sphere, which is not suitable here.

  • You'll have to write a shader for your preview that converts from sRGB to linear (or vice versa). The code is pretty simple, you can find the algorithm online, but it may not be the exact calculations Godot it doing. However, it should look pretty close, if not identical.

Color management. Godot imports/reads the sRGB image file and then converts it to linear color space.
https://matt77hias.github.io/blog/2018/07/01/linear-gamma-and-sRGB-color-spaces.html
https://tiberius-viris.artstation.com/blog/3ZBO/color-space-management-srgb-linear-and-log

edit: additionally worth noting that the GLSL 2 renderer is sRGB output while GLSL 3 is not:
https://docs.godotengine.org/en/stable/tutorials/rendering/gles2_gles3_differences.html#color-space

    Megalomaniak
    Thanks for the explanation, although the linked articles went slightly over my head. I now understand the difference and need for linear light vs sRGB, but I don't really know how to apply that to my problem. I exported the textures with 8 bit colour depth in Gimp's built-in sRGB profile. Is there anything I can to do make the textures look identical in 3D and in the GUI? I suppose I could try to add my own resource previewer, but that seems more like circumventing the problem. Any advice?

    In godot file browser navigate to your texture, select/highlight it then check the import tab, there should be a setting there I think. Related to the color space.

      You'll have to write a shader for your preview that converts from sRGB to linear (or vice versa). The code is pretty simple, you can find the algorithm online, but it may not be the exact calculations Godot it doing. However, it should look pretty close, if not identical.

        cybereality
        That sounds exactly like what I need to do, thanks!

        Megalomaniak
        I checked all options, but I don't think any help me achieve an identical look in the editor GUI and in-game.

        cybereality
        Cool, thanks for sharing. I cobbled something together myself, but the result is too bright and I don't know anything about the sRGB standard or GLSL to fix it.

        So I'll gladly steal it if it's good 🙂

        shader_type canvas_item;
        uniform sampler2D albedo;
        
        // source: https://www.shadertoy.com/view/4tXcWr
        vec4 fromLinear(vec4 linearRGB)
        {
            bvec4 cutoff = lessThan(linearRGB, vec4(0.0031308));
            vec4 higher = vec4(1.055)*pow(linearRGB, vec4(1.0/2.4)) - vec4(0.055);
            vec4 lower = linearRGB * vec4(12.92);
            return mix(higher, lower, cutoff);
        }
        
        void vertex() {}
        
        void fragment() 
        {
            COLOR = fromLinear(texture(albedo, UV));
        }

          cybereality sRGB gamma is 2.2 and linear is linear so 1.0. n * 0.4545 should get ~ close to 1 then from sRGB gamma 2.2. I see that const float SRGB_GAMMA = 1.0 / 2.2;in there which should give that same ~0.4545 ish value though probably more precise.

          TL;DR: should work for godot fine then.

          lincore So I'll gladly steal it if it's good

          You'll want to look through this page in the docs if you are going to be converting GLSL into godot shaderlang:
          https://docs.godotengine.org/en/stable/tutorials/shaders/converting_glsl_to_godot_shaders.html

            cybereality You'll have to write a shader for your preview that converts from sRGB to linear (or vice versa).

            Can this be included in the standard package Godot?