diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-05-27 11:50:39 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-05-27 11:50:39 +0300 |
commit | 198be6f37b3ca8d65a026a7aeab7d8db4f3eb25e (patch) | |
tree | 0e804d8839ad6bff2af07e77eccbca47c5198d1d /source/blender/draw/modes/shaders/object_grid_frag.glsl | |
parent | aefc793a818aa8fa35e968b2be38e1b73909907d (diff) |
Grid: Fix T51813: Opaque grid on OSX.
Diffstat (limited to 'source/blender/draw/modes/shaders/object_grid_frag.glsl')
-rw-r--r-- | source/blender/draw/modes/shaders/object_grid_frag.glsl | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/source/blender/draw/modes/shaders/object_grid_frag.glsl b/source/blender/draw/modes/shaders/object_grid_frag.glsl index baf508fd854..2d0d637fc45 100644 --- a/source/blender/draw/modes/shaders/object_grid_frag.glsl +++ b/source/blender/draw/modes/shaders/object_grid_frag.glsl @@ -32,19 +32,19 @@ uniform int gridFlag; #define GRID_LINE_SMOOTH 1.15 -float get_grid(vec3 co, vec3 fwidthCos, float grid_size) +float get_grid(vec2 co, vec2 fwidthCos, float grid_size) { float half_size = grid_size / 2.0; - /* triangular wave pattern, amplitude is [0, grid_size] */ - vec3 grid_domain = abs(mod(co + half_size, grid_size) - half_size); + /* triangular wave pattern, amplitude is [0, half_size] */ + vec2 grid_domain = abs(mod(co + half_size, grid_size) - half_size); /* modulate by the absolute rate of change of the coordinates * (make lines have the same width under perspective) */ grid_domain /= fwidthCos; /* collapse waves and normalize */ - grid_domain.x = min(grid_domain.x, min(grid_domain.y, grid_domain.z)) / grid_size; + grid_domain.x = min(grid_domain.x, grid_domain.y) / half_size; - return 1.0 - smoothstep(0.0, GRID_LINE_SMOOTH / grid_size, grid_domain.x); + return 1.0 - smoothstep(0.0, GRID_LINE_SMOOTH / grid_size, grid_domain.x * 0.5); } vec3 get_axes(vec3 co, vec3 fwidthCos, float line_size) @@ -160,9 +160,23 @@ void main() float scaleB = gridScale * pow(gridSubdiv, max(lvl + 0.0, 0.0)); float scaleC = gridScale * pow(gridSubdiv, max(lvl + 1.0, 1.0)); - float gridA = get_grid(wPos, fwidthPos, scaleA); - float gridB = get_grid(wPos, fwidthPos, scaleB); - float gridC = get_grid(wPos, fwidthPos, scaleC); + vec2 grid_pos, grid_fwidth; + if ((gridFlag & PLANE_XZ) > 0) { + grid_pos = wPos.xz; + grid_fwidth = fwidthPos.xz; + } + else if ((gridFlag & PLANE_YZ) > 0) { + grid_pos = wPos.yz; + grid_fwidth = fwidthPos.yz; + } + else { + grid_pos = wPos.xy; + grid_fwidth = fwidthPos.xy; + } + + float gridA = get_grid(grid_pos, grid_fwidth, scaleA); + float gridB = get_grid(grid_pos, grid_fwidth, scaleB); + float gridC = get_grid(grid_pos, grid_fwidth, scaleC); FragColor = vec4(colorGrid.rgb, gridA * blend); FragColor = mix(FragColor, vec4(mix(colorGrid.rgb, colorGridEmphasise.rgb, blend), 1.0), gridB); |