1
\$\begingroup\$

I have a shader which creates a circle inside of a plane mesh. I would like to get get rid of the parts around the circle, which are the r and b parts of the ALBEDO but I can't seem to figure out how to do it.

The only thing I've managed to find is ALPHA but that changes the transparency of the entire shader and not just parts of it.

shader_type spatial;

float circle(vec2 position, float radius, float feather)
{
    return smoothstep(radius, radius + feather, length(position - vec2(0.5)));
}

void fragment() {
    ALBEDO = vec3(0, circle(UV - vec2(0), 0.5, 0.005), 0);
}

Which currently looks like:

enter image description here

\$\endgroup\$
1
\$\begingroup\$

ALPHA is what you want, except you want to set it to 1 anywhere you want it be transparent. So, we can reuse your circle function and do this:

shader_type spatial;

float circle(vec2 position, float radius, float feather)
{
    return smoothstep(radius, radius + feather, length(position - vec2(0.5)));
}

void fragment() {
    ALBEDO = vec3(0, circle(UV - vec2(0), 0.5, 0.005), 0);
    ALPHA = 1.0 - circle(UV - vec2(0), 0.5, 0.005);
}

Yes, you could put circle(UV - vec2(0), 0.5, 0.005) in a variable and use that instead of calling circle twice, I didn't bother.

Note that if I didn't put 1.0 - /*...*/ I would have the circle transparent, but we want the parts around the circle transparent instead.

This is how it looks like:

The shader code above in Godot

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.