diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2018-10-19 18:55:19 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2018-10-29 22:04:19 +0300 |
commit | a0dfa320cddd8396911058bae7c3a0eb52e7f2ee (patch) | |
tree | 9fbb05f44a99a83354edbfea586edbb9130b886c /source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl | |
parent | b18ac77df3c2eb002bd4c5ed2e6b606535cb67cc (diff) |
Dope Sheet: new option to display keyframe interpolation mode and extremes.
With the new automatic handle algorithm, it is possible to do a lot
of the animation via keyframes without touching the curves. It is
however necessary to change the keyframe interpolation and handle
types in certain cases. Currently the dopesheet/action editor
allows changing the types, but does not show them in any way.
To fix, add a new menu option to display this information. For handle
type, it is represented using the shape of the key icons: diamond for
Free, clipped diamond for Aligned, square for Vector, circle for Auto
Clamp, and cirle with dot for Automatic.
Non-bezier interpolation is a property of intervals between keys,
so it is marked by drawing lines, similar to holds. In this initial
version, only the fact of non-bezier interpolation is displayed,
without distinguishing types. For summaries, the line is drawn at
half alpha if not all curves in the group are non-bezier.
In addition, it is sometimes helpful to know the general direction
of change of the curve, and which keys are extremes. This commit
also adds an option to highlight extremes, based on comparing the
keyed values with adjacent keys. Half-intensity display is used
for overshot bezier extremes, or non-uniform summaries.
Reviewers: brecht, aligorith, billreynish
Differential Revision: https://developer.blender.org/D3788
Diffstat (limited to 'source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl | 81 |
1 files changed, 65 insertions, 16 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl b/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl index c49832bf9b4..26eb864821a 100644 --- a/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl @@ -1,34 +1,83 @@ uniform mat4 ModelViewProjectionMatrix; +uniform vec2 ViewportSize = vec2(-1, -1); -const float pixel_fudge = sqrt(2.0); -const float outline_width = 1.15 * pixel_fudge; +const float line_falloff = 1.0; +const float circle_scale = sqrt(2.0 / 3.1416); +const float square_scale = sqrt(0.5); + +const float diagonal_scale = sqrt(0.5); in vec2 pos; in float size; in vec4 color; in vec4 outlineColor; -out vec4 finalColor; -out vec4 finalOutlineColor; -out vec4 radii; +in int flags; + +flat out vec4 finalColor; +flat out vec4 finalOutlineColor; + +flat out int finalFlags; + +flat out vec4 radii; +flat out vec4 thresholds; + +bool test(int bit) { + return (flags & bit) != 0; +} + +vec2 line_thresholds(float width) { + return vec2(max(0, width - line_falloff), width); +} void main() { gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0); - // pass through unchanged - gl_PointSize = size + pixel_fudge; // 0.5 pixel_fudge on either side + /* Align to pixel grid if the viewport size is known. */ + if (ViewportSize.x > 0) { + vec2 scale = ViewportSize * 0.5; + vec2 px_pos = (gl_Position.xy + 1) * scale; + vec2 adj_pos = round(px_pos - 0.5) + 0.5; + gl_Position.xy = adj_pos / scale - 1; + } + + /* Pass through parameters. */ finalColor = color; finalOutlineColor = outlineColor; + finalFlags = flags; + + if (!test(0xF)) { + finalFlags |= 1; + } + + /* Size-dependent line thickness. */ + float half_width = (0.06 + (size - 10) * 0.04); + float line_width = half_width + line_falloff; + + /* Outline thresholds. */ + thresholds.xy = line_thresholds(line_width); + + /* Inner dot thresholds. */ + thresholds.zw = line_thresholds(line_width * 1.6); + + /* Extend the primitive size by half line width on either side; odd for symmetry. */ + float ext_radius = round(0.5 * size) + thresholds.x; + + gl_PointSize = ceil(ext_radius + thresholds.y) * 2 + 1; + + /* Diamond radius. */ + radii[0] = ext_radius * diagonal_scale; + + /* Circle radius. */ + radii[1] = ext_radius * circle_scale; - // calculate concentric radii in pixels - float radius = 0.5 * gl_PointSize; + /* Square radius. */ + radii[2] = round(ext_radius * square_scale); - // start at the outside and progress toward the center - radii[0] = radius; - radii[1] = radius - pixel_fudge; - radii[2] = radius - outline_width; - radii[3] = radius - outline_width - pixel_fudge; + /* Min/max cutout offset. */ + radii[3] = -line_falloff; - // convert to PointCoord units - radii /= size; + /* Convert to PointCoord units. */ + radii /= gl_PointSize; + thresholds /= gl_PointSize; } |