[Bf-blender-cvs] [b0476f06312] blender-v2.81-release: Workbench: Background Dithering

Jeroen Bakker noreply at git.blender.org
Wed Oct 16 15:41:00 CEST 2019


Commit: b0476f06312db95423e6b83a86d7675dbbc94431
Author: Jeroen Bakker
Date:   Wed Oct 16 15:30:57 2019 +0200
Branches: blender-v2.81-release
https://developer.blender.org/rBb0476f06312db95423e6b83a86d7675dbbc94431

Workbench: Background Dithering

Background dithering was introduced to solve banding issues on gradient backgrounds.
This patch will enable dithering based on the texture that is used for drawing.
Only when using a GPU_RGBA8 texture the dithering will be enabled.

This disables dithering for final rendering, vertex and texture paint modes.

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D6056

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

M	source/blender/draw/engines/workbench/shaders/workbench_background_lib.glsl
M	source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl
M	source/blender/draw/engines/workbench/workbench_data.c
M	source/blender/draw/engines/workbench/workbench_private.h

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

diff --git a/source/blender/draw/engines/workbench/shaders/workbench_background_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_background_lib.glsl
index a6d7c4b393b..3ac220aee59 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_background_lib.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_background_lib.glsl
@@ -1,5 +1,5 @@
 vec3 background_color(WorldData world_data, float y)
 {
   return mix(world_data.background_color_low, world_data.background_color_high, y).xyz +
-         bayer_dither_noise();
+         (world_data.background_dither_factor * bayer_dither_noise());
 }
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl
index 16df56b393a..f60eca24821 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl
@@ -16,5 +16,6 @@ struct WorldData {
   float background_alpha;
   float curvature_ridge;
   float curvature_valley;
-  int pad[3];
+  float background_dither_factor;
+  int pad[2];
 };
diff --git a/source/blender/draw/engines/workbench/workbench_data.c b/source/blender/draw/engines/workbench/workbench_data.c
index 743a1fc42b6..3e63f05ca64 100644
--- a/source/blender/draw/engines/workbench/workbench_data.c
+++ b/source/blender/draw/engines/workbench/workbench_data.c
@@ -111,6 +111,7 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd)
     zero_v3(wd->background_color_low);
     zero_v3(wd->background_color_high);
   }
+  wd->background_dither_factor = workbench_background_dither_factor(wpd);
 
   studiolight_update_world(wpd, wpd->studio_light, wd);
 
diff --git a/source/blender/draw/engines/workbench/workbench_private.h b/source/blender/draw/engines/workbench/workbench_private.h
index 252be3570d7..f28cf12405e 100644
--- a/source/blender/draw/engines/workbench/workbench_private.h
+++ b/source/blender/draw/engines/workbench/workbench_private.h
@@ -194,7 +194,8 @@ typedef struct WORKBENCH_UBO_World {
   float background_alpha;
   float curvature_ridge;
   float curvature_valley;
-  int pad[3];
+  float background_dither_factor;
+  int pad[2];
 } WORKBENCH_UBO_World;
 BLI_STATIC_ASSERT_ALIGN(WORKBENCH_UBO_World, 16)
 
@@ -406,6 +407,12 @@ BLI_INLINE eGPUTextureFormat workbench_color_texture_format(const WORKBENCH_Priv
   return result;
 }
 
+BLI_INLINE bool workbench_background_dither_factor(const WORKBENCH_PrivateData *wpd) {
+  /* Only apply dithering when rendering on a RGBA8 texture.
+   * The dithering will remove banding when using a gradient as background */
+  return workbench_color_texture_format(wpd) == GPU_RGBA8;
+}
+
 /* workbench_deferred.c */
 void workbench_deferred_engine_init(WORKBENCH_Data *vedata);
 void workbench_deferred_engine_free(void);



More information about the Bf-blender-cvs mailing list