home     graphics   guestbook                  

 

                        MOSAIC SHADER   DEVELOPMENT

 

mosaic sourcecode

 

Main features observed in a real mosaic floor,that were used to model the shader:

·        each block of tile is made up of multi-colored chips distributed randomly.

·        the tile has a characteristic white mortar.

·        the grooves that separate the tile blocks has a characteristic crumbled look.

·        Tile blocks have a random distribution of dust.

·        There is a slight color variation between individual tile blocks.

·        Tiles have a characteristic specular reflectance model,where the chips have a more glossy reflection than the surrounding white mortar.

·        Tiles have a very slight reflectivity.

                    

 

The noise function is used as the base for generating the mosaic chips on the surface.Below is shown a surface with only plain noise applied to it.

Fig : Surface with only noise applied to it.

next to create the chips the noise function is filtered using a threshold value,only the noises above the threshold value showup on the surface,the rest gets filtered.this creates chip like shapes on the surface.

float ni = float noise(pshad*50);

float   mono =1-smoothstep(0.6,1,ni);

color surfcolor =  mono;

Fig : Surface with thresholded noise.

Now the surface at present,has a distribution of  black chips on it.now the next challenge is to create multi-colored chips on the surface. It is almost impossible to create randomly distributed realistic multicolored chips using a single thresholded noise function.so,the trick here is to use multiple thresholded noise functions one for each color of chips.here care must be taken to reduce the frequency of the various colored chips,so that overlap of chips is kept to a minimum,to ensure realism..

 

float nib = float noise(pshad*10);

float   black =1-smoothstep(0.6,1,nib);

color surfcolor =  black;

 

float nir = float noise(pshad*10);

float   red =1-smoothstep(0.6,1,nir);

color surfcolor =  red;

 

float nig = float noise(pshad*10);

float   green =1-smoothstep(0.6,1,nig);

color surfcolor =  green;

 

float nip = float noise(pshad*10);

float   pink =1-smoothstep(0.6,1,nip);

color surfcolor =  pink;

 

float niw = float noise(pshad*10);

float   white =1-smoothstep(0.6,1,niw);

color surfcolor =  white;

 

Fig : Mosaic with multicolored chips

 

Till now we have worked on what appears to be a single block of tile.To draw  multiple blocks of tiles on the surface,first we need to obtain a coordinate system across the surface.for this we make use of  Projectto2D() function(Refer Advanced Renderman for explanation on this function).This function returns a uniform (s,t) parametric coordinate across the surface of the geometry.The values of  s,t  range from 0 to 1 across the surface,irrespective of the shape and size of the geometric surface.

The (s,t) value of the point currently being shaded,along with the groove width and groove height values is used as input  parameters to call the grooves() function(For more explanation on this function,refer to the tilepattern  function in the ceramictile shader(section 12.3) of  advanced renderman).this function uses the pulsetrain function to draw a series of stripes across the surface which can be used as grooves for the tile blocks.

float grooves (  float ss, tt ; float groovewidth, grooveheight; )

{      

    return pulsetrain (groovewidth,1,ss+groovewidth/2)

           * pulsetrain (grooveheight,1,tt+grooveheight/2);

}

float pulsetrain (float edge, period, x)

{

    return pulse (edge, period, mod(x,period));

}

float pulse (float edge0, edge1, x)

{

    return step(edge0,x) - step(edge1,x);

}

Fig : Default pulse train

 

The default pulse train does not have the realistic appearance of the tile grooves.The actual grooves appear crumbled and are often irregular.To modify the appearance of the pulse train,To give it a crumbled look,we use the Fbm() noise function to add irregularity to the pulse train.heres the modified code for the grooves() function,i have added all kinds of offsets to get the correct looks,you can add your own offsets.just make sure the grooves look nice.

Float grooves(  float ss, tt; float groovewidth, grooveheigh; )

{  

float gh = ((grooveheight * .8) + .012*fBm (point((ss),(tt*2)+90,(ss+tt)+25) *1000,filterwidthp(point((ss*30)-53,(tt*2)-9,(ss+tt)-54)),4,2,0.1));

float gh = ((grooveheight * .8) + .012*fBm (point((ss)-53,(tt*2)-9,(ss+tt)-54)*5000,filterwidthp(point((ss*30)-53,(tt*2)-9,(ss+tt)-54)),4,2,0.1));

    float bw = 1 - gw;

    float bh = 1 - gh;

    return pulsetrain (gw,bw,ss+groovewidth/2)

             * pulsetrain (gh,bh,tt+grooveheight/2);

}

Fig : Modified pulse train - with a realistic groove appearance

 

Drawing multiple tile blocks on the surface :

when you increase the number of tile blocks across the surface,the size of the tile blocks along with the chips have to be scaled down relativley

This is done as follows:

·        we take the nbh(number of blocks horizonally) and nbv(number of blocks vertically) as two input parameters to the shader.

·        Then we scale down the (s,t) values returned by the ProjectTo2D() function according to the values of nbh,nbv using the following equations,

float SS=mod(ss*nbh,1);

float TT=mod(tt*nbv,1);

ss,tt are the actual s,t coordinates returned by the ProjectTo2D() function. SS,TT are the modified  coordinates used as input to the grooves() function.As a result the size of the blocks and the chip sizes gets scaled down to accommodate the desired number of blocks horizontally and vertically.

NOTE: theoretically the shader should be able to take all possible values for the parameters 'nbh' and 'nbv'.But in reality the shader works  correctly only for values of  1,2 and 4 .for the rest of the values,the grooves get really messed up.The reason for this strange behaviour,is that the default input value for the groovewidth and grooveheight  parameters is really small (groveh=0.005,grovew=0.005).such small values causes the pulse train function to go wacky.so,increasing the values of groove width and groove height  solves this problem.BUT this affects the realism of the tiles.therefore,If u want to increase the number of tile blocks to a large number,u can do so by increasing the st mapping of the surface in the RIB file.

 

Dust :

Randomly scattered dust across the tile blocks is modeled by using the fBM function ,

float dust = dust_intensity*clamp(fBm((P),filterwidthp(P),30,12,01),-.2,1);

where,dust_intensity is a shader parameter that gives the intensity of the dust.

Fig :Tile blocks with dust

 

 

Tile to Tile mottling :

Color variation between individual tile blocks is modeled using the cell noise function.

float offset =cellnoise((ss*nbh)+6,(tt*nbv)-10);

this offset is added to the final color equation to produce the tile to tile color variation.

Fig : Mosaic blocks with inter tile color difference

 

Modified Lighting model :

With the default lighting equation,the material does not actually interact with the lights placed in the scene.when lights are placed in the scene,they simply illuminate the mosaic surface,there is no true interaction of light with the surface.

Heres the default lighting equation,

ambientcolor = Ka * ambient();

diffusecolor = Kd * diffuse(nf);

i = normalize(-I);

speccolor = Ks * specular(nf, i, roughness) * hilitecolor;

Ci = Oi * Cs * surfcolor * (ambientcolor + diffusecolor + speccolor);

Here the ambient color,diffuse color and the specular color are simply added together.this leads to a rather uninteresting and uniformly lit surface.this lighting creates bleaching in and around the region of specular highlight.

Fig : Mosaic with just a light above it

This looks more like the light is being shined on an image of the mosaic floor,there is no true interaction  between the lights and any of the components of the mosaic floor.

In reality the reflectance model of an actual mosaic floor is very different,they have the following characterstics,

·        the chips reflect the specular highlight more stongly than the surrounding white background.Around the region of specular highlight,they loose their color and appear to be glossy white.

·        The bleaching effect in and around the region of specular highlight due to the default reflectance model,is not so much observed in real mosaic floors.

·        The grooves appear to be especially darker inside the region of specular highlight,than otherwise.

Our modified reflectance model takes into account the above mentioned features,to produces a very realistic reflectance model,in which the marerials of the surface appear to be truly interacting with the lights shined on them.

To produce the glossy white reflectivity of the chips,in the region of specular highlight,we modify the way in which the chips are colored to take into account the region of specular highlight.

Heres how the chips are colored before taking into account the specular highlight,

if(monob !=1 && intile==1)    

{

surfcolor=color (0.05,0.05,0.05);

}

this simple equation identifies all the points on the surface where black chips have to be placed and then assigns the black color to those points.This is irrespective of whether the chip is in the region of specular highlight or not.

Now the modified coloring equation,takes into account the region of specular highlight and colors the chips as glossy white when inside the highlight region and as normal black  when otherwise.This way when the highlight moves across the surface the chips change color accordingly.

if(monob !=1 && intile==1)

{

surfcolor=mix(color(0.05,0.05,0.05),hilitecolor,specular(nf, i, roughness));

}

Here,the mix function is used to make the transition between the colors when moving across a region of specular highlight on the surface.

The process is repeated for coloring all the chips on the mosaic,similarly the groove color is also altered based on the position of the specular highlight.

if(intile!=1 && monob==1)

{

surfcolor=mix(color(.9,.9,.9),color (.14,.14,.19),specular(nf, i, roughness));

}

A bleaching effect is created when using the default lighting model,due to the unconditional addition of the ambient,diffuse and specular colors at all the points on the surface.This creates very bright spots around the specular highlights on the surface.By ,introducing a compensating factor,this bleaching can be avoided.

Heres the default lighting equation,

ambientcolor = Ka * ambient();

diffusecolor = Kd * diffuse(nf);

 

Heres the modified version,without bleaching,

diffusecolor = Kd * (1-specular(nf, i, roughness)/1.9) * LocIllumOrenNayar(nf,i,3*roughness);

ambientcolor = Ka * (1-specular(nf, i, roughness)/1.9) * ambient();

Fig : Mosaic with specular lighting

 

The modified reflectance model is very similar to the  actual reflectance behavior of a real mosaic floor.

Also finally,the object reflections on the mosaic is simulated using the built in raytrace function,

vector reflectRay = reflect(i, nf);

reflectcolor = Kr*trace(P, reflectRay);

Fig : Shader with interobject reflections.

  © 2004-6 Celambarasan Ramasamy. All rights reserved.