[Bf-blender-cvs] [419a818eec8] draw-colormanagement: OCIO: Support overlay blending in linear colorspace in GLSL backend

Clément Foucault noreply at git.blender.org
Sun Jan 26 21:08:44 CET 2020


Commit: 419a818eec87536f0578f1b061a3b0020a85cc27
Author: Clément Foucault
Date:   Sun Jan 26 17:03:25 2020 +0100
Branches: draw-colormanagement
https://developer.blender.org/rB419a818eec87536f0578f1b061a3b0020a85cc27

OCIO: Support overlay blending in linear colorspace in GLSL backend

This add the possibility for the caller to add an extra color texture
to composite on top of the main texture. The compositing is done in post
viewtransform linear space.

However, this means the caller needs to pass the proper color processor
to undo and apply the display transform.

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

M	intern/opencolorio/fallback_impl.cc
M	intern/opencolorio/gpu_shader_display_transform.glsl
M	intern/opencolorio/ocio_capi.cc
M	intern/opencolorio/ocio_capi.h
M	intern/opencolorio/ocio_impl.h
M	intern/opencolorio/ocio_impl_glsl.cc
M	source/blender/imbuf/intern/colormanagement.c

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

diff --git a/intern/opencolorio/fallback_impl.cc b/intern/opencolorio/fallback_impl.cc
index ec63dccf147..6d49644b39d 100644
--- a/intern/opencolorio/fallback_impl.cc
+++ b/intern/opencolorio/fallback_impl.cc
@@ -658,10 +658,13 @@ bool FallbackImpl::supportGLSLDraw(void)
 }
 
 bool FallbackImpl::setupGLSLDraw(struct OCIO_GLSLDrawState ** /*state_r*/,
+                                 OCIO_ConstProcessorRcPtr * /*processor*/,
+                                 OCIO_ConstProcessorRcPtr * /*processor*/,
                                  OCIO_ConstProcessorRcPtr * /*processor*/,
                                  OCIO_CurveMappingSettings * /*curve_mapping_settings*/,
                                  float /*dither*/,
-                                 bool /*predivide*/)
+                                 bool /*predivide*/,
+                                 bool /*overlay*/)
 {
   return false;
 }
diff --git a/intern/opencolorio/gpu_shader_display_transform.glsl b/intern/opencolorio/gpu_shader_display_transform.glsl
index bc8f5006dda..a2bd49fa686 100644
--- a/intern/opencolorio/gpu_shader_display_transform.glsl
+++ b/intern/opencolorio/gpu_shader_display_transform.glsl
@@ -2,11 +2,15 @@
 
 uniform sampler1D curve_mapping_texture;
 uniform sampler2D image_texture;
+uniform sampler2D overlay_texture;
 uniform sampler3D lut3d_texture;
+uniform sampler3D lut3d_display_texture;
+uniform sampler3D lut3d_linear_texture;
 
 uniform float dither;
 uniform bool predivide;
 uniform bool curve_mapping;
+uniform bool overlay;
 
 layout(std140) uniform OCIO_GLSLCurveMappingParameters
 {
@@ -129,7 +133,7 @@ vec4 apply_dither(vec4 col, vec2 uv)
   return col;
 }
 
-vec4 OCIO_ProcessColor(vec4 col, vec2 noise_uv)
+vec4 OCIO_ProcessColor(vec4 col, vec4 col_overlay, vec2 noise_uv)
 {
   if (curve_mapping) {
     col = curvemapping_evaluate_premulRGBF(col);
@@ -146,12 +150,21 @@ vec4 OCIO_ProcessColor(vec4 col, vec2 noise_uv)
    *       for straight alpha at this moment
    */
 
-  col = OCIODisplay(col, lut3d_texture);
+  col = OCIO_to_display_encoded_with_look(col, lut3d_texture);
 
   if (dither > 0.0) {
     col = apply_dither(col, noise_uv);
   }
 
+  if (overlay) {
+    col = OCIO_to_display_linear(col, lut3d_display_texture);
+
+    col *= 1.0 - col_overlay.a;
+    col += col_overlay; /* Assumed unassociated alpha. */
+
+    col = OCIO_to_display_encoded(col, lut3d_linear_texture);
+  }
+
   return col;
 }
 
@@ -160,18 +173,11 @@ vec4 OCIO_ProcessColor(vec4 col, vec2 noise_uv)
 in vec2 texCoord_interp;
 out vec4 fragColor;
 
-/* Standard Implementation. */
 void main()
 {
   vec4 col = texture(image_texture, texCoord_interp.st);
+  vec4 col_overlay = texture(overlay_texture, texCoord_interp.st);
   vec2 noise_uv = round_to_pixel(image_texture, texCoord_interp.st);
 
-  fragColor = OCIO_ProcessColor(col, noise_uv);
-}
-
-#if 0 /* In-place transformation. No extra buffer required. */
-void main()
-{
-  /* TODO(fclem) use imageLoad/Store to do in-place color-management. */
-}
-#endif
+  fragColor = OCIO_ProcessColor(col, col_overlay, noise_uv);
+}
\ No newline at end of file
diff --git a/intern/opencolorio/ocio_capi.cc b/intern/opencolorio/ocio_capi.cc
index d259ba73e45..0d2aab43e14 100644
--- a/intern/opencolorio/ocio_capi.cc
+++ b/intern/opencolorio/ocio_capi.cc
@@ -351,11 +351,21 @@ int OCIO_supportGLSLDraw(void)
 
 int OCIO_setupGLSLDraw(struct OCIO_GLSLDrawState **state_r,
                        OCIO_ConstProcessorRcPtr *processor,
+                       OCIO_ConstProcessorRcPtr *processor_linear,
+                       OCIO_ConstProcessorRcPtr *processor_display,
                        OCIO_CurveMappingSettings *curve_mapping_settings,
                        float dither,
-                       bool predivide)
-{
-  return (int)impl->setupGLSLDraw(state_r, processor, curve_mapping_settings, dither, predivide);
+                       bool predivide,
+                       bool overlay)
+{
+  return (int)impl->setupGLSLDraw(state_r,
+                                  processor,
+                                  processor_linear,
+                                  processor_display,
+                                  curve_mapping_settings,
+                                  dither,
+                                  predivide,
+                                  overlay);
 }
 
 void OCIO_finishGLSLDraw(struct OCIO_GLSLDrawState *state)
diff --git a/intern/opencolorio/ocio_capi.h b/intern/opencolorio/ocio_capi.h
index 5670b37f892..dd80bf3c66d 100644
--- a/intern/opencolorio/ocio_capi.h
+++ b/intern/opencolorio/ocio_capi.h
@@ -213,9 +213,12 @@ void OCIO_matrixTransformScale(float *m44, float *offset4, const float *scale4);
 int OCIO_supportGLSLDraw(void);
 int OCIO_setupGLSLDraw(struct OCIO_GLSLDrawState **state_r,
                        OCIO_ConstProcessorRcPtr *processor,
+                       OCIO_ConstProcessorRcPtr *processor_linear,
+                       OCIO_ConstProcessorRcPtr *processor_display,
                        OCIO_CurveMappingSettings *curve_mapping_settings,
                        float dither,
-                       bool predivide);
+                       bool predivide,
+                       bool overlay);
 void OCIO_finishGLSLDraw(struct OCIO_GLSLDrawState *state);
 void OCIO_freeOGLState(struct OCIO_GLSLDrawState *state);
 
diff --git a/intern/opencolorio/ocio_impl.h b/intern/opencolorio/ocio_impl.h
index 082aa4a091e..b4fe8dcc2ce 100644
--- a/intern/opencolorio/ocio_impl.h
+++ b/intern/opencolorio/ocio_impl.h
@@ -133,9 +133,12 @@ class IOCIOImpl {
   virtual bool supportGLSLDraw(void) = 0;
   virtual bool setupGLSLDraw(struct OCIO_GLSLDrawState **state_r,
                              OCIO_ConstProcessorRcPtr *processor,
+                             OCIO_ConstProcessorRcPtr *processor_linear,
+                             OCIO_ConstProcessorRcPtr *processor_display,
                              OCIO_CurveMappingSettings *curve_mapping_settings,
                              float dither,
-                             bool predivide) = 0;
+                             bool predivide,
+                             bool overlay) = 0;
   virtual void finishGLSLDraw(struct OCIO_GLSLDrawState *state) = 0;
   virtual void freeGLState(struct OCIO_GLSLDrawState *state_r) = 0;
 
@@ -244,9 +247,12 @@ class FallbackImpl : public IOCIOImpl {
   bool supportGLSLDraw(void);
   bool setupGLSLDraw(struct OCIO_GLSLDrawState **state_r,
                      OCIO_ConstProcessorRcPtr *processor,
+                     OCIO_ConstProcessorRcPtr *processor_linear,
+                     OCIO_ConstProcessorRcPtr *processor_display,
                      OCIO_CurveMappingSettings *curve_mapping_settings,
                      float dither,
-                     bool predivide);
+                     bool predivide,
+                     bool overlay);
   void finishGLSLDraw(struct OCIO_GLSLDrawState *state);
   void freeGLState(struct OCIO_GLSLDrawState *state_r);
 
@@ -354,9 +360,12 @@ class OCIOImpl : public IOCIOImpl {
   bool supportGLSLDraw(void);
   bool setupGLSLDraw(struct OCIO_GLSLDrawState **state_r,
                      OCIO_ConstProcessorRcPtr *processor,
+                     OCIO_ConstProcessorRcPtr *processor_linear,
+                     OCIO_ConstProcessorRcPtr *processor_display,
                      OCIO_CurveMappingSettings *curve_mapping_settings,
                      float dither,
-                     bool predivide);
+                     bool predivide,
+                     bool overlay);
   void finishGLSLDraw(struct OCIO_GLSLDrawState *state);
   void freeGLState(struct OCIO_GLSLDrawState *state_r);
 
diff --git a/intern/opencolorio/ocio_impl_glsl.cc b/intern/opencolorio/ocio_impl_glsl.cc
index 3d4c4a00a5d..a2c2f8e3b49 100644
--- a/intern/opencolorio/ocio_impl_glsl.cc
+++ b/intern/opencolorio/ocio_impl_glsl.cc
@@ -102,6 +102,8 @@ typedef struct OCIO_GLSLShader {
   GLuint program;
   /** Uniform locations. */
   GLint dither_loc;
+  GLint overlay_loc;
+  GLint overlay_tex_loc;
   GLint predivide_loc;
   GLint curve_mapping_loc;
   /** Error checking. */
@@ -113,6 +115,8 @@ typedef struct OCIO_GLSLLut3d {
   std::string cacheId;
   /** OpenGL Texture handles. 0 if not allocated. */
   GLuint texture;
+  GLuint texture_linear;
+  GLuint texture_dispay;
   /** Error checking. */
   bool valid;
 } OCIO_GLSLLut3d;
@@ -200,6 +204,8 @@ static GLuint linkShaders(GLuint frag, GLuint vert)
 
 static void updateGLSLShader(OCIO_GLSLShader *shader,
                              ConstProcessorRcPtr *ocio_processor,
+                             ConstProcessorRcPtr *ocio_processor_linear,
+                             ConstProcessorRcPtr *ocio_processor_display,
                              GpuShaderDesc *shaderDesc,
                              std::string *cacheId)
 {
@@ -233,7 +239,15 @@ static void updateGLSLShader(OCIO_GLSLShader *shader,
     os << "#define texture2D texture\n";
     os << "#define texture3D texture\n";
 
+    shaderDesc->setFunctionName("OCIO_to_display_encoded_with_look");
     os << (*ocio_processor)->getGpuShaderText(*shaderDesc) << "\n";
+
+    shaderDesc->setFunctionName("OCIO_to_display_linear");
+    os << (*ocio_processor_linear)->getGpuShaderText(*shaderDesc) << "\n";
+
+    shaderDesc->setFunctionName("OCIO_to_display_encoded");
+    os << (*ocio_processor_display)->getGpuShaderText(*shaderDesc) << "\n";
+
     os << datatoc_gpu_shader_display_transform_glsl;
 
     shader->frag = compileShaderText(GL_FRAGMENT_SHADER, os.str().c_str());
@@ -246,14 +260,18 @@ static void updateGLSLShader(OCIO_GLSLShader *shader,
 
   if (shader->program) {
     shader->dither_loc = glGetUniformLocation(shader->program, "dither");
+    shader->overlay_tex_loc = glGetUniformLocation(shader->program, "overlay_texture");
+    shader->overlay_loc = glGetUniformLocation(shader->program, "overlay");
     shader->predivide_loc = glGetUniformLocation(shader->program, "predivide");
     shader->curve_mapping_loc = glGetUniformLocation(shader->program, "curve_mapping");
 
     glUseProgram(shader->program);
     /* Set texture bind point uniform once. This is saved by the shader. */
     glUniform1i(glGetUniformLocation(sha

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list