diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2017-05-01 17:21:53 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2017-05-01 17:32:55 +0300 |
commit | d7d4bca23be91ec5b0ce562d47a34ee49dd337b8 (patch) | |
tree | 6184684f5300324294dbaa103522e7e817e3d6bd /source/blender/gpu/shaders/gpu_shader_3D_line_dashed_vert.glsl | |
parent | 6ef497d401e5e7842d1e9d33e491672bb77d60e0 (diff) |
Reworked version of dashed line shader.
Using geometry shader allows us to get rid of the 'line origin' extra
vertex attribute, which means dashed shader no longer requires fiddling
with those vertex attributes definition, and, most importantly, does not
require anymore special drawing code!
As you can see, this makes code much simpler, and much less verbose,
especially in complex cases.
In addition, changed how dashes are handled, to have two 'modes', a
simple one with single color (using default "color" uniform name), and a
more advanced one allowing more complex and multi-color patterns.
Note that since GLSL 1.2 does not support geometry shaders, a hack was
added for now (which gives solid lines, but at least does not make
Blender crash).
Diffstat (limited to 'source/blender/gpu/shaders/gpu_shader_3D_line_dashed_vert.glsl')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_3D_line_dashed_vert.glsl | 19 |
1 files changed, 1 insertions, 18 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_vert.glsl index f3e91b6cc03..f86088e8d79 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_vert.glsl @@ -1,32 +1,15 @@ -/* Note: nearly the same code as for 2D version... Maybe we could deduplicate? */ +// Draw dashed lines, perforated in screen space. uniform mat4 ModelViewProjectionMatrix; -uniform vec2 viewport_size; #if __VERSION__ == 120 attribute vec3 pos; - attribute vec3 line_origin; // = pos for one vertex of the line - noperspective varying float distance_along_line; #else in vec3 pos; - in vec3 line_origin; - noperspective out float distance_along_line; #endif void main() { gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); - - vec4 point = ModelViewProjectionMatrix * vec4(line_origin, 1.0); - vec2 ref_point = (point.xy / point.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range. - ref_point = ref_point * viewport_size; // <- fragment coordinates. - - vec2 curr_point = (gl_Position.xy / gl_Position.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range. - curr_point = curr_point * viewport_size; // <- fragment coordinates. - - distance_along_line = distance(ref_point, curr_point); - - /* Note: we could also use similar approach as diag_stripes_frag, but this would give us dashed 'anchored' - * to the screen, and not to one end of the line... */ } |