Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl
| Show All 11 Lines | |||||
| uniform float dash_factor; /* if > 1.0, solid line. */ | uniform float dash_factor; /* if > 1.0, solid line. */ | ||||
| /* More advanced mode, allowing for complex, multi-colored patterns. | /* More advanced mode, allowing for complex, multi-colored patterns. | ||||
| * Enabled when colors_len > 0. */ | * Enabled when colors_len > 0. */ | ||||
| /* Note: max number of steps/colors in pattern is 32! */ | /* Note: max number of steps/colors in pattern is 32! */ | ||||
| uniform int colors_len; /* Enabled if > 0, 1 for solid line. */ | uniform int colors_len; /* Enabled if > 0, 1 for solid line. */ | ||||
| uniform vec4 colors[32]; | uniform vec4 colors[32]; | ||||
| noperspective in float distance_along_line; | flat in vec4 color_vert; | ||||
| noperspective in vec4 color_geom; | |||||
| noperspective in vec2 stipple_pos; | |||||
| flat in vec2 stipple_start; | |||||
| out vec4 fragColor; | out vec4 fragColor; | ||||
| void main() | void main() | ||||
| { | { | ||||
| float distance_along_line = distance(stipple_pos, stipple_start); | |||||
| /* Multi-color option. */ | /* Multi-color option. */ | ||||
| if (colors_len > 0) { | if (colors_len > 0) { | ||||
| /* Solid line case, simple. */ | /* Solid line case, simple. */ | ||||
| if (colors_len == 1) { | if (colors_len == 1) { | ||||
| fragColor = colors[0]; | fragColor = colors[0]; | ||||
| } | } | ||||
| /* Actually dashed line... */ | /* Actually dashed line... */ | ||||
| else { | else { | ||||
| float normalized_distance = fract(distance_along_line / dash_width); | float normalized_distance = fract(distance_along_line / dash_width); | ||||
| fragColor = colors[int(normalized_distance * colors_len)]; | fragColor = colors[int(normalized_distance * colors_len)]; | ||||
| } | } | ||||
| } | } | ||||
| /* Single color option. */ | /* Single color option. */ | ||||
| else { | else { | ||||
| /* Solid line case, simple. */ | /* Solid line case, simple. */ | ||||
| if (dash_factor >= 1.0f) { | if (dash_factor >= 1.0f) { | ||||
| fragColor = color_geom; | fragColor = color_vert; | ||||
| } | } | ||||
| /* Actually dashed line... */ | /* Actually dashed line... */ | ||||
| else { | else { | ||||
| float normalized_distance = fract(distance_along_line / dash_width); | float normalized_distance = fract(distance_along_line / dash_width); | ||||
| if (normalized_distance <= dash_factor) { | if (normalized_distance <= dash_factor) { | ||||
| fragColor = color_geom; | fragColor = color_vert; | ||||
| } | } | ||||
| else { | else { | ||||
| discard; | discard; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||