[Bf-blender-cvs] [4e352851e4d] tmp-ocio-v2: OpenColorIO: update GPU display shader for version 2.0

Brecht Van Lommel noreply at git.blender.org
Mon Feb 1 15:49:17 CET 2021


Commit: 4e352851e4dc47d22325db3308d91b879958bcd0
Author: Brecht Van Lommel
Date:   Sun Jan 31 20:10:04 2021 +0100
Branches: tmp-ocio-v2
https://developer.blender.org/rB4e352851e4dc47d22325db3308d91b879958bcd0

OpenColorIO: update GPU display shader for version 2.0

To avoid baking exposure and gamma into the GLSL shader and requiring slow
recompiles when tweaking, we manually apply them in the shader. This leads
to some logic duplicaton between the CPU and GPU display processor, but it
seems unavoidable.

Caching was also changed. Previously this was done both on the imbuf and
opencolorio module levels. Now it's all done in the opencolorio module by
simply matching color space names. We no longer use cacheIDs from OpenColorIO
since computing them is expensive, and they are unlikely to match now that
more is baked into the shader code.

Shaders can now use multiple 2D textures, 3D textures and uniforms, rather
than a single 3D texture. So allocating and binding those adds some code.

Color space conversions for blending with overlays is now hardcoded in the
shader. This was using harcoded numbers anyway, if this every becomes a
general OpenColorIO transform it can be changed, but for now there is no
point to add code complexity.

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

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/gpu_shader_display_transform.glsl b/intern/opencolorio/gpu_shader_display_transform.glsl
index 61da755f02f..7b37f672af2 100644
--- a/intern/opencolorio/gpu_shader_display_transform.glsl
+++ b/intern/opencolorio/gpu_shader_display_transform.glsl
@@ -1,17 +1,20 @@
 /* Blender OpenColorIO implementation */
 
+#ifdef USE_CURVE_MAPPING
 uniform sampler1D curve_mapping_texture;
+#endif
+
 uniform sampler2D image_texture;
 uniform sampler2D overlay_texture;
-uniform sampler3D lut3d_texture;
-uniform sampler3D lut3d_display_texture;
 
 uniform float dither;
+uniform float scale;
+uniform float exponent;
 uniform bool predivide;
-uniform bool curve_mapping;
 uniform bool overlay;
 
-layout(std140) uniform OCIO_GLSLCurveMappingParameters
+#ifdef USE_CURVE_MAPPING
+layout(std140) uniform OCIO_GPUCurveMappingParameters
 {
   /* Curve mapping parameters
    *
@@ -114,6 +117,7 @@ vec4 curvemapping_evaluate_premulRGBF(vec4 col)
   result.a = col.a;
   return result;
 }
+#endif /* USE_CURVE_MAPPING */
 
 /* Using a triangle distribution which gives a more final uniform noise.
  * See Banding in Games:A Noisy Rant(revision 5) Mikkel Gjøl, Playdead (slide 27) */
@@ -145,9 +149,9 @@ vec4 apply_dither(vec4 col, vec2 uv)
 
 vec4 OCIO_ProcessColor(vec4 col, vec4 col_overlay, vec2 noise_uv)
 {
-  if (curve_mapping) {
-    col = curvemapping_evaluate_premulRGBF(col);
-  }
+#ifdef USE_CURVE_MAPPING
+  col = curvemapping_evaluate_premulRGBF(col);
+#endif
 
   if (predivide) {
     if (col.a > 0.0 && col.a < 1.0) {
@@ -160,15 +164,31 @@ vec4 OCIO_ProcessColor(vec4 col, vec4 col_overlay, vec2 noise_uv)
    *       for straight alpha at this moment
    */
 
-  col = OCIO_to_display_linear_with_look(col, lut3d_texture);
+  /* Convert to scene linear (usually a no-op). */
+  col = OCIO_to_scene_linear(col);
+
+  /* Apply exposure in scene linear. */
+  col.rgb *= scale;
 
+  /* Convert to display space. */
+  col = OCIO_to_display(col);
+
+  /* Blend with overlay in UI colorspace.
+   *
+   * UI colorspace here refers to the display linear color space,
+   * i.e: The linear color space w.r.t. display chromaticity and radiometry.
+   * We separate the colormanagement process into two steps to be able to
+   * merge UI using alpha blending in the correct color space. */
   if (overlay) {
+    col.rgb = pow(col.rgb, vec3(exponent * 2.2));
     col = clamp(col, 0.0, 1.0);
     col *= 1.0 - col_overlay.a;
     col += col_overlay; /* Assumed unassociated alpha. */
+    col.rgb = pow(col.rgb, vec3(1.0 / 2.2));
+  }
+  else {
+    col.rgb = pow(col.rgb, vec3(exponent));
   }
-
-  col = OCIO_to_display_encoded(col, lut3d_display_texture);
 
   if (dither > 0.0) {
     col = apply_dither(col, noise_uv);
@@ -189,4 +209,4 @@ void main()
   vec2 noise_uv = round_to_pixel(image_texture, texCoord_interp.st);
 
   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 e5136659dda..6904ce207dd 100644
--- a/intern/opencolorio/ocio_capi.cc
+++ b/intern/opencolorio/ocio_capi.cc
@@ -278,36 +278,44 @@ void OCIO_PackedImageDescRelease(OCIO_PackedImageDesc *id)
   impl->OCIO_PackedImageDescRelease(id);
 }
 
-int OCIO_supportGLSLDraw(void)
+bool OCIO_supportGPUShader()
 {
-  return (int)impl->supportGLSLDraw();
+  return impl->supportGPUShader();
 }
 
-int OCIO_setupGLSLDraw(struct OCIO_GLSLDrawState **state_r,
-                       OCIO_ConstProcessorRcPtr *ocio_processor_scene_to_ui,
-                       OCIO_ConstProcessorRcPtr *ocio_processor_ui_to_display,
-                       OCIO_CurveMappingSettings *curve_mapping_settings,
-                       float dither,
-                       bool predivide,
-                       bool overlay)
+bool OCIO_gpuDisplayShaderBind(OCIO_ConstConfigRcPtr *config,
+                               const char *input,
+                               const char *view,
+                               const char *display,
+                               const char *look,
+                               OCIO_CurveMappingSettings *curve_mapping_settings,
+                               const float scale,
+                               const float exponent,
+                               const float dither,
+                               const bool use_predivide,
+                               const bool use_overlay)
 {
-  return (int)impl->setupGLSLDraw(state_r,
-                                  ocio_processor_scene_to_ui,
-                                  ocio_processor_ui_to_display,
-                                  curve_mapping_settings,
-                                  dither,
-                                  predivide,
-                                  overlay);
+  return impl->gpuDisplayShaderBind(config,
+                                    input,
+                                    view,
+                                    display,
+                                    look,
+                                    curve_mapping_settings,
+                                    scale,
+                                    exponent,
+                                    dither,
+                                    use_predivide,
+                                    use_overlay);
 }
 
-void OCIO_finishGLSLDraw(struct OCIO_GLSLDrawState *state)
+void OCIO_gpuDisplayShaderUnbind(void)
 {
-  impl->finishGLSLDraw(state);
+  impl->gpuDisplayShaderUnbind();
 }
 
-void OCIO_freeOGLState(struct OCIO_GLSLDrawState *state)
+void OCIO_gpuCacheFree(void)
 {
-  impl->freeGLState(state);
+  impl->gpuCacheFree();
 }
 
 const char *OCIO_getVersionString(void)
diff --git a/intern/opencolorio/ocio_capi.h b/intern/opencolorio/ocio_capi.h
index 7e04fbc0bb7..d93200c8181 100644
--- a/intern/opencolorio/ocio_capi.h
+++ b/intern/opencolorio/ocio_capi.h
@@ -24,7 +24,7 @@
 extern "C" {
 #endif
 
-struct OCIO_GLSLDrawState;
+typedef struct OCIO_GPUShader OCIO_GPUShader;
 
 #define OCIO_DECLARE_HANDLE(name) \
   typedef struct name##__ { \
@@ -192,16 +192,20 @@ OCIO_PackedImageDesc *OCIO_createOCIO_PackedImageDesc(float *data,
 
 void OCIO_PackedImageDescRelease(OCIO_PackedImageDesc *p);
 
-int OCIO_supportGLSLDraw(void);
-int OCIO_setupGLSLDraw(struct OCIO_GLSLDrawState **state_r,
-                       OCIO_ConstProcessorRcPtr *ocio_processor_scene_to_ui,
-                       OCIO_ConstProcessorRcPtr *ocio_processor_ui_to_display,
-                       OCIO_CurveMappingSettings *curve_mapping_settings,
-                       float dither,
-                       bool predivide,
-                       bool overlay);
-void OCIO_finishGLSLDraw(struct OCIO_GLSLDrawState *state);
-void OCIO_freeOGLState(struct OCIO_GLSLDrawState *state);
+bool OCIO_supportGPUShader(void);
+bool OCIO_gpuDisplayShaderBind(OCIO_ConstConfigRcPtr *config,
+                               const char *input,
+                               const char *view,
+                               const char *display,
+                               const char *look,
+                               OCIO_CurveMappingSettings *curve_mapping_settings,
+                               const float scale,
+                               const float exponent,
+                               const float dither,
+                               const bool use_predivide,
+                               const bool use_overlay);
+void OCIO_gpuDisplayShaderUnbind(void);
+void OCIO_gpuCacheFree(void);
 
 const char *OCIO_getVersionString(void);
 int OCIO_getVersionHex(void);
diff --git a/intern/opencolorio/ocio_impl.h b/intern/opencolorio/ocio_impl.h
index 50525b124e0..870432cf367 100644
--- a/intern/opencolorio/ocio_impl.h
+++ b/intern/opencolorio/ocio_impl.h
@@ -112,16 +112,31 @@ class IOCIOImpl {
 
   virtual void OCIO_PackedImageDescRelease(OCIO_PackedImageDesc *p) = 0;
 
-  virtual bool supportGLSLDraw(void) = 0;
-  virtual bool setupGLSLDraw(struct OCIO_GLSLDrawState **state_r,
-                             OCIO_ConstProcessorRcPtr *ocio_processor_scene_to_ui,
-                             OCIO_ConstProcessorRcPtr *ocio_processor_ui_to_display,
-                             OCIO_CurveMappingSettings *curve_mapping_settings,
-                             float dither,
-                             bool predivide,
-                             bool overlay) = 0;
-  virtual void finishGLSLDraw(struct OCIO_GLSLDrawState *state) = 0;
-  virtual void freeGLState(struct OCIO_GLSLDrawState *state_r) = 0;
+  /* Optional GPU support. */
+  virtual bool supportGPUShader()
+  {
+    return false;
+  }
+  virtual bool gpuDisplayShaderBind(OCIO_ConstConfigRcPtr * /* config */,
+                                    const char * /* input */,
+                                    const char * /* view */,
+                                    const char * /* display */,
+                                    const char * /* look */,
+                                    OCIO_CurveMappingSettings * /* curve_mapping_settings */,
+                                    const float /* scale */,
+                                    const float /* exponent */,
+                                    const float /* dither */,
+                                    const bool /* use_predivide */,
+                                    const bool /* use_overlay */)
+  {
+    return false;
+  }
+  virtual void gpuDisplayShaderUnbind(void)
+  {
+  }
+  virtual void gpuCacheFree(void)
+  {
+  }
 
   virtual const char *getVersionString(void) = 0;
   virtual int getVersionHex(void) = 0;
@@ -211,17 +226,6 @@ class FallbackImpl : public IOCIOImpl {
 
   void OCIO_PackedImageDescRelease(OCIO_PackedImageDesc *p);
 
-  bool supportGLSLDraw(void);
-  bool setupGLSLDraw(struct OCIO_GLSLDrawState **state_r,
-                     OCIO_ConstProcessorRcPtr *ocio_processor_scene_to_ui,
-                     OCIO_ConstProcessorRcPtr *ocio_processor_ui_to_display,
-                     OCIO_CurveMappingSettings *curve_mapping_settings,
-                     float dither,
-                     bool predivide,
-                     bool overlay);
-  void finishGLSLDraw(struct OCIO_GLSLDrawState *state);
-  void freeGLSt

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list