Commit: 2616a0a9d6eba0b48164cf592488b83c7a7aa83c
Author: Clément Foucault
Date:   Sun Jan 26 17:32:53 2020 +0100
Branches: draw-colormanagement
https://developer.blender.org/rB2616a0a9d6eba0b48164cf592488b83c7a7aa83c

GPUViewport: Add fallback colormanagment

Just assume sRGB display and no color correction.

===================================================================

M       source/blender/gpu/CMakeLists.txt
M       source/blender/gpu/GPU_shader.h
M       source/blender/gpu/intern/gpu_shader.c
M       source/blender/gpu/intern/gpu_viewport.c
R067    source/blender/gpu/shaders/gpu_shader_image_linear_frag.glsl    
source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl

===================================================================

diff --git a/source/blender/gpu/CMakeLists.txt 
b/source/blender/gpu/CMakeLists.txt
index 8daeda67c80..0cd8cbb3bc2 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -167,7 +167,7 @@ data_to_c_simple(shaders/gpu_shader_2D_image_rect_vert.glsl 
SRC)
 data_to_c_simple(shaders/gpu_shader_2D_image_multi_rect_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_image_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_image_desaturate_frag.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_image_linear_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_overlays_merge_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_image_shuffle_color_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_image_mask_uniform_color_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_image_modulate_alpha_frag.glsl SRC)
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index e877646310b..1339873ec67 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -183,7 +183,7 @@ typedef enum eGPUBuiltinShader {
   GPU_SHADER_3D_DEPTH_ONLY,
   GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR,
   /* basic image drawing */
-  GPU_SHADER_2D_IMAGE_LINEAR_TO_SRGB,
+  GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE,
   GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR,
   GPU_SHADER_2D_IMAGE_MASK_UNIFORM_COLOR,
   /**
diff --git a/source/blender/gpu/intern/gpu_shader.c 
b/source/blender/gpu/intern/gpu_shader.c
index ae2c7864e36..c950a1daaa5 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -80,7 +80,7 @@ extern char datatoc_gpu_shader_2D_nodelink_vert_glsl[];
 
 extern char datatoc_gpu_shader_3D_image_vert_glsl[];
 extern char datatoc_gpu_shader_image_frag_glsl[];
-extern char datatoc_gpu_shader_image_linear_frag_glsl[];
+extern char datatoc_gpu_shader_image_overlays_merge_frag_glsl[];
 extern char datatoc_gpu_shader_image_color_frag_glsl[];
 extern char datatoc_gpu_shader_image_desaturate_frag_glsl[];
 extern char datatoc_gpu_shader_image_varying_color_frag_glsl[];
@@ -1008,10 +1008,10 @@ static const GPUShaderStages 
builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
             .vert = datatoc_gpu_shader_2D_smooth_color_vert_glsl,
             .frag = datatoc_gpu_shader_2D_smooth_color_dithered_frag_glsl,
         },
-    [GPU_SHADER_2D_IMAGE_LINEAR_TO_SRGB] =
+    [GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE] =
         {
             .vert = datatoc_gpu_shader_2D_image_vert_glsl,
-            .frag = datatoc_gpu_shader_image_linear_frag_glsl,
+            .frag = datatoc_gpu_shader_image_overlays_merge_frag_glsl,
         },
     [GPU_SHADER_2D_IMAGE] =
         {
diff --git a/source/blender/gpu/intern/gpu_viewport.c 
b/source/blender/gpu/intern/gpu_viewport.c
index d459e38e1df..7daa0087091 100644
--- a/source/blender/gpu/intern/gpu_viewport.c
+++ b/source/blender/gpu/intern/gpu_viewport.c
@@ -522,34 +522,35 @@ void GPU_viewport_draw_to_screen(GPUViewport *viewport, 
const rcti *rect)
   }
 
   if (!use_ocio) {
-    /* TODO fallback. */
+    immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE);
+    immUniform1i("image_texture", 0);
+    immUniform1i("overlays_texture", 1);
   }
-  else {
-    GPU_texture_bind(color, 0);
-    GPU_texture_bind(color_overlay, 1);
 
-    immBegin(GPU_PRIM_TRI_STRIP, 4);
+  GPU_texture_bind(color, 0);
+  GPU_texture_bind(color_overlay, 1);
 
-    immAttr2f(texco, halfx, halfy);
-    immVertex2f(pos, x1, y1);
-    immAttr2f(texco, halfx + 1.0f, halfy);
-    immVertex2f(pos, x2, y1);
-    immAttr2f(texco, halfx, halfy + 1.0f);
-    immVertex2f(pos, x1, y2);
-    immAttr2f(texco, halfx + 1.0f, halfy + 1.0f);
-    immVertex2f(pos, x2, y2);
+  immBegin(GPU_PRIM_TRI_STRIP, 4);
 
-    immEnd();
+  immAttr2f(texco, halfx, halfy);
+  immVertex2f(pos, x1, y1);
+  immAttr2f(texco, halfx + 1.0f, halfy);
+  immVertex2f(pos, x2, y1);
+  immAttr2f(texco, halfx, halfy + 1.0f);
+  immVertex2f(pos, x1, y2);
+  immAttr2f(texco, halfx + 1.0f, halfy + 1.0f);
+  immVertex2f(pos, x2, y2);
 
-    GPU_texture_unbind(color);
-    GPU_texture_unbind(color_overlay);
-  }
+  immEnd();
+
+  GPU_texture_unbind(color);
+  GPU_texture_unbind(color_overlay);
 
   if (use_ocio) {
     IMB_colormanagement_finish_glsl_draw();
   }
   else {
-    /* TODO fallback. */
+    immUnbindProgram();
   }
 }
 
diff --git a/source/blender/gpu/shaders/gpu_shader_image_linear_frag.glsl 
b/source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl
similarity index 67%
rename from source/blender/gpu/shaders/gpu_shader_image_linear_frag.glsl
rename to source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl
index e6acdd446d3..0147a270aaa 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_linear_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl
@@ -1,7 +1,8 @@
 
 /* Display a linear image texture into sRGB space */
 
-uniform sampler2D image;
+uniform sampler2D image_texture;
+uniform sampler2D overlays_texture;
 
 in vec2 texCoord_interp;
 
@@ -27,7 +28,12 @@ void linearrgb_to_srgb(vec4 col_from, out vec4 col_to)
 
 void main()
 {
-  fragColor = texture(image, texCoord_interp.st);
+  fragColor = texture(image_texture, texCoord_interp.st);
+
+  vec4 overlay_col = texture(overlays_texture, texCoord_interp.st);
+
+  fragColor *= 1.0 - overlay_col.a;
+  fragColor += overlay_col;
 
   linearrgb_to_srgb(fragColor, fragColor);
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to