[Bf-blender-cvs] [36e6a41f6f7] blender2.8: Object Mode: Grid: Make antialiasing more grounded

Clément Foucault noreply at git.blender.org
Fri Nov 9 15:35:34 CET 2018


Commit: 36e6a41f6f76b7a670f0ed0d59a9a1f73832a216
Author: Clément Foucault
Date:   Fri Nov 9 14:37:35 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB36e6a41f6f76b7a670f0ed0d59a9a1f73832a216

Object Mode: Grid: Make antialiasing more grounded

Went a bit anal on this but at least we will have a decent AA reference
for lines in the future.

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

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

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

diff --git a/source/blender/draw/modes/shaders/object_grid_frag.glsl b/source/blender/draw/modes/shaders/object_grid_frag.glsl
index 3ccb10ca4ab..35a95e809df 100644
--- a/source/blender/draw/modes/shaders/object_grid_frag.glsl
+++ b/source/blender/draw/modes/shaders/object_grid_frag.glsl
@@ -32,8 +32,18 @@ uniform int gridFlag;
 #define PLANE_YZ  (1 << 6)
 #define GRID_BACK (1 << 9) /* grid is behind objects */
 
-#define GRID_LINE_SMOOTH_START -0.1
-#define GRID_LINE_SMOOTH_END 1.05
+#define M_1_SQRTPI   0.5641895835477563    /* 1/sqrt(pi) */
+
+/**
+ * We want to know how much a pixel is covered by a line.
+ * We replace the square pixel with acircle of the same area and try to find the intersection area.
+ * The area we search is the circular segment. https://en.wikipedia.org/wiki/Circular_segment
+ * The formula for the area uses inverse trig function and is quite complexe.
+ * Instead, we approximate it by using the smoothstep function and a 1.05 factor to the disc radius.
+ **/
+#define DISC_RADIUS (M_1_SQRTPI * 1.05)
+#define GRID_LINE_SMOOTH_START (0.5 - DISC_RADIUS)
+#define GRID_LINE_SMOOTH_END (0.5 + DISC_RADIUS)
 
 float get_grid(vec2 co, vec2 fwidthCos, float grid_size)
 {



More information about the Bf-blender-cvs mailing list