Planetside Software Forums

General => User-contributed Tutorials => Topic started by: David Burnett on March 25, 2007, 01:37:48 PM

Title: A function only Landscape : Part One - A Pyramid
Post by: David Burnett on March 25, 2007, 01:37:48 PM
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

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 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,


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]



Title: Re: A function only Landscape : Part One - A Pyramid
Post by: Oshyan on March 25, 2007, 02:47:39 PM
Glad to see this show up in the tutorial section now. It makes a very good stand-alone write-up. The only thing I think is missing would be a rendered example of the terrain this produces. :)

- Oshyan
Title: Re: A function only Landscape : Part One - A Pyramid
Post by: David Burnett on March 25, 2007, 06:14:11 PM
I've added a couple of images now, showing the end result of this part of the tutorial, and I've done the same for the second part too.

Dave
Title: Re: A function only Landscape : Part One - A Pyramid
Post by: Oshyan on March 25, 2007, 06:25:27 PM
Excellent Dave, thanks. :)
Title: Re: A function only Landscape : Part One - A Pyramid
Post by: rcallicotte on July 03, 2007, 09:44:21 AM
Thanks David.  This is an excellent way to an understanding of the TG2 functions.
Title: Re: A function only Landscape : Part One - A Pyramid
Post by: Ironshirt on October 04, 2007, 05:15:05 AM
I'm sorry, but since english isn't my native language I couldn't figure out which math. formula you used for the pyramid...?

In other words - before you start with things like the pyramid you have a mathmatical formula which you use to convert into TG2...
which one was it in the case of the pyramid? It would be a great help if you could tell me!

thanks ahead!
Michael

Title: Re: A function only Landscape : Part One - A Pyramid
Post by: David Burnett on October 04, 2007, 02:14:28 PM
The maths formula would be

y = r - clamp( maximum( absolute(x), absolute(z) ), 0, r)

Where r is the half the length of one side of the pyramid base.

Depending on how good your english is you may need to know that...

Clamp restricts the result of the maximum function to between 0 and r. Effectively min (max (x, 0), min(x, r))

Absolute gives the value without the sign so absolute(-5) is 5 and absolute(5) is 5

Dave
Title: Re: A function only Landscape : Part One - A Pyramid
Post by: Ironshirt on October 09, 2007, 09:00:20 AM
Thanks Dave!
Got it - this was very helpful!
Title: Re: A function only Landscape : Part One - A Pyramid
Post by: lukedesmith on April 23, 2009, 03:15:13 PM
there is way too much math involved in this program, which should be simple and intuitive to us artist types. why cant i just drop a primitve shape in the scene with one click?
Title: Re: A function only Landscape : Part One - A Pyramid
Post by: Alpha Centurion on April 28, 2010, 06:30:28 PM
I don't think this tutorial is written in a useful way. There should have been waaay more graphic illustrations, since what is described doesn't match what the image of the node network shows. 
Title: Re: A function only Landscape : Part One - A Pyramid
Post by: David Burnett on July 07, 2010, 05:01:05 PM
Quote from: Alpha Centurion on April 28, 2010, 06:30:28 PM
I don't think this tutorial is written in a useful way. There should have been waaay more graphic illustrations, since what is described doesn't match what the image of the node network shows.  

Yes it does, I've just run though the tutorial again and I get exactly what I've described, bar the name of a node or two which I've altered the node that might be confusing (mac pyramid height -> mac pyramid radius) in the the tutorial to match the network node picture.
Title: Re: A function only Landscape : Part One - A Pyramid
Post by: nethskie on August 10, 2010, 09:33:32 PM
Dave,

Thank you for the function tutorial because of this tutorial i was able to create this:

(http://th09.deviantart.net/fs70/150/f/2010/222/6/9/The_Great_Pyramids_of_Kaiser_1_by_nethskie.jpg)

Full View: http://nethskie.deviantart.com/art/The-Great-Pyramids-of-Kaiser-1-174843418 (http://nethskie.deviantart.com/art/The-Great-Pyramids-of-Kaiser-1-174843418)

Thanks and Best Regards,

Ken
Title: Re: A function only Landscape : Part One - A Pyramid
Post by: yangin0 on November 11, 2010, 08:50:07 PM
It took a while for me to get the math, but I enjoyed it very much. Thank you!
Title: Re: A function only Landscape : Part One - A Pyramid
Post by: bellker on July 03, 2013, 02:53:39 PM
Hello!
Can someone look into my pyramid?? I don't know what is wrong... the link is attached!
Thank you very much!!
Title: Re: A function only Landscape : Part One - A Pyramid
Post by: Dune on July 04, 2013, 03:07:01 AM
Here you go. It was there alright. If you make a surface shader at the end of the line before planet, you can test where things are with the color.