Double sided transparent gradient

Fades an element from transparent (outside) to fully visible (inside) with some config options.

Couldn’t find a working version before. I used it on a subviewportcontainer.
Default values are what I used to blur the subviewportainer in the screenshot, the size of the container is 128×40, for other sizes you have to edit the values

I chatgpt’d it, so don’t credit me

 

Shader code
shader_type canvas_item;

uniform float divide = 0.065;      
uniform float blur = 0.385;        
uniform float fade_width = 0.995;  

void fragment() {
    float left_fade_edge = fade_width;
    float right_fade_edge = 1.0 - fade_width;

    float leftFade = 1.0;
    float rightFade = 1.0;

    // Normalize to 0..1 within the fade width region
    if (UV.x < left_fade_edge) {
        float px = UV.x / fade_width;
        leftFade = smoothstep(divide, divide + blur, px);
    }

    if (UV.x > right_fade_edge) {
        float px = (1.0 - UV.x) / fade_width; // mirrored
        rightFade = smoothstep(divide, divide + blur, px);
    }

    COLOR.w *= min(leftFade, rightFade);
}
Tags
fade, gradient, Transparent
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

Double Vision w/ chromatic aberration

Double texture blend 2D

Double Bar progress, for lerping or Rpg type drain!

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments