Resource icon

Free Simple eased pan animated motion .shader filter plugin 1.0

I swear this has to exist somewhere.. I have needed this simple animation capability for a panning background layer, with easing, in OBS and could not find a basic plugin to do it quickly and easily. I just wrote this one. hopefully this helps someone.. This .shader file is meant to be used with Exeldro's fantastic OBS-shaderfilter. Simply extract to obs-shaderfilter's examples folder and load the filter from file or copy the text from the .shader file (included below) into a new User-defined shader.
--

Code:
// Simple eased pan for a layer that exceeds the edges of the frame by graveyard420woo
uniform float speed<
    string label = "Speed";
    string widget_type = "slider";
    float minimum = 0.001;
    float maximum = 1.0;
    float step = 0.001;
> = 0.2;

uniform float pan_amount<
    string label = "Pan Amount (%)";
    string widget_type = "slider";
    float minimum = 0.0;
    float maximum = 50.0;
    float step = 1.0;
> = 10.0;

// Easing function for smooth acceleration and deceleration
float easeInOutCubic(float t) {
    t *= 2.0;
    if (t < 1.0) {
        return 0.5 * t * t * t;
    }
    t -= 2.0;
    return 0.5 * (t * t * t + 2.0);
}

float4 mainImage(VertData v_in) : TARGET
{
    // 1. Create a continuous time value controlled by the speed slider
    float time = elapsed_time * speed;

    // 2. Create a "ping-pong" effect where the value goes from 0 to 1 and then back to 0
    float pingPong = fmod(time, 2.0);
    if (pingPong > 1.0) {
        pingPong = 2.0 - pingPong;
    }

    // 3. Apply the easing function to smooth out the start and end of the movement
    float easedTime = easeInOutCubic(pingPong);

    // 4. Calculate the total travel distance based on the Pan Amount slider
    // We divide by 100.0 to convert the percentage to a decimal value.
    float travel_distance = pan_amount / 100.0;

    // 5. Calculate the horizontal offset.
    // (easedTime - 0.5) creates a range from -0.5 to 0.5.
    // Multiplying by travel_distance scales the movement to the desired amount.
    float offsetX = (easedTime - 0.5) * travel_distance;

    // 6. Apply the final offset to the texture coordinates
    float2 uv = v_in.uv;
    uv.x -= offsetX;

    // Return the pixel from the source image at the new, modified coordinate
    return image.Sample(textureSampler, uv);
}
Author
graveyard420woo
Downloads
21
Views
98
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from graveyard420woo

Top