Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/modes/shaders/object_grid_frag.glsl
| Show All 36 Lines | |||||
| #define M_1_SQRTPI 0.5641895835477563 /* 1/sqrt(pi) */ | #define M_1_SQRTPI 0.5641895835477563 /* 1/sqrt(pi) */ | ||||
| /** | /** | ||||
| * We want to know how much a pixel is covered by a line. | * 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. | * 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 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. | * 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. | * 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 DISC_RADIUS (M_1_SQRTPI * 1.05) | ||||
| #define GRID_LINE_SMOOTH_START (0.5 - DISC_RADIUS) | #define GRID_LINE_SMOOTH_START (0.5 - DISC_RADIUS) | ||||
| #define GRID_LINE_SMOOTH_END (0.5 + DISC_RADIUS) | #define GRID_LINE_SMOOTH_END (0.5 + DISC_RADIUS) | ||||
| float get_grid(vec2 co, vec2 fwidthCos, float grid_size) | float get_grid(vec2 co, vec2 fwidthCos, float grid_size) | ||||
| { | { | ||||
| float half_size = grid_size / 2.0; | float half_size = grid_size / 2.0; | ||||
| /* triangular wave pattern, amplitude is [0, half_size] */ | /* triangular wave pattern, amplitude is [0, half_size] */ | ||||
| ▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines | |||||