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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2017-07-13 17:44:02 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2017-07-13 17:47:58 +0300
commit474454be3976f51d59aff327491a5fd2ab48abc2 (patch)
tree895407db5881d98958dd2b56ea4e95b042f7e3d6 /source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl
parentc9aef27326d54ed053edb37d27fe5571805139b9 (diff)
Cleanup/rename etc. dashed line shaders.
Goal is to make them more modular, to allow more variants (variable single-color, thickness, ...) to be added without having to copy-and-change-one-line of whole chain of shaders.
Diffstat (limited to 'source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl')
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl44
1 files changed, 28 insertions, 16 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl
index 346d3b3c6d9..7caf00f58fd 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl
@@ -1,38 +1,50 @@
-// Draw dashed lines, perforated in screen space.
-
-noperspective in float distance_along_line;
-out vec4 fragColor;
+/*
+ * Fragment Shader for dashed lines, with uniform multi-color(s), or any single-color, and any thickness.
+ *
+ * Dashed is performed in screen space.
+ */
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];
+noperspective in float distance_along_line;
+noperspective in vec4 color_geom;
+
+out vec4 fragColor;
+
void main()
{
- /* Solid line cases, simple. */
- if (num_colors == 1) {
- fragColor = colors[0];
- }
- else if (dash_factor >= 1.0f) {
- fragColor = color;
- }
- else {
+ /* Multi-color option. */
+ if (num_colors > 0) {
+ /* Solid line case, simple. */
+ if (num_colors == 1) {
+ fragColor = colors[0];
+ }
/* Actually dashed line... */
- float normalized_distance = fract(distance_along_line / dash_width);
- if (num_colors > 0) {
+ else {
+ float normalized_distance = fract(distance_along_line / dash_width);
fragColor = colors[int(normalized_distance * num_colors)];
}
+ }
+ /* Single color option. */
+ else {
+ /* Solid line case, simple. */
+ if (dash_factor >= 1.0f) {
+ fragColor = color_geom;
+ }
+ /* Actually dashed line... */
else {
+ float normalized_distance = fract(distance_along_line / dash_width);
if (normalized_distance <= dash_factor) {
- fragColor = color;
+ fragColor = color_geom;
}
else {
discard;