I'm working with OpenGL >3.3 and I was wondering if there is a way to find out if a fragment belongs to the background easily in the fragment Shader. (I'm working with #Version 330).
I'm using a multipass rendering, and I have to work with neighbors of a fragment that are actually not the background... (I'm working with pointcloud).
So I tried to do :
uniform vec3 backGroundColor;
float dx = 1/screenwidth;
float dy = 1/screenHeight;
for (int i=-3; i<3; ++i){
for (int j=-3; j<3; ++j){
vec3 frag = texture(screenTexture, TexCoords + vec2(i*dx, j*dy)).xyz;
if (frag.x != backGroundColor.x && frag.y != backGroundColor.y && frag.z != backGroundColor.z)
do something...
else
do other Things...
}
}
But I believe this is underproductive... (And not that right because of float precisions ...) Is there any better way to achieve what I'm trying to?