Programming models and shaders II

April 02 , 2006 Posted by Ana Nikoloska

The next topic for research was about ambient occlusion.

Ambient occlusion can be obtainted in a fiew different ways. I have found a lot of sites that have some information about ambient occlusion in Renderman, and the Renderman Application notes #35 are also a very resorcefull site for that

Basically the ambient occlusion gives the soft contact shadows between objects, and therefore if ambient occlusion is written as a shader no lights are necessary in the scene, because the ambient occlusion only depends on the position of the objects, how much one object occludes another. But it can be obtained in a light shader (but it is independent of the light position).

Occlusion in Renderman can both be achieved with the predefined gather loop or with a predefined occlusion function. The difference between the gather and the occlusion predefined functions is gather computes occlusion at every shading point, whereas the occlusion function only does gathers at the shading points at the corners of the micropolygon grids and interpolates the occlusion at other shading points.

gather loop

The gather loop

gather (string catergory, point P, vector dir, float angle, float samples,.token-value pairs optional values ...)

{statements when ray hits something}

else

{statements when ray misses everything}

practically casts rays in directions (based on the indirect light, i-e rays that collect information not on wether they hit a light source, but wether they hit another surface)

example:

float samples=64

nf=faceforward(normalize(N))

gather("illuminance ", P, nf, PI/2, samples, "distribution" "uniform", "surface: Cs", hitc)

{

hits+=1

totalcolor+=hitc;

}

else

{

totalcolor+=1

}

occl=hits/samples;

totalcolor=totalcolor/samples;

occl=1-occl;

The important thing to consider is the way the rays are cast

In the token value optional pairs there is a token called "distribution"

The two possible values are

  • uniform
  • cosine

The uniform distribution casts rays in a uniform fashion equaly distributing them on all sides. That has effect on the final image

here is an example with a model of a car that I have modeled

The cosine distribution on the other hand, casts rays in a cosine fashion distributing more rays near angle 0.

There is another way to get an occlusion shader with the gather function. I have noticed this in Bob Moyer's web page.

His occlusion function casts rays in a distribution based on the camera (i.e viewer's) perpective

It calculates oclusion only on the objects that can be visible in the camera view that have an occlusion shader and the center of that distribution is the reflected incident vector on the surface

surface amb_occ (float samples =1;color Camb=1)

{

float sum=0;

normal Nn=normalize(N);

vector R=reflect (normalize(I), Nn);

gather ("illuminance", P,R,PI/2,samples,"distribution","cosine")

{}

else {sum=sum+1;}

sum=sum+samples;

Ci=Camb*sum;

Oi=Os;

}

 

This way,however eventhough it seems more effective in casting the rays in a single render, can't be used for baking the occlusion inside a point cloud for an environment scene with only camera animation, because the gather function is dependent on the camera angle

No comments | Leave a comment