appendixA.html, appendixF.html, index.html, section01.html, section02.html, section03.html, section04.html, section05.html, section06.html, section07.html, section08.html, section09.html, section10.html, section11.html, section12.html, section13.html, section14.html, section15.html, section16.html


12 - Shader Execution Environment

Surface Shaders | Light Source Shaders | Volume Shaders | Displacement Shaders | Transformation Shaders | Imager Shaders


There are some major restrictions in the use of the predefined variables. This requires the avoidance of certain idioms which are not currently supported. Any shader using these idioms will have to be recoded according to the rules below.

There are further restrictions on the use of variables in illuminance, illuminate and solar statements but these are dealt with in the next section ( Illuminance and Illuminate Statements).

Surface Shaders

The value of the output variable Ci, is not available inside shaders. Ci must only be used in one of the following ways:

    Ci = expr;

    Ci += expr;
    

For example:

    /* WRONG */
    surface broken_shader()
    {
      	Declare and calculate Nf, Kd

      	Ci = Kd*diffuse(Nf);
	Ci *= Os * Cs;                 /* NOT SUPPORTED */
    }
    

won't work correctly as the multiplication by Ci is not allowed. But this may be rewritten:

    /* RIGHT */
    surface fixed_shader()
    {
      	Declare and calculate Nf, Kd

	Ci = Os * Cs * Kd*diffuse(Nf); /* OK */
    }
    

In addition the functions diffuse(), specular(), phong() and trace() may only be used in the following ways:

    Ci = factor * lightrayfun(..);

    Ci += factor * lightrayfun(..);
    

where lightrayfun is one of diffuse, specular, phong or trace

For example:

    /* WRONG */
    surface broken_shader()
    {
      	Declare and calculate P, D, Kr, Kd, Nf, Cr

	if(Kr != 0)
	    Cr = trace(P,D);        /* NOT SUPPORTED */
	else
	    Cr = 0;
      	Ci = Kd * diffuse(Nf);
      	Ci += Kr * Cr;
    }
    

won't work. This may be achieved as follows:

    /* RIGHT */
    surface fixed_shader()
    {
      	Declare and calculate P, D, Kr, Kd, Nf, Cr

      	Ci = Kd * diffuse(Nf);
	if(Kr != 0)
	    Ci += Kr * trace(P,D); /* OK */
    }
    

Another example:

    /* WRONG */
    surface broken_shader()
    {
      	Declare and calculate Nf
      	Declare d, Kd

	d = diffuse(Nf);            /* NOT SUPPORTED */

        Calculate Kd

      	Ci += Kd * d;
    }
    

won't work. This may be achieved as follows:

    /* RIGHT */
    surface fixed_shader()
    {
      	Declare and calculate Nf
      	Declare Kd

        Calculate Kd

	Ci += Kd * diffuse(Nf);     /* OK */
    }
    

The variable Ol is not supported

Light Source Shaders

Although area lights are supported, the geometric variables: u, v, s, t, N, Ng, du, dv, are not supported. Varying parameters will also not work.

The variable Ol is not supported

Volume Shaders

The values of Ci and Oi are not available as inputs to volume shaders. Instead the emission and transmission must be specified. This may be done in the following way:

    volume example()
    {
      	color emission;
      	color transmission;

      	Calculate emission and transmission

      	Ci = transmission * Ci + emission;
      	Oi = transmission * Oi + (1 - transmission);
    }
    

The renderer will also accept the following way of specifying the emission and transmission:

    volume example2()
    {
      	color x;
      	color y;

      	Calculate x and y
      	/* emission == x * y */
      	/* transmission == 1 - y */

      	Ci = mix(Ci, x, y);
      	Oi = mix(Oi, color (1,1,1), y);
    }
    

The direction of I is from the eye (towards light sources). P is end point of the ray to be shaded. The ray segment to be shaded goes from (P-I) to P (as it travels away from the eye).

Displacement Shaders

Displacement shaders are now supported.

Transformation Shaders

Transformation Shaders are only supported for use as camera shaders. See RiProjection .

Imager Shaders

Not supported.

Last modified: Tue Jun 27 12:25:10 BST 2000