Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gpu_shader_2D_line_dashed_vert.glsl « shaders « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 708871b363f74d05c70b778a342e5414f04fa63a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

// Draw dashed lines, perforated in screen space.
// Based on a (3D) version by Mike Erwin.

uniform mat4 ModelViewProjectionMatrix;
uniform vec2 viewport_size;

#if __VERSION__ == 120
  attribute vec2 pos;
  attribute vec2 line_origin; // = pos for one vertex of the line
  noperspective varying float distance_along_line;
#else
  in vec2 pos;
  in vec2 line_origin;
  noperspective out float distance_along_line;
#endif

void main()
{
	gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);

	vec4 point = ModelViewProjectionMatrix * vec4(line_origin, 0.0, 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;  // <- 'virtual' screen 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;  // <- 'virtual' screen 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... */
}