[Bf-blender-cvs] [20b0194cd3f] blender2.8: Workbench: Xray: Make dithered depth dependant on alpha.

Clément Foucault noreply at git.blender.org
Sun Jun 10 19:56:51 CEST 2018


Commit: 20b0194cd3f33f613bba6923e3ca6fbf16838c55
Author: Clément Foucault
Date:   Sun Jun 10 20:06:02 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB20b0194cd3f33f613bba6923e3ca6fbf16838c55

Workbench: Xray: Make dithered depth dependant on alpha.

The range is 0.25 to 0.75 opacity when the Xray opacity is between 0.0 to 1.0.

This is to avoid loosing completely the sense of occlusion when having no
other solid drawing than the wireframe and loosing the transparency when
xray alpha is at 1.0.

Also replace Bayer (checkerboard) method by interlieved gradient noise to
minimize the chance to loose an occluded line completely.

Other noise function could be tested in the future.

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

M	source/blender/draw/engines/workbench/shaders/workbench_checkerboard_depth_frag.glsl
M	source/blender/draw/engines/workbench/workbench_forward.c

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

diff --git a/source/blender/draw/engines/workbench/shaders/workbench_checkerboard_depth_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_checkerboard_depth_frag.glsl
index 4e44f6e1914..7027543f5a9 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_checkerboard_depth_frag.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_checkerboard_depth_frag.glsl
@@ -1,8 +1,35 @@
+
+/* 4x4 bayer matrix. */
+#define P(x) ((x + 0.5) * (1.0 / 16.0))
+const vec4 dither_mat[4] = vec4[4](
+	vec4( P(0.0),  P(8.0),  P(2.0), P(10.0)),
+	vec4(P(12.0),  P(4.0), P(14.0),  P(6.0)),
+	vec4( P(3.0), P(11.0),  P(1.0),  P(9.0)),
+	vec4(P(15.0),  P(7.0), P(13.0),  P(5.0))
+);
+
+uniform float threshold = 0.5;
+
+/* Noise dithering pattern
+ * 0 - Bayer matrix
+ * 1 - Interlieved gradient noise
+ */
+#define NOISE 1
+
 void main()
 {
-	vec2 p= vec2(floor(gl_FragCoord.x), floor(gl_FragCoord.y));
-	vec2 test = mod(p, 2.0);
-	if (mod(test.x + test.y, 2.0)==0.0) {
+#if NOISE == 0
+	ivec2 tx = ivec2(gl_FragCoord.xy) % 4;
+	float noise = dither_mat[tx.x][tx.y];
+#elif NOISE == 1
+	/* Interlieved gradient noise by Jorge Jimenez
+	 * http://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare */
+	float noise = fract(52.9829189 * fract(0.06711056 * gl_FragCoord.x + 0.00583715 * gl_FragCoord.y));
+#else
+#error
+#endif
+
+	if (noise > threshold) {
 		discard;
 	} else {
 		gl_FragDepth = 1.0;
diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c
index 4e97fc730a3..6864d1ec9b3 100644
--- a/source/blender/draw/engines/workbench/workbench_forward.c
+++ b/source/blender/draw/engines/workbench/workbench_forward.c
@@ -353,6 +353,7 @@ void workbench_forward_engine_init(WORKBENCH_Data *vedata)
 		psl->checker_depth_pass = DRW_pass_create("Checker Depth", state);
 		grp = DRW_shgroup_create(e_data.checker_depth_sh, psl->checker_depth_pass);
 		DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+		DRW_shgroup_uniform_float_copy(grp, "threshold", 0.75f - wpd->shading.xray_alpha * 0.5f);
 	}
 }



More information about the Bf-blender-cvs mailing list