Author Topic: Dissolve/Gradient Effect  (Read 895 times)

DJO_Maverick

  • Newbie
  • *
  • Posts: 4
    • View Profile
Dissolve/Gradient Effect
« on: April 14, 2023, 09:23:18 PM »
Trying to throw together a custom layout at the moment (sort of porting something I did for ES a while back for personal use), and can't quite find how to achieve a certain effect.

I'd like my video snap to be in a bit of a spotlight effect, where it is rounded off (circular or ovoid...  or trapezoidal, long story) but the image dissolves at those edges.  I gather something like that would have to be done with a shader, wondering if anyone has one in use for similar purpose, or could give me some guidance on how to implement it?

Thanks,

DJO_Maverick

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Dissolve/Gradient Effect
« Reply #1 on: April 16, 2023, 06:16:57 PM »
Found a solid example option in Shadertoys, but struggling to convert it to work in AM.  https://www.shadertoy.com/view/DscSW7

Original
Code: [Select]
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
    vec2 uv = fragCoord.xy / iResolution.y;
   
    float margin = 0.125;
    float radius = 0.15;
   
    vec2 halfDimensions = iResolution.xy / iResolution.y * 0.5;
   
    vec2 point = abs(uv - halfDimensions);
    vec2 corner = halfDimensions - margin - radius;
    vec2 anchor = min(point, corner);
   
    float distance = length(point - anchor);
   
    fragColor = vec4(smoothstep(radius, radius + margin, distance));
}

Modified
Code: [Select]
uniform vec2 rez;

void main()
{
float margin = 0.125;
float radius = 0.25;

    vec2 uv = gl_FragCoord.xy / rez.y;
   
    vec2 halfDimensions = rez.xy / rez.y * 0.5;
   
    vec2 point = abs(uv - halfDimensions);
    vec2 corner = halfDimensions - margin - radius;
    vec2 anchor = min(point, corner);
   
    float distance = length(point - anchor);
   
    gl_FragColor = vec4(smoothstep(radius, radius + margin, distance));
}

I know pretty much nothing about coding these myself, so I'm sure I'm missing something stupid.  At the moment, it's just changing the snap to a solid white rectangle.