This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/gpu/shaders/gpu_shader_keyframe_shape_frag.glsl
Jason Fielder dedca2c994 Fix T103313: Resolve shader compilation failures when enabling GPU workarounds.
A number of paths resulted in compilation errors after porting EEVEE to use Create-Info. Namely the fallback path for cubemap support. A number of other strict compilation failures regarding format comparison also required fixing when this mode is enabled.

Authored by Apple: Michael Parkin-White

Ref T96261

Reviewed By: fclem

Maniphest Tasks: T96261, T103313

Differential Revision: https://developer.blender.org/D16819
2022-12-20 14:22:09 +01:00

93 lines
2.7 KiB
GLSL

/* Values in GPU_shader.h. */
#define GPU_KEYFRAME_SHAPE_DIAMOND (1u << 0)
#define GPU_KEYFRAME_SHAPE_CIRCLE (1u << 1)
#define GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL (1u << 2)
#define GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL (1u << 3)
#define GPU_KEYFRAME_SHAPE_INNER_DOT (1u << 4)
#define GPU_KEYFRAME_SHAPE_ARROW_END_MAX (1u << 8)
#define GPU_KEYFRAME_SHAPE_ARROW_END_MIN (1u << 9)
#define GPU_KEYFRAME_SHAPE_ARROW_END_MIXED (1u << 10)
#define GPU_KEYFRAME_SHAPE_SQUARE \
(GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL)
const float diagonal_scale = sqrt(0.5);
const float minmax_bias = 0.7;
const float minmax_scale = sqrt(1.0 / (1.0 + 1.0 / minmax_bias));
bool test(uint bit)
{
return (finalFlags & bit) != 0u;
}
void main()
{
vec2 pos = gl_PointCoord - vec2(0.5);
vec2 absPos = abs(pos);
float radius = (absPos.x + absPos.y) * diagonal_scale;
float outline_dist = -1.0;
/* Diamond outline */
if (test(GPU_KEYFRAME_SHAPE_DIAMOND)) {
outline_dist = max(outline_dist, radius - radii[0]);
}
/* Circle outline */
if (test(GPU_KEYFRAME_SHAPE_CIRCLE)) {
radius = length(absPos);
outline_dist = max(outline_dist, radius - radii[1]);
}
/* Top & Bottom clamp */
if (test(GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL)) {
outline_dist = max(outline_dist, absPos.y - radii[2]);
}
/* Left & Right clamp */
if (test(GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL)) {
outline_dist = max(outline_dist, absPos.x - radii[2]);
}
float alpha = 1 - smoothstep(thresholds[0], thresholds[1], abs(outline_dist));
/* Inside the outline. */
if (outline_dist < 0) {
/* Middle dot */
if (test(GPU_KEYFRAME_SHAPE_INNER_DOT)) {
alpha = max(alpha, 1 - smoothstep(thresholds[2], thresholds[3], length(absPos)));
}
/* Up and down arrow-like shading. */
if (test(GPU_KEYFRAME_SHAPE_ARROW_END_MAX | GPU_KEYFRAME_SHAPE_ARROW_END_MIN)) {
float ypos = -1.0;
/* Up arrow (maximum) */
if (test(GPU_KEYFRAME_SHAPE_ARROW_END_MAX)) {
ypos = max(ypos, pos.y);
}
/* Down arrow (minimum) */
if (test(GPU_KEYFRAME_SHAPE_ARROW_END_MIN)) {
ypos = max(ypos, -pos.y);
}
/* Arrow shape threshold. */
float minmax_dist = (ypos - radii[3]) - absPos.x * minmax_bias;
float minmax_step = smoothstep(thresholds[0], thresholds[1], minmax_dist * minmax_scale);
/* Reduced alpha for uncertain extremes. */
float minmax_alpha = test(GPU_KEYFRAME_SHAPE_ARROW_END_MIXED) ? 0.55 : 0.85;
alpha = max(alpha, minmax_step * minmax_alpha);
}
fragColor = mix(finalColor, finalOutlineColor, alpha);
}
/* Outside the outline. */
else {
fragColor = vec4(finalOutlineColor.rgb, finalOutlineColor.a * alpha);
}
}