#How to contain a shader in a circle?
1 messages · Page 1 of 1 (latest)
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?
I basically just want the invert shader to be inside the circle
You are for instance not sampling a mask and not modifing the alpha
and not outside of it
In other words, you should sample a value from a mask texture and then multiply this with alpha
hmm
if you don't mind at all
but if what you're saying is correct, then how shall I modify this script here?
and also again, I am on 2D not 3D
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
Hmm unfortunately it didn't work
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 :)
Ahem
Mb mb😭
And thank you so much too
@civic bloom thank you very much as well
I feel guilty to copy and paste this now for some reason