Background color ruins Antialiasing

Started by
5 comments, last by BadEggGames 8 years, 7 months ago

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?

sphere_1440920210684.png

sphere_1440919194539.png

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

Advertisement

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

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

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));

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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

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:

PixelColor.add(BackgroundColour);

//edit

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

sphere_1440924669142.png

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

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 smile.png

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Thanks man, couldn't have done it without you :)

This topic is closed to new replies.

Advertisement