This tutorial was originally released in the file sharing forum at [url]http://forums.planetside.co.uk/index.php?topic=843.0[url]

To make a pyramid using a function, we need an algorithm that represents a pyramid.

So lets look at a rough plan of an upside down pyramid.

[attachimg=2]

The 'height' of the upside down pyramid at any point is highest distance between the x or y co-ordinate

and the y or x axis repectively, i.e. z = max(x, y).

We then limit the size of the pyramid by stopping the measurements at a

maximum value of x and y, oh and we need to turn it the right way around.

Right let fire up TGTP and don't forget to save often.

So lets see how we make a pyramid. First we need to extract the 'x' and 'y' values.

In TG2 the co-ordinate system has X and Z as the co-ordinates on the plane and Y is up - down.

so what we really need is the X and Z co-ordinates.

To get the current co-ordinates we use the Get Position Function (Create Function/Get/Get Position).

To extract the individual ordinates there are three functions in Create Function/Convert

- X to scalar

- Y to scalar

- Z to scalar

These take the in a vertex, and output the individual ordinates as scalar values.

We will use 'X to scalar' and 'Z to scalar' feeding Get Position into both.

We want the distance between the ordinate and the adjacent axis, which effectively mean we want to

throw away the ordinates sign. This is called the absolute value, and the function that gets the absolute value

for a scalar is Create Function/Clamp/Abs scalar. There also a Create Function/Clamp/Abs vector that we could use

on the output from Get Position, but I'm going to change things up there later. So add two Create Function/Clamp/Abs Scalar nodes and attach one to 'X to scalar' and the other to 'Z to scalar', call them Absolute X and Absolute Z

So now I know the distances, I need to pick the maximum distance. There is no function called max though, what this is is the conditional scalar (Create Function/Conditional scalar). This function asks if...then...else.... If has 4 inputs and a setting.

- The first input (Input node) is the left hand side of the condition.

- The setting is the condition (is greater than, is less than etc.).

- The second input (Comparison value) is the right hand side of the condition.

- The third input (If result) is the value output if the condition is true.

- The final input (Else result) is the value output is the the condition is false.

The condition we want is 'if x is greater than z then x else z' so the feed from Absolute X goes in Input Node and If result, Absolute Z goes in Comparison value and Else result. The Condition is set to greater than.

Our upside down pyramid currently goes on forever, so we need to clamp it.

There are a lot of clamping functions, you can find them in Create Function/Clamp

We've already used Abs scalar. Now we are going to use a clamping functions,

- Clamp 0 means that any value less than 0 is forced to zero

- Clamp 0 1 means that any value less than 0 is forced to zero, values greater than 1 are forced to 1

- Clamp clamps between the two input values

We need to clamp between 0 and our max pyramid height. So we need two constants

(Create Function/Constant/Constant scalar) one set to Zero and the other to our max pyramid height, which I've called max pyramid radius.

Add a 'Clamp scalar' function and connect the zero constant to min and the max pyramid radius to max.

Connect the Conditional Scalar to the Clamp scalar input.

Finally we need to turn our upside pyramid the right way around, this is easy. Our pyramid goes from 0 to x, we need it to go from x to 0., and we do this by subtracting the height so far from the max height.

Add a subtract function (Create Function/Subtract/Subtract scalar) attach the max pyramid radius node we connected to the clamp node to the left hand input node, and then connect the clamp node to the right hand input node (Input 2).

We now have a pyramid, but we need to use it to change the landscape. To do this add a Displacement shader, connect it to the compute terrain node in the Terrain Group. Finally attach the Subtraction Function to the Displacement Shader Function Input Node.

You should have something like this....

[attachimg=1]

Now, depending on how big your pyramid is, the camera is probably in the middle of it, so to 'find' it set the camera to 0,2xmax pyramid radius,0 and the rotation to -90,0,0 and your pyramid should be right below you. This top down view looks like this.

[attachimg=3]

Moving the camera to position 250, 235, 800 rotation -15, 200, 0 give's you a nice view of the pyramid.

[attachimg=4]