• 11
• 9
• 10
• 9
• 10

# Background color ruins Antialiasing

This topic is 966 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all

I am having a new problem with my ray tracer. My Antialiasing is simply shooting 100 random rays at each pixel then averaging. This works great but only when the background color is black or white. As soon as I make it a different color, every edge above the horizon looks fuzzy. Anyone know why this is? I understand that if the sky is black then it adds nothing to the pixel color average and if its white, it adds 1 and averages out. Is there a way to add a color in a way that doesn't ruin anti aliasing?

I should note that this happens to non gradient colored skies too.

##### Share on other sites

I'm going to go with overflow in your colors again. Can you post your anti-aliasing code, where it averages the colors.

##### Share on other sites

I simply average r,g and b by the amount of rays for each pixel

PixelColor.x = PixelColor.x / rays.length;
PixelColor.y = PixelColor.y / rays.length;
PixelColor.z = PixelColor.z / rays.length;

if(PixelColor.x>1){
PixelColor.x=1.0f;
}

if(PixelColor.y>1){
PixelColor.y=1.0f;
}

if(PixelColor.z>1){
PixelColor.z=1.0f;
}

image.drawPixel(x, y, Color.rgba8888(PixelColor.x, PixelColor.y, PixelColor.z, 1));

##### Share on other sites

How are you adding them up to obtain PixelColor, though? What color is the blue background in RGB float values? Also, could you try with a purple background color? (not exactly the same color as the middle sphere but something nearby). I'd be somewhat curious to see the result.

##### Share on other sites

Interesting, purple background looks smooth:

The background color vector is:

BackgroundColour = new Vector3(1.0f,0f,0.8705f); //purple

If the ray doesn't intersect a sphere or a plane then the background color is added with:

//edit

This is weird. I just set the background color back to the gradient, hit compile and this came out:

Exact same code, just restarted android studio. Must be some kind of weird android studio/java/emulator garbage collection thing going on. This development environment has strange outputs if you use it to long. Sorry about that

##### Share on other sites

It could be that it was running your old code before you added anti-aliasing or something, dunno. If it works now then cool, looks nice by the way