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


13 - Language Constructs

Statements and Expressions | Standard Control Flow Constructs | Volume Shaders | Illuminance and Illuminate Statements


Statements and Expressions

Variables can be declared anywhere a statement can be made. They have similar scoping to the C++ language, ie. variables declared in a statement block are available to expressions from the declaration to the end of the block.

Standard Control Flow Constructs

Untyped Shading Language functions are assumed not to have a return value, instead of being assumed to return a float.

Illuminance and Illuminate Statements

Values computed inside these statements are not available outside the statement. Hence, when using an illuminate or solar, Cl must be set inside the statement. When using an illuminance, Ci must be added to inside the statement as follows:

    illuminance(position [, axis, angle])
    {
      	Calculate factor
      	Ci += factor * Cl;
    }
    

For example:

    /* WRONG */
    surface broken_shader()
    {
        First part of shader

	x = 0;
	Nn = normalize(N);
	illuminance(P, N, PI/2) {
	    Ln = normalize(L);
	    /* WRONG: value of x only affected within statement */
	    x += Cl * Ln.Nn;
	}

        More shader

	Ci += Cs * x;       /* WRONG: value of x is still zero */
    }
    

should be rewritten:

    /* RIGHT */
    surface fixed_shader()
    {
        First part of shader

	Nn = normalize(N);
	illuminance(P, N, PI/2) {
	    Ln = normalize(L);
	    Ci += Cs * Ln.Nn * Cl;
	}

        More shader
    }
    

Also see the previous section (Surface Shaders) about restrictions on the use of Ci.

These statements may not be nested or used inside function calls.

The language extension extern is not supported and should be omitted.

Last modified: Fri Apr 11 16:33:06 BST 2003