# anti-aliasing

#1

hey, 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

#2

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 * (greaterKaambient() + greaterKddiffuse(Nf));
}

if (noise < 0.5) {
Cless = Cs * (lessKaambient() + lessKsspecular(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

#3

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, [b]filterstep( 0.5, noise)[/b] );

``````

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.

#4

yeah i just read up and came to a similar conclusion. will try this when i get home. cheers