Using the Combo Shader


return to main index

View combo source code



line
GETTING STARTED

This tutorial will demonstrate the use of a shader called combo. The shader has the following parameters,

float  Ks = 0.7,            /* specularity                            */
       Kd = 0.5,            /* diffuse                                */
       Ka = 1,              /* ambient                                */
       roughness = .1,      /* small is very smooth                   */
           
       decalblend = 0,      /* mixture of decal with texture          */
       envblend = 0,        /* contribution of the environment map    */
					
       smovetex = 0,        /* shift the texture in "s"               */
       tmovetex = 0,        /* shift the texture in "t"               */
       smovetra = 0,        /* shift the transparency map in "s"      */
       tmovetra = 0,        /* shift the transparency map in "t"      */
       smovedecal = 0,      /* shift the decal map in "s"             */
       tmovedecal = 0,      /* shift the decal map in "t"             */
       smovedecalmask = 0,  /* shift the decalmask in "s"             */
       tmovedecalmask = 0;  /* shift the decalmask in "t"             */
					
color  specularcolor = 1;   /* color of the reflection                */
string texname = "",        /* name of the texture map                */
       traname = "",        /* name of the transparency map           */
       decalname = "",      /* name of the decal map                  */
       decalmask = "",      /* name of the decal mask                 */
       envname = "",        /* name of the environment/reflection map */
       specname = "",       /* name of the specular map               */
       envspace = "world"   /* coordinate system for the environment  */

The parameters shown in purple enable a variety of texture maps to be used for a number of purposes. Those shown in red enable texture maps to be slid across a surface in the the 's' and 't' directions. Parameters shown in blue are used to adjust the contributions of the decal and environment maps. The following examples should clarify the ways in which combo can be used.



The following images are used in this tutorial


foreground

"foreground.tif"

mask

"mask.tif"

background

"background.tif"

greengrid

"greengrid.tif"



The code shown below is a snippet taken from the RIB file used to render the test frames.


WorldBegin
LightSource "distantlight" 1 "intensity" 1.5 
             "from" [0 0 1] "to" [0 0 0]
AttributeBegin
    Surface "combo" "Ks" 0.7 "Kd" 0.5
    Scale 4 4 1
    Polygon "P" [-0.5 -0.5 0   0.5 -0.5 0  0.5 0.5 0  -0.5 0.5 0]
                "st" [0 0  1 0  1 1  0 1]
    AttributeEnd
WorldEnd


combo as a texture mapper

foreground

    Surface "combo" "Ks" 0.7 "Kd" 0.5
            "texname" ["background.tx"]


combo as an environment mapper

env1

    Surface "combo" "Ks" 0.7 "Kd" 0.5
            "envname" ["greengrid.tx"]
            "envblend" 1

To apply a tiff image as an environment it is necessary to convert the image using the following statement in the RIB file,

MakeLatLongEnvironment "greengrid.tif" "greengrid.tx" "gaussian" 2 2

The envblend parameter controls the visibility of the environment map - a value of zero will make the map invisible.



combo as a decal mapper

decal1

    Surface "combo" "Ks" 0.7 "Kd" 0.5
            "texname" ["background.tx"]
            "decalmask" ["mask.tx"]
            "decalname" ["foreground.tx"]
            "decalblend" 0

In the example shown above the foreground image (decalname) has been applied to the background image (texname) through the stencil (decalmask).

How much of the decal is applied to the background is controlled by the decalblend parameter. A value of one will mix 100% of the background with 0% of the decal. In the animation shown below the value of decalblend changes from 1 to 0.





combo as a decal / texture mover


    Surface "combo" "Ks" 0.7 "Kd" 0.5
            "texname" ["background.tx"]
            "decalmask" ["mask.tx"]
            "decalname" ["foreground.tx"]
            "decalblend" 0
            
            "smovetex" 0
            "tmovetex" 0
            "smovedecal" 0
            "tmovedecal" 0
            "smovedecalmask" 0
            "tmovedecalmask" 0
            

In the animation shown below the values of the "smovedecal" and "smovedecalmask" change from 0 to 1.





In the final animation the values of the "tmovedecal" and "tmovedecalmask" change from 0 to 1 and at the same time the value of "smovetex" also changes from 0 to 1.




© 2002-4 Malcolm Kesson. All rights reserved.