Page MenuHome

View3D Grid: fix drawing of grid with imperial units

Authored by Germano Cavalcante (mano-wii) on Feb 19 2019, 5:49 PM.



This is a step to finish the D4325 and fix the T61286.
Currently the grid is highlighted in steps of 10 out of 10, which is wrong for the imperial units as seen in buImperialLenDef.
The idea of the code is to pass the steps of the grid already dimensioned as a uniform.

Another important thing to note is that subdivisions now only affect the grid without unity.
This matches with previous versions of Blender.

*Performance Considerations:
After unrolling the loop, I see no significant change in peformanse.

Diff Detail

rB Blender

Event Timeline

  • unroll loop;
  • Fix loop with non-detectable array size
  • Cleanup
Germano Cavalcante (mano-wii) retitled this revision from View3D Grid: Draw each step as one of the imperial units to View3D Grid: fix drawing of grid with imperial units.Feb 20 2019, 4:12 PM
Germano Cavalcante (mano-wii) edited the summary of this revision. (Show Details)
  • rename ARRAY_SIZE(r_grid_steps) to STEP_LEN

This looks good to me. The only thing I would change is the blending factor. Here is a cubic interpolation that matches the old look better than the smoothstep.

diff --git a/source/blender/draw/modes/shaders/object_grid_frag.glsl b/source/blender/draw/modes/shaders/object_grid_frag.glsl
index f2293c1ee2e..9866406e57b 100644
--- a/source/blender/draw/modes/shaders/object_grid_frag.glsl
+++ b/source/blender/draw/modes/shaders/object_grid_frag.glsl
@@ -70,6 +70,8 @@ vec3 get_axes(vec3 co, vec3 fwidthCos, float line_size)
 	return 1.0 - smoothstep(GRID_LINE_SMOOTH_START, GRID_LINE_SMOOTH_END, axes_domain - (line_size + lineKernel));
+#define linearstep(p0, p1, v) (clamp(((v) - (p0)) / abs((p1) - (p0)), 0.0, 1.0))
 void main()
 	vec3 wPos = local_pos * meshSize;
@@ -159,7 +161,8 @@ void main()
 			scale = vec4(grid_steps[6], grid_steps[7], grid_steps[7], grid_steps[7]);
-		float blend = 1.0 - smoothstep(scale[0], scale[1], grid_res);
+		float blend = 1.0 - linearstep(scale[0], scale[1], grid_res);
+		blend = blend * blend * blend;
 		vec2 grid_pos, grid_fwidth;
 		if ((gridFlag & PLANE_XZ) != 0) {

After that I would accept the patch.


Style: Uniform should be camelCase

  • Remove unused UBO members;
  • Rename grid_distance -> gridDistance;
  • Use interpolation of type cubic;
Germano Cavalcante (mano-wii) marked an inline comment as done.Feb 28 2019, 12:17 AM
  • Rebase Master
  • Improve comment
  • Fix cubic interpolation being operated in the opposite way
  • Remove unnecessary fov calculation

Just some style comments which you can fix before commit.


This should be camel case as well then.


Camel case.


Don't leave commented out code without explaining why it is commented out.


Camel case.

This revision is now accepted and ready to land.Aug 19 2019, 2:45 PM
Germano Cavalcante (mano-wii) marked 3 inline comments as done.Aug 19 2019, 3:07 PM
Germano Cavalcante (mano-wii) updated this revision to Diff 17266.
  • Use camelCase for uniforms
  • remove unused uniforms
Germano Cavalcante (mano-wii) marked an inline comment as done.Aug 19 2019, 3:46 PM