Page MenuHome
Paste P1213

sRGB color corrected viewport compositing.
ActivePublic

Authored by Clément Foucault (fclem) on Wed, Jan 15, 12:00 AM.
diff --git a/source/blender/draw/engines/overlay/overlay_antialiasing.c b/source/blender/draw/engines/overlay/overlay_antialiasing.c
index 751c6dc7016..fdc3ac3eac7 100644
--- a/source/blender/draw/engines/overlay/overlay_antialiasing.c
+++ b/source/blender/draw/engines/overlay/overlay_antialiasing.c
@@ -83,7 +83,7 @@ void OVERLAY_antialiasing_init(OVERLAY_Data *vedata)
GPUTexture *line_tex = NULL;
if (pd->antialiasing.enabled) {
- DRW_texture_ensure_fullscreen_2d(&txl->overlay_color_tx, GPU_RGBA8, DRW_TEX_FILTER);
+ DRW_texture_ensure_fullscreen_2d(&txl->overlay_color_tx, GPU_SRGB8_A8, DRW_TEX_FILTER);
DRW_texture_ensure_fullscreen_2d(&txl->overlay_line_tx, GPU_RGBA8, 0);
color_tex = txl->overlay_color_tx;
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c
index 65365ef7119..390c1e784e9 100644
--- a/source/blender/draw/intern/draw_common.c
+++ b/source/blender/draw/intern/draw_common.c
@@ -173,14 +173,12 @@ void DRW_globals_update(void)
invert_v2(gb->sizeViewportInv);
/* Color management. */
- if (!DRW_state_do_color_management()) {
- float *color = gb->UBO_FIRST_COLOR;
- do {
- /* TODO more accurate transform. */
- srgb_to_linearrgb_v4(color, color);
- color += 4;
- } while (color != gb->UBO_LAST_COLOR);
- }
+ float *color = gb->UBO_FIRST_COLOR;
+ do {
+ /* TODO more accurate transform. */
+ srgb_to_linearrgb_v4(color, color);
+ color += 4;
+ } while (color != gb->UBO_LAST_COLOR);
if (G_draw.block_ubo == NULL) {
G_draw.block_ubo = DRW_uniformbuffer_create(sizeof(GlobalsUboStorage), gb);
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 3174edb0c05..ac1e0b0f6ba 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -319,6 +319,8 @@ void DRW_transform_to_display(GPUTexture *tex, bool use_view_transform, bool use
GPU_texture_bind(tex, 0); /* OCIO texture bind point is 0 */
+ glDisable(GL_FRAMEBUFFER_SRGB);
+
float mat[4][4];
unit_m4(mat);
immUniformMatrix4fv("ModelViewProjectionMatrix", mat);
@@ -343,6 +345,8 @@ void DRW_transform_to_display(GPUTexture *tex, bool use_view_transform, bool use
else {
immUnbindProgram();
}
+
+ glEnable(GL_FRAMEBUFFER_SRGB);
}
/* Draw texture to framebuffer without any color transforms */
diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index 19c7386ad6d..b728a27d55d 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -98,6 +98,7 @@ typedef enum eGPUTextureFormat {
GPU_R11F_G11F_B10F,
GPU_DEPTH32F_STENCIL8,
GPU_DEPTH24_STENCIL8,
+ GPU_SRGB8_A8,
/* Texture only format */
GPU_RGB16F,
@@ -123,7 +124,6 @@ typedef enum eGPUTextureFormat {
/* Special formats texture only */
#if 0
- GPU_SRGB8_A8,
GPU_SRGB8,
GPU_RGB9_E5,
GPU_COMPRESSED_RG_RGTC2,
diff --git a/source/blender/gpu/intern/gpu_framebuffer.c b/source/blender/gpu/intern/gpu_framebuffer.c
index a531c22365c..5cb9943a86c 100644
--- a/source/blender/gpu/intern/gpu_framebuffer.c
+++ b/source/blender/gpu/intern/gpu_framebuffer.c
@@ -513,6 +513,7 @@ void GPU_framebuffer_bind(GPUFrameBuffer *fb)
if (GPU_framebuffer_active_get() != fb) {
glBindFramebuffer(GL_FRAMEBUFFER, fb->object);
+ glEnable(GL_FRAMEBUFFER_SRGB);
}
gpu_framebuffer_current_set(fb);
@@ -547,6 +548,8 @@ void GPU_framebuffer_restore(void)
if (GPU_framebuffer_active_get() != NULL) {
glBindFramebuffer(GL_FRAMEBUFFER, GPU_framebuffer_default());
gpu_framebuffer_current_set(NULL);
+
+ glDisable(GL_FRAMEBUFFER_SRGB);
}
}
diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c
index 1feb5b7732d..7bf74bf7600 100644
--- a/source/blender/gpu/intern/gpu_texture.c
+++ b/source/blender/gpu/intern/gpu_texture.c
@@ -183,6 +183,7 @@ static int gpu_get_component_count(eGPUTextureFormat format)
case GPU_RGBA16F:
case GPU_RGBA16:
case GPU_RGBA32F:
+ case GPU_SRGB8_A8:
return 4;
case GPU_RGB16F:
case GPU_R11F_G11F_B10F:
@@ -221,7 +222,7 @@ static void gpu_validate_data_format(eGPUTextureFormat tex_format, eGPUDataForma
}
}
/* Byte formats */
- else if (ELEM(tex_format, GPU_R8, GPU_RG8, GPU_RGBA8, GPU_RGBA8UI)) {
+ else if (ELEM(tex_format, GPU_R8, GPU_RG8, GPU_RGBA8, GPU_RGBA8UI, GPU_SRGB8_A8)) {
BLI_assert(ELEM(data_format, GPU_DATA_UNSIGNED_BYTE, GPU_DATA_FLOAT));
}
/* Special case */
@@ -349,6 +350,7 @@ static uint gpu_get_bytesize(eGPUTextureFormat data_type)
case GPU_DEPTH_COMPONENT32F:
case GPU_RGBA8UI:
case GPU_RGBA8:
+ case GPU_SRGB8_A8:
case GPU_R11F_G11F_B10F:
case GPU_R32F:
case GPU_R32UI:
@@ -398,6 +400,8 @@ static GLenum gpu_get_gl_internalformat(eGPUTextureFormat format)
return GL_RGBA8;
case GPU_RGBA8UI:
return GL_RGBA8UI;
+ case GPU_SRGB8_A8:
+ return GL_SRGB8_ALPHA8;
case GPU_R32F:
return GL_R32F;
case GPU_R32UI:
diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c
index 972ff87ebcf..def37f43531 100644
--- a/source/blender/gpu/intern/gpu_viewport.c
+++ b/source/blender/gpu/intern/gpu_viewport.c
@@ -391,7 +391,7 @@ static void gpu_viewport_default_fb_create(GPUViewport *viewport, const bool hig
bool ok = true;
dtxl->color = GPU_texture_create_2d(
- size[0], size[1], high_bitdepth ? GPU_RGBA16F : GPU_RGBA8, NULL, NULL);
+ size[0], size[1], high_bitdepth ? GPU_RGBA16F : GPU_SRGB8_A8, NULL, NULL);
dtxl->depth = GPU_texture_create_2d(size[0], size[1], GPU_DEPTH24_STENCIL8, NULL, NULL);
if (!(dtxl->depth && dtxl->color)) {
@@ -432,7 +432,7 @@ static void gpu_viewport_default_multisample_fb_create(GPUViewport *viewport)
bool ok = true;
dtxl->multisample_color = GPU_texture_create_2d_multisample(
- size[0], size[1], GPU_RGBA8, NULL, samples, NULL);
+ size[0], size[1], GPU_SRGB8_A8, NULL, samples, NULL);
dtxl->multisample_depth = GPU_texture_create_2d_multisample(
size[0], size[1], GPU_DEPTH24_STENCIL8, NULL, samples, NULL);
@@ -544,8 +544,12 @@ void GPU_viewport_draw_to_screen(GPUViewport *viewport, const rcti *rect)
glUniform4f(GPU_shader_get_uniform_ensure(shader, "rect_geom"), x1, y1, x2, y2);
glUniform4f(GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_COLOR), 1.0f, 1.0f, 1.0f, 1.0f);
+ glEnable(GL_FRAMEBUFFER_SRGB);
+
GPU_draw_primitive(GPU_PRIM_TRI_STRIP, 4);
+ glDisable(GL_FRAMEBUFFER_SRGB);
+
GPU_texture_unbind(color);
}