From 644fb2b67935b443b3ffede9412f5592b7ab24e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Thu, 3 Jul 2025 14:07:58 +0200 Subject: [PATCH] Fix #98654: GPUOffScreen example has wrong color management This was because the display shader never did the correct color transformation. This is a risky fix as it expects all input texture to be in the correct colorspace (srgb). If they aren't this will produce darker result. If this is a huge issue we can introduce a global setting (like line width) to set if the attached texture is in srgb space or linear. This would avoid to change the drawing code all over the place. Pull Request: https://projects.blender.org/blender/blender/pulls/141237 --- source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl | 3 +++ source/blender/gpu/shaders/gpu_shader_image_frag.glsl | 3 +++ source/blender/gpu/shaders/infos/gpu_shader_2D_image_info.hh | 3 +++ .../gpu/shaders/infos/gpu_shader_2D_image_rect_color_info.hh | 3 +++ source/blender/gpu/shaders/infos/gpu_shader_3D_image_info.hh | 3 +++ 5 files changed, 15 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl index 6c93dd81069..69c946eb121 100644 --- a/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl @@ -6,7 +6,10 @@ FRAGMENT_SHADER_CREATE_INFO(gpu_shader_2D_image_rect_color) +#include "gpu_shader_colorspace_lib.glsl" + void main() { fragColor = texture(image, texCoord_interp) * color; + fragColor = blender_srgb_to_framebuffer_space(fragColor); } diff --git a/source/blender/gpu/shaders/gpu_shader_image_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_frag.glsl index 87a78d8c122..fdef13a437b 100644 --- a/source/blender/gpu/shaders/gpu_shader_image_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_image_frag.glsl @@ -6,7 +6,10 @@ FRAGMENT_SHADER_CREATE_INFO(gpu_shader_2D_image_common) +#include "gpu_shader_colorspace_lib.glsl" + void main() { fragColor = texture(image, texCoord_interp); + fragColor = blender_srgb_to_framebuffer_space(fragColor); } diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_image_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_info.hh index c5bb852cc9a..75bb6b65461 100644 --- a/source/blender/gpu/shaders/infos/gpu_shader_2D_image_info.hh +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_info.hh @@ -11,6 +11,8 @@ # include "gpu_glsl_cpp_stubs.hh" # include "GPU_shader_shared.hh" + +# include "gpu_srgb_to_framebuffer_space_info.hh" #endif #include "gpu_interface_info.hh" @@ -24,4 +26,5 @@ FRAGMENT_OUT(0, float4, fragColor) PUSH_CONSTANT(float4x4, ModelViewProjectionMatrix) SAMPLER(0, sampler2D, image) VERTEX_SOURCE("gpu_shader_2D_image_vert.glsl") +ADDITIONAL_INFO(gpu_srgb_to_framebuffer_space) GPU_SHADER_CREATE_END() diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_image_rect_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_rect_color_info.hh index c04706d8fef..5a41ab26cf8 100644 --- a/source/blender/gpu/shaders/infos/gpu_shader_2D_image_rect_color_info.hh +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_rect_color_info.hh @@ -11,6 +11,8 @@ # include "gpu_glsl_cpp_stubs.hh" # include "GPU_shader_shared.hh" + +# include "gpu_srgb_to_framebuffer_space_info.hh" #endif #include "gpu_interface_info.hh" @@ -26,5 +28,6 @@ PUSH_CONSTANT(float4, rect_geom) SAMPLER(0, sampler2D, image) VERTEX_SOURCE("gpu_shader_2D_image_rect_vert.glsl") FRAGMENT_SOURCE("gpu_shader_image_color_frag.glsl") +ADDITIONAL_INFO(gpu_srgb_to_framebuffer_space) DO_STATIC_COMPILATION() GPU_SHADER_CREATE_END() diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_image_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_3D_image_info.hh index 26b3f816a78..61ca25d902f 100644 --- a/source/blender/gpu/shaders/infos/gpu_shader_3D_image_info.hh +++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_image_info.hh @@ -11,6 +11,8 @@ # include "gpu_glsl_cpp_stubs.hh" # include "GPU_shader_shared.hh" + +# include "gpu_srgb_to_framebuffer_space_info.hh" #endif #include "gpu_interface_info.hh" @@ -24,6 +26,7 @@ FRAGMENT_OUT(0, float4, fragColor) PUSH_CONSTANT(float4x4, ModelViewProjectionMatrix) SAMPLER(0, sampler2D, image) VERTEX_SOURCE("gpu_shader_3D_image_vert.glsl") +ADDITIONAL_INFO(gpu_srgb_to_framebuffer_space) GPU_SHADER_CREATE_END() GPU_SHADER_CREATE_INFO(gpu_shader_3D_image)