how do i fade out a texture in Godot shader?

529 Views Asked by At

Hello I was wondoring how can I fade out the edges of the rainbow shine to create somewhat of a card foil effect Using Godot 4.1 stable . This is what I've done . . . (I combined Two Shaders I found online , I'm new to shaders). Using a panel as the render target

How can I Achieve that ?

What I've Done so far :

enter image description here

here is the code:

shader_type canvas_item;
render_mode unshaded;
uniform sampler2D shine_color ;
uniform float shine_Alpha ;
uniform float shine_progress : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float shine_size : hint_range(0.01, 1.0, 0.01) = 0.1;
uniform float shine_angle : hint_range(0.0, 89.9, 0.1) = 45.0;
uniform vec2 size; //rect_size of panel passed on_ready
uniform sampler2D TEXTURE2 : hint_normal; //Image texture to use as background
uniform vec2 texture_size; //rect size of texture (to scale texture)
uniform sampler2D noise;
uniform vec2 transform; // x,y transform to clip to areas of texture
uniform float Float : hint_range(0.1,1.0); // corner radius to apply to panel, will 
apply as percentage of shortest x/y length
float scale(float value, float inMin, float inMax, float outMin, float outMax) {
    return (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}
void fragment()
{
    float yx_ratio = size.y/size.x;
    float xy_ratio = size.x/size.y;
    float grow = max(yx_ratio,xy_ratio);
    float shrink = min(yx_ratio,xy_ratio);
    ivec2 img_size = textureSize(TEXTURE2,0);
    float img_xratio = texture_size.x/size.x;
    float img_yratio = texture_size.y/size.y;
    float tfm_xratio = transform.x/size.x;
    float tfm_yratio = transform.y/size.y;
    vec4 blend = texture(noise, UV);
    vec2 top_left = vec2(0.0,0.0);
    vec2 top_right = vec2(1.0,0.0);
    vec2 bottom_left = vec2(0.0,1.0);
    vec2 bottom_right = vec2(1.0,1.0);

if (UV.x <= top_left.x && UV.y <= top_left.y){
     if (!(distance(vec2(UV.x,UV.y*grow),vec2(top_left.x,top_left.y*grow))<0.0)){
        COLOR.a = 0.0;
    }
}
if (UV.x>=top_right.x &&  UV.y <= top_right.y){
     if (!(distance(vec2(UV.x,UV.y*grow),vec2(top_right.x,top_right.y*grow))<0.0)){
        COLOR.a = 0.0;
    }
}
if (UV.x<=bottom_left.x && UV.y>=bottom_left.y){
     if (!(distance(vec2(UV.x,UV.y*grow),vec2(bottom_left.x,bottom_left.y*grow))<0.0)){
    COLOR.a = 0.0;
    }
}
if (UV.x>=bottom_right.x && UV.y>=bottom_right.y){
     if (!(distance(vec2(UV.x,UV.y*grow),vec2(bottom_right.x,bottom_right.y*grow))<0.0)){
    COLOR.a = 0.0;
    }
}
COLOR.rgb = texture(TEXTURE2,vec2((UV.x/img_xratio)+tfm_xratio,(UV.y/img_yratio)+tfm_yratio)).rgb;
vec4 base = texture(TEXTURE2, UV);
if(blend.r * 1.6> Float ){
    COLOR.r = .0;
    COLOR.g = .0;
    COLOR.b = .0;
    COLOR.a = 1.0;
}
if(base.r * base.g > Float){
    COLOR.r = 1.0;
    COLOR.g = 1.0;
    COLOR.b = 1.0;
    COLOR.a = 1.0;
}
float slope = tan(radians(shine_angle));
float progress = scale(shine_progress, 0.0, 1.0, -1.0 - shine_size - shine_size * slope, 1.0 * slope);
float shine = step(slope * UV.x - UV.y, progress + shine_size + shine_size * slope) - step(slope * UV.x - UV.y, progress);
if (COLOR.r != 0.0 && COLOR.g != 0.0 && COLOR.b != 0.0){
    vec4 tex = texture(shine_color,UV);
    COLOR.rgb = mix(COLOR.rgb, tex.rgb, shine * shine_Alpha);
}

}

0

There are 0 best solutions below