[Bf-blender-cvs] [ec5b795d11b] greasepencil-refactor: GPencil: Refactor: First step to get rid of sRGB

Clément Foucault noreply at git.blender.org
Fri Dec 20 00:18:40 CET 2019


Commit: ec5b795d11b2d9ef3dcbc1381bdbe74535130d1c
Author: Clément Foucault
Date:   Fri Dec 20 00:14:16 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBec5b795d11b2d9ef3dcbc1381bdbe74535130d1c

GPencil: Refactor: First step to get rid of sRGB

This patch removes sRGB from the rendering pipeline. All color that
enters shading is a Linear color. Only the final composite shader is
still using sRGB as display transform for now (will later be replaced by
full OCIO transform).

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

M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/draw/engines/gpencil/gpencil_draw_data.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/shaders/gpencil_composite_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index fbf2beb809e..751e9c12ebc 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -115,7 +115,7 @@ static void gpencil_buffer_add_point(
   gpStrokeVert *vert = &verts[v];
   copy_v3_v3(vert->pos, &pt->x);
   copy_v2_v2(vert->uv, pt->uv_fill);
-  copy_v4_v4(vert->col, pt->mix_color);
+  srgb_to_linearrgb_v4(vert->col, pt->mix_color);
   vert->strength = pt->strength;
   vert->u_stroke = pt->uv_fac;
   vert->stroke_id = gps->runtime.stroke_start;
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.c b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
index e4d45d7ad21..30eb575e438 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
@@ -194,6 +194,10 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
       copy_v4_v4(mat_data->fill_color, gp_style->fill_rgba);
       mat_data->fill_texture_mix = 0.0f;
     }
+
+    /* TODO fix the color in the dna instead */
+    srgb_to_linearrgb_v4(mat_data->fill_color, mat_data->fill_color);
+    srgb_to_linearrgb_v4(mat_data->stroke_color, mat_data->stroke_color);
   }
 
   *ofs = 0;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 74591c3d3de..5249ccfdb8b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -848,6 +848,10 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
   iter->ubo_lights = (use_lights) ? iter->pd->global_light_pool->ubo :
                                     iter->pd->shadeless_light_pool->ubo;
 
+  /* TODO fix the color in the dna instead */
+  float tint_col[4];
+  srgb_to_linearrgb_v4(tint_col, gpl->tintcolor);
+
   struct GPUShader *sh = GPENCIL_shader_geometry_get(&en_data);
   iter->grp = DRW_shgroup_create(sh, tgp_layer->geom_ps);
   DRW_shgroup_uniform_block(iter->grp, "gpLightBlock", iter->ubo_lights);
@@ -866,7 +870,7 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
   DRW_shgroup_uniform_float_copy(iter->grp, "thicknessOffset", (float)gpl->line_change);
   DRW_shgroup_uniform_float_copy(iter->grp, "thicknessWorldScale", thickness_scale);
   DRW_shgroup_uniform_float_copy(iter->grp, "vertexColorOpacity", gpl->vertex_paint_opacity);
-  DRW_shgroup_uniform_vec4_copy(iter->grp, "layerTint", gpl->tintcolor);
+  DRW_shgroup_uniform_vec4_copy(iter->grp, "layerTint", tint_col);
   DRW_shgroup_stencil_mask(iter->grp, 0xFF);
 }
 
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_composite_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_composite_frag.glsl
index 7ac992e046d..80358a9cf85 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_composite_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_composite_frag.glsl
@@ -8,6 +8,17 @@ in vec4 uvcoordsvar;
 layout(location = 0, index = 0) out vec4 fragColor;
 layout(location = 0, index = 1) out vec4 fragRevealage;
 
+/* TODO Remove. */
+float linearrgb_to_srgb(float c)
+{
+  if (c < 0.0031308) {
+    return (c < 0.0) ? 0.0 : c * 12.92;
+  }
+  else {
+    return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
+  }
+}
+
 void main()
 {
   /* Revealage, how much light passes through. */
@@ -18,4 +29,9 @@ void main()
   fragColor.rgb = textureLod(colorBuf, uvcoordsvar.xy, 0.0).rgb;
   /* Add the alpha. */
   fragColor.a = 1.0 - fragRevealage.a;
+  /* Temporary srgb conversion.
+   * TODO do color management / tonemapping here. */
+  fragColor.r = linearrgb_to_srgb(fragColor.r);
+  fragColor.g = linearrgb_to_srgb(fragColor.g);
+  fragColor.b = linearrgb_to_srgb(fragColor.b);
 }
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
index e57b6522527..034a2132052 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
@@ -56,13 +56,13 @@ void main()
   vec4 col;
   if (GP_FLAG_TEST(matFlag, GP_STROKE_TEXTURE_USE)) {
     bool premul = GP_FLAG_TEST(matFlag, GP_STROKE_TEXTURE_PREMUL);
-    col = texture_read_as_srgb(gpStrokeTexture, premul, finalUvs);
+    col = texture_read_as_linearrgb(gpStrokeTexture, premul, finalUvs);
   }
   else if (GP_FLAG_TEST(matFlag, GP_FILL_TEXTURE_USE)) {
     bool use_clip = GP_FLAG_TEST(matFlag, GP_FILL_TEXTURE_CLIP);
     vec2 uvs = (use_clip) ? clamp(finalUvs, 0.0, 1.0) : finalUvs;
     bool premul = GP_FLAG_TEST(matFlag, GP_FILL_TEXTURE_PREMUL);
-    col = texture_read_as_srgb(gpFillTexture, premul, uvs);
+    col = texture_read_as_linearrgb(gpFillTexture, premul, uvs);
   }
   else /* SOLID */ {
     col = vec4(1.0);



More information about the Bf-blender-cvs mailing list