56 lines
2.2 KiB
GLSL
56 lines
2.2 KiB
GLSL
float getSdfRectangle(in vec2 p, in vec2 xy, in vec2 b)
|
|
{
|
|
vec2 d = abs(p - xy) - b;
|
|
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0);
|
|
}
|
|
|
|
vec2 normalize(vec2 value, float isPosition) {
|
|
return (value * 2.0 - (iResolution.xy * isPosition)) / iResolution.y;
|
|
}
|
|
|
|
float antialising(float distance) {
|
|
return 1. - smoothstep(0., normalize(vec2(2., 2.), 0.).x, distance);
|
|
}
|
|
|
|
vec2 getRectangleCenter(vec4 rectangle) {
|
|
return vec2(rectangle.x + (rectangle.z / 2.), rectangle.y - (rectangle.w / 2.));
|
|
}
|
|
float ease(float x) {
|
|
return pow(1.0 - x, 3.0);
|
|
}
|
|
|
|
// Toned down colors with reduced alpha
|
|
const vec4 TRAIL_COLOR = vec4(0.7, 0.495, 0.111, 0.5);
|
|
const vec4 TRAIL_COLOR_ACCENT = vec4(0.8, 0., 0., 0.6);
|
|
const float DURATION = 0.25;
|
|
const float EXPANSION_FACTOR = 0.05;
|
|
|
|
void mainImage(out vec4 fragColor, in vec2 fragCoord)
|
|
{
|
|
#if !defined(WEB)
|
|
fragColor = texture(iChannel0, fragCoord.xy / iResolution.xy);
|
|
#endif
|
|
// Normalization for fragCoord to a space of -1 to 1;
|
|
vec2 vu = normalize(fragCoord, 1.);
|
|
vec2 offsetFactor = vec2(-.5, 0.5);
|
|
|
|
// Normalization for cursor position and size;
|
|
// cursor xy has the postion in a space of -1 to 1;
|
|
// zw has the width and theight
|
|
vec4 currentCursor = vec4(normalize(iCurrentCursor.xy, 1.), normalize(iCurrentCursor.zw, 0.));
|
|
vec4 previousCursor = vec4(normalize(iPreviousCursor.xy, 1.), normalize(iPreviousCursor.zw, 0.));
|
|
|
|
vec2 centerCC = getRectangleCenter(currentCursor);
|
|
vec2 centerCP = getRectangleCenter(previousCursor);
|
|
|
|
float sdfCurrentCursor = getSdfRectangle(vu, currentCursor.xy - (currentCursor.zw * offsetFactor), currentCursor.zw * 0.5);
|
|
|
|
float progress = clamp((iTime - iTimeCursorChange) / DURATION, 0.0, 1.0);
|
|
float easedProgress = ease(progress);
|
|
float lineLength = distance(centerCC, centerCP) * EXPANSION_FACTOR; // Reduced expansion
|
|
|
|
//cursorblaze
|
|
vec4 trail = mix(TRAIL_COLOR_ACCENT, fragColor, 1. - smoothstep(0., sdfCurrentCursor + .001, 0.002)); // Smaller blend radius
|
|
trail = mix(TRAIL_COLOR, trail, 1. - smoothstep(0., sdfCurrentCursor + .001, 0.002)); // Smaller blend radius
|
|
fragColor = mix(trail, fragColor, 1. - smoothstep(0., sdfCurrentCursor, easedProgress * lineLength));
|
|
}
|