0 votes

Hey gang! I'm using a greyscale mask on a shader to set the alpha value for a 2D canvas item. I have checked the mask PNG to make sure that all the colors are pixel perfect, and there are no anti-aliasing artifacts or anything there. However, when I go to render, godot creates artifacts that seem to result from interpolation from texture sampling. How do I fix this?

Here is the effect I'm seeing

EDIT: klaas has confirmed my suspicions about interpolation. For anyone ecnountering the same issue, here is a sample method to use texelFetch() from UV in lieu of texture:

float value = texture(mask, UV, 1).r;


int texelX = int(UV.x * float(width) + float(offset_x)  );
int texelY = int(UV.y * float(height) + float(offset_y) );
ivec2 texel = ivec2( texelX, texelY );
float value = texelFetch( mask, texel, 0).r;


in Engine by (12 points)
edited by

1 Answer

+1 vote

those are sampling artifacts from the GPU itself.

Try to use texelFetch() instead of texture() this will give you destinct pixels of the texture. Texture() will allways interpolate due to subpixel sampling.

Read this for some more insight: https://gamedev.stackexchange.com/questions/66448/how-do-opengls-texelfetch-and-texture-differ

by (4,084 points)

This is exactly the answer I needed. Thank you.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.