View Full Version : anti-aliasing

 conomara06 June 2005, 09:25 AMhey, am trying to write a fairly simple RSL shader using thresholded noise. when i did a frame great, but when i did a bit of camera movement it gives artifacts. it was almost identical to the LGrustymetal shader, so i checked that out and it anti aliased in the rust and on the edges of the rust as well. it also happens with splatter.sl as well another fairly well estabhlised shader. i'm pretty sure that its not the way i'm using it. its not a shader space problem. is this something inherent to these shaders?? if so can it be remedied? I always thought that using the noise function wuold basically ensure against this kind of thing anyway any ideas would be welcome cheers conor
conomara
06 June 2005, 11:20 AM
i stripped down the spatter and lgrustymetal shaders and the version i had written to the very basics. it seems that if you want to say, in my case, use the noise function to define opacity, and

if (noise >= 0.5) {
Cgreater = colorgreater * (greaterKa*ambient() + greaterKd*diffuse(Nf));
}

if (noise < 0.5) {
Cless = Cs * (lessKa*ambient() + lessKs*specular(Nf,V,metalroughness));
}

Oi = Os;
Ci = Oi * mix (Cgreater, Cless, noise);

this will give artifacts. the only way i can i can figure this is cos i am using an edge defined by noise to creat a boundary between Cgreater and Cless. this strikes me as being similar to using any other mathematical function to define a boundary without using smoothstep to anti alias it!!!
however this is my best guess so i may not be right
if i am right then how can i blend this boundary
failing this has any one else managed to use similar function (ie LGrustymetal, spatter) with a moving camera without artifacts???

help

conor

playmesumch00ns
06 June 2005, 10:00 AM
You want to do this:

Cgreater = colorgreater * (greaterKa*ambient() + greaterKd*diffuse(Nf));
Cless = Cs * (lessKa*ambient() + lessKs*specular(Nf,V,metalroughness));

Oi = Os;
Ci = Oi * mix (Cgreater, Cless, filterstep( 0.5, noise) );

filterstep gives you a properly filtered edge that you can use to mix between the colours.

You should never, ever write an if() statement that depends on a varying variable. Always compute both paths and then blend between the two using filterstep.

There are certain exceptions to this rule (like where each path does raytracing and computing both would be very expensive), and you have to handle those cases individiually and with some clever blending to hide the aliasing.

conomara
06 June 2005, 03:06 PM
yeah i just read up and came to a similar conclusion. will try this when i get home. cheers
credit for numorous helpful posts, keep up the good work

conor

playmesumch00ns
06 June 2005, 09:07 AM
My pleasure :)

CGTalk Moderation
06 June 2005, 09:07 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

1