diff options
author | Dalai Felinto <dalai@blender.org> | 2021-09-23 16:53:38 +0300 |
---|---|---|
committer | Dalai Felinto <dalai@blender.org> | 2021-09-23 18:41:11 +0300 |
commit | d0493796a6f40db8dcdd4a9058b98a69282d4759 (patch) | |
tree | 7f9e26a80147fc473d2c6a705cfa89a87302bd97 /source/blender/gpu/shaders | |
parent | f11bcb5a80eb106560678c8c60be32ad997d6641 (diff) |
Cleanup: Remove hardcoded values and rename keyframe shape shaders
No functional change.
The shader is complicated by itself, having hardcoded values makes it
even more cryptic.
I also renamed the shader because the shader is not for the keyfarme diamond only,
but for all the keyframe shapes.
Differential Revision: https://developer.blender.org/D12615
Diffstat (limited to 'source/blender/gpu/shaders')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_keyframe_shape_frag.glsl (renamed from source/blender/gpu/shaders/gpu_shader_keyframe_diamond_frag.glsl) | 31 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl (renamed from source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl) | 17 |
2 files changed, 37 insertions, 11 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_frag.glsl b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_frag.glsl index 1c4039bc590..f0ff70f7690 100644 --- a/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_frag.glsl @@ -1,3 +1,16 @@ + +/* Values in GPU_shader.h. */ +#define GPU_KEYFRAME_SHAPE_DIAMOND (1 << 0) +#define GPU_KEYFRAME_SHAPE_CIRCLE (1 << 1) +#define GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL (1 << 2) +#define GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL (1 << 3) +#define GPU_KEYFRAME_SHAPE_INNER_DOT (1 << 4) +#define GPU_KEYFRAME_SHAPE_ARROW_END_MAX (1 << 8) +#define GPU_KEYFRAME_SHAPE_ARROW_END_MIN (1 << 9) +#define GPU_KEYFRAME_SHAPE_ARROW_END_MIXED (1 << 10) +#define GPU_KEYFRAME_SHAPE_SQUARE \ + (GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL) + flat in vec4 radii; flat in vec4 thresholds; @@ -27,24 +40,24 @@ void main() float outline_dist = -1.0; /* Diamond outline */ - if (test(0x1)) { + if (test(GPU_KEYFRAME_SHAPE_DIAMOND)) { outline_dist = max(outline_dist, radius - radii[0]); } /* Circle outline */ - if (test(0x2)) { + if (test(GPU_KEYFRAME_SHAPE_CIRCLE)) { radius = length(absPos); outline_dist = max(outline_dist, radius - radii[1]); } /* Top & Bottom clamp */ - if (test(0x4)) { + if (test(GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL)) { outline_dist = max(outline_dist, absPos.y - radii[2]); } /* Left & Right clamp */ - if (test(0x8)) { + if (test(GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL)) { outline_dist = max(outline_dist, absPos.x - radii[2]); } @@ -53,20 +66,20 @@ void main() /* Inside the outline. */ if (outline_dist < 0) { /* Middle dot */ - if (test(0x10)) { + if (test(GPU_KEYFRAME_SHAPE_INNER_DOT)) { alpha = max(alpha, 1 - smoothstep(thresholds[2], thresholds[3], radius)); } /* Up and down arrow-like shading. */ - if (test(0x300)) { + if (test(GPU_KEYFRAME_SHAPE_ARROW_END_MAX | GPU_KEYFRAME_SHAPE_ARROW_END_MIN)) { float ypos = -1.0; /* Up arrow (maximum) */ - if (test(0x100)) { + if (test(GPU_KEYFRAME_SHAPE_ARROW_END_MAX)) { ypos = max(ypos, pos.y); } /* Down arrow (minimum) */ - if (test(0x200)) { + if (test(GPU_KEYFRAME_SHAPE_ARROW_END_MIN)) { ypos = max(ypos, -pos.y); } @@ -75,7 +88,7 @@ void main() float minmax_step = smoothstep(thresholds[0], thresholds[1], minmax_dist * minmax_scale); /* Reduced alpha for uncertain extremes. */ - float minmax_alpha = test(0x400) ? 0.55 : 0.85; + float minmax_alpha = test(GPU_KEYFRAME_SHAPE_ARROW_END_MIXED) ? 0.55 : 0.85; alpha = max(alpha, minmax_step * minmax_alpha); } diff --git a/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl index 2ba89230d80..18e8b76ba23 100644 --- a/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl @@ -1,4 +1,16 @@ +/* Values in GPU_shader.h. */ +#define GPU_KEYFRAME_SHAPE_DIAMOND (1 << 0) +#define GPU_KEYFRAME_SHAPE_CIRCLE (1 << 1) +#define GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL (1 << 2) +#define GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL (1 << 3) +#define GPU_KEYFRAME_SHAPE_INNER_DOT (1 << 4) +#define GPU_KEYFRAME_SHAPE_ARROW_END_MAX (1 << 8) +#define GPU_KEYFRAME_SHAPE_ARROW_END_MIN (1 << 9) +#define GPU_KEYFRAME_SHAPE_ARROW_END_MIXED (1 << 10) +#define GPU_KEYFRAME_SHAPE_SQUARE \ + (GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL) + uniform mat4 ModelViewProjectionMatrix; uniform vec2 ViewportSize = vec2(-1, -1); uniform float outline_scale = 1.0; @@ -49,8 +61,9 @@ void main() finalOutlineColor = outlineColor; finalFlags = flags; - if (!test(0xF)) { - finalFlags |= 1; + if (!test(GPU_KEYFRAME_SHAPE_DIAMOND | GPU_KEYFRAME_SHAPE_CIRCLE | + GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL)) { + finalFlags |= GPU_KEYFRAME_SHAPE_DIAMOND; } /* Size-dependent line thickness. */ |