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

gpu_shader_2D_line_dashed_frag.glsl « shaders « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1bca505390b0b88f70adea1adc20bbefc425a929 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47

// Draw dashed lines, perforated in screen space.

#if __VERSION__ == 120
  noperspective varying float distance_along_line;
  #define fragColor gl_FragColor
#else
  noperspective in float distance_along_line;
  out vec4 fragColor;
#endif

uniform float dash_width;

/* Simple mode, discarding non-dash parts (so no need for blending at all). */
uniform float dash_factor;  /* if > 1.0, solid line. */
uniform vec4 color;

/* More advanced mode, allowing for complex, multi-colored patterns. Enabled when num_colors > 0. */
/* Note: max number of steps/colors in pattern is 32! */
uniform int num_colors;  /* Enabled if > 0, 1 for solid line. */
uniform vec4 colors[32];

void main()
{
	/* Solid line cases, simple. */
	if (num_colors == 1) {
		fragColor = colors[0];
	}
	else if (dash_factor >= 1.0f) {
		fragColor = color;
	}
	else {
		/* Actually dashed line... */
		float normalized_distance = fract(distance_along_line / dash_width);
		if (num_colors > 0) {
			fragColor = colors[int(normalized_distance * num_colors)];
		}
		else {
			if (normalized_distance <= dash_factor) {
				fragColor = color;
			}
			else {
				discard;
			}
		}
	}
}