#How to contain a shader in a circle?

1 messages · Page 1 of 1 (latest)

stray meadow
#

Hello, I am trying to make an invert shader and have been trying to contain it a circle for a few hours now but nothing seems to work. if someone knows how to do this please give me a script that works for this situation or most shaders. it would really help. Yes I did make a circle mask but that also did not help somehow.

#

the code:

#

the mask:

civic bloom
#

Could you try to rephrase what you want to do in other words or show an image that explains what is you desired outcome?

What I think you do from your shader: You want to invert the already rendered background and mask it. But you also do some UV manipulation. There I'm not sure what you're are doing.

And also what kind of mesh is used?

stray meadow
civic bloom
#

You are for instance not sampling a mask and not modifing the alpha

stray meadow
civic bloom
#

In other words, you should sample a value from a mask texture and then multiply this with alpha

stray meadow
#

if you don't mind at all

stray meadow
#

and also again, I am on 2D not 3D

civic bloom
#

Are you using the mask in the default texture?

#

Usually you would sample it like:

float maskOpacity = texture( TEXTURE, UV).r;

And then:

COLOR.a = COLOR.a * maskOpacity

stray meadow
#

ohhh I see

#

let me try that

stray meadow
#

Hmm unfortunately it didn't work

cold umbra
#
shader_type canvas_item;

uniform sampler2D SCREEN_TEXTURE: hint_screen_texture, filter_linear_mipmap;
uniform float size;
uniform vec2 center;
uniform float force;
uniform float thickness;


void vertex() {
    // Called for every vertex the material is visible on.
}

void fragment() {
    float ratio = SCREEN_PIXEL_SIZE.x / SCREEN_PIXEL_SIZE.y;
    vec2 scaledUV = (UV - vec2(0.5, 0.0)) / vec2(ratio, 1.0) + vec2( 0.0, 0.0);
    float mask = 1.0 - step(size, length(scaledUV - center));
    vec2 disp = normalize(scaledUV - center) * force;

    // Rewritten slightly so the variable names make more sense.
    vec4 screen_texture = texture(SCREEN_TEXTURE, SCREEN_UV - disp);
    vec4 inverted_color = 1.0 - screen_texture;

    // Either of these should work. Comment out whichever one you are not using.
    // Option 1.
    COLOR = mix(screen_texture, inverted_color, mask);
    COLOR.a = 1.0;

    // Option 2:
    COLOR = inverted_color;
    COLOR.a = mask;
}
#

I didn't take the time to really look at how you're calculating the circular mask.

#

I also don't know what the disp and force uniforms are supposed to be doing.

#

With a size of .25 and a center of 0.0, 0.5, I got this in testing:

#

In the future it would be very helpful if you paste example code as code rather than a screenshot :)

stray meadow
#

Mb mb😭

#

And thank you so much too

#

@civic bloom thank you very much as well

stray meadow