[Bf-blender-cvs] [26223f8d9a0] blender2.8: Object Mode: Grid: Reduce line thickness a tiny bit and apply UI scaling

Clément Foucault noreply at git.blender.org
Tue Oct 30 16:44:31 CET 2018


Commit: 26223f8d9a09a0554e94610039abf5c85284e2e3
Author: Clément Foucault
Date:   Tue Oct 30 16:20:48 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB26223f8d9a09a0554e94610039abf5c85284e2e3

Object Mode: Grid: Reduce line thickness a tiny bit and apply UI scaling

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

M	source/blender/draw/modes/object_mode.c
M	source/blender/draw/modes/shaders/object_grid_frag.glsl

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

diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index 1b20e32a770..b494fbc740e 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -1044,6 +1044,7 @@ static void OBJECT_cache_init(void *vedata)
 		psl->grid = DRW_pass_create("Infinite Grid Pass", state);
 
 		struct GPUBatch *geom = DRW_cache_grid_get();
+		float grid_line_size = max_ff(0.0f, U.pixelsize - 1.0f) * 0.5f;
 		static float mat[4][4];
 		unit_m4(mat);
 
@@ -1055,6 +1056,7 @@ static void OBJECT_cache_init(void *vedata)
 		DRW_shgroup_uniform_vec3(grp, "cameraPos", e_data.camera_pos, 1);
 		DRW_shgroup_uniform_vec4(grp, "screenvecs[0]", e_data.screenvecs[0], 3);
 		DRW_shgroup_uniform_vec4(grp, "gridSettings", e_data.grid_settings, 1);
+		DRW_shgroup_uniform_float_copy(grp, "lineKernel", grid_line_size);
 		DRW_shgroup_uniform_float(grp, "gridOneOverLogSubdiv", &e_data.grid_settings[4], 1);
 		DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
 		DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
diff --git a/source/blender/draw/modes/shaders/object_grid_frag.glsl b/source/blender/draw/modes/shaders/object_grid_frag.glsl
index 4a3ac6abd84..928db048a46 100644
--- a/source/blender/draw/modes/shaders/object_grid_frag.glsl
+++ b/source/blender/draw/modes/shaders/object_grid_frag.glsl
@@ -12,6 +12,7 @@ uniform vec3 eye;
 uniform vec4 gridSettings;
 uniform vec2 viewportSize;
 uniform vec4 screenvecs[3];
+uniform float lineKernel = 0.0;
 uniform float gridOneOverLogSubdiv;
 uniform sampler2D depthBuffer;
 
@@ -31,7 +32,8 @@ uniform int gridFlag;
 #define PLANE_YZ  (1 << 6)
 #define GRID_BACK (1 << 9) /* grid is behind objects */
 
-#define GRID_LINE_SMOOTH 1.15
+#define GRID_LINE_SMOOTH_START -0.1
+#define GRID_LINE_SMOOTH_END 1.05
 
 float get_grid(vec2 co, vec2 fwidthCos, float grid_size)
 {
@@ -42,10 +44,10 @@ float get_grid(vec2 co, vec2 fwidthCos, float grid_size)
 	 * (make lines have the same width under perspective) */
 	grid_domain /= fwidthCos;
 
-	/* collapse waves and normalize */
-	grid_domain.x = min(grid_domain.x, grid_domain.y) / half_size;
+	/* collapse waves */
+	float line_dist = min(grid_domain.x, grid_domain.y);
 
-	return 1.0 - smoothstep(0.0, GRID_LINE_SMOOTH / grid_size, grid_domain.x * 0.5);
+	return 1.0 - smoothstep(GRID_LINE_SMOOTH_START, GRID_LINE_SMOOTH_END, line_dist - lineKernel);
 }
 
 vec3 get_axes(vec3 co, vec3 fwidthCos, float line_size)
@@ -55,7 +57,7 @@ vec3 get_axes(vec3 co, vec3 fwidthCos, float line_size)
 	 * (make line have the same width under perspective) */
 	axes_domain /= fwidthCos;
 
-	return 1.0 - smoothstep(0.0, GRID_LINE_SMOOTH, axes_domain - line_size);
+	return 1.0 - smoothstep(GRID_LINE_SMOOTH_START, GRID_LINE_SMOOTH_END, axes_domain - (line_size + lineKernel));
 }
 
 vec3 get_floor_pos(vec2 uv, out vec3 wPos)



More information about the Bf-blender-cvs mailing list