/*
 * staircase.sl -- displacement shader for stairs.
 *
 * Description:
 * 	Makes displacements for an angled staircase.
 * 
 * Parameters:
 *	stepheight               	Height of a step (in st space)
 *	angle				Surface angle with horizontal
 *	noisefactor			How much noise in the final displacement
 *
 * AUTHOR: written by Adrian Ilie
 */

#include "noises.h"

displacement
staircase ( float stepheight = 0.1, angle = 45, noisefactor = 0.01; )
{
    float tt;
    float disp;
	float sina, cosa, tana, sina2;

	sina = sin(angle);
	sina2 = sina * sina;
	cosa = cos(angle);
	tana = sina/cosa;

	tt = t/stepheight;
	tt -= floor(tt);

	if (tt < sina2) {
		/* We're in the lower half of the step */
		disp = tt/tana;
    }
    else {
		/* We're in the upper half of the step */
		disp = (1-tt)*tana;
    }

	disp *= stepheight;

	disp += snoise(noisefactor);

    P += disp * normalize(N);
    N = calculatenormal (P);
}
