Author Topic: A function only Landscape : Part One - A Pyramid  (Read 47262 times)

Offline David Burnett

  • Member
  • *
  • Posts: 86
A function only Landscape : Part One - A Pyramid
« on: March 25, 2007, 05: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.



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



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.



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





« Last Edit: July 07, 2010, 08:58:31 PM by David Burnett »

Offline Oshyan

  • Planetside Staff
  • *
  • Posts: 11544
  • Holy snagging ducks!
Re: A function only Landscape : Part One - A Pyramid
« Reply #1 on: March 25, 2007, 06: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

Offline David Burnett

  • Member
  • *
  • Posts: 86
Re: A function only Landscape : Part One - A Pyramid
« Reply #2 on: March 25, 2007, 10: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

Offline Oshyan

  • Planetside Staff
  • *
  • Posts: 11544
  • Holy snagging ducks!
Re: A function only Landscape : Part One - A Pyramid
« Reply #3 on: March 25, 2007, 10:25:27 PM »
Excellent Dave, thanks. :)

Offline rcallicotte

  • Member
  • *
  • Posts: 9542
Re: A function only Landscape : Part One - A Pyramid
« Reply #4 on: July 03, 2007, 01:44:21 PM »
Thanks David.  This is an excellent way to an understanding of the TG2 functions.
So this is Disney World.  Can we live here?

Offline Ironshirt

  • Member
  • *
  • Posts: 55
Re: A function only Landscape : Part One - A Pyramid
« Reply #5 on: October 04, 2007, 09: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


Offline David Burnett

  • Member
  • *
  • Posts: 86
Re: A function only Landscape : Part One - A Pyramid
« Reply #6 on: October 04, 2007, 06: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
« Last Edit: October 04, 2007, 06:50:29 PM by David Burnett »

Offline Ironshirt

  • Member
  • *
  • Posts: 55
Re: A function only Landscape : Part One - A Pyramid
« Reply #7 on: October 09, 2007, 01:00:20 PM »
Thanks Dave!
Got it - this was very helpful!

Offline lukedesmith

  • Member
  • *
  • Posts: 1
Re: A function only Landscape : Part One - A Pyramid
« Reply #8 on: April 23, 2009, 07: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?

Offline Alpha Centurion

  • Member
  • *
  • Posts: 21
Re: A function only Landscape : Part One - A Pyramid
« Reply #9 on: April 28, 2010, 10: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. 

Offline David Burnett

  • Member
  • *
  • Posts: 86
Re: A function only Landscape : Part One - A Pyramid
« Reply #10 on: July 07, 2010, 09:01:05 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.
« Last Edit: July 07, 2010, 09:04:22 PM by David Burnett »

Offline nethskie

  • Member
  • *
  • Posts: 105
  • finally now!
    • nethskie.deviantart.com
Re: A function only Landscape : Part One - A Pyramid
« Reply #11 on: August 11, 2010, 01:33:32 AM »
Dave,

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



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

Thanks and Best Regards,

Ken
« Last Edit: August 14, 2010, 02:34:02 PM by nethskie »

Offline yangin0

  • Member
  • *
  • Posts: 6
Re: A function only Landscape : Part One - A Pyramid
« Reply #12 on: November 12, 2010, 12:50:07 AM »
It took a while for me to get the math, but I enjoyed it very much. Thank you!

Offline bellker

  • Member
  • *
  • Posts: 1
Re: A function only Landscape : Part One - A Pyramid
« Reply #13 on: July 03, 2013, 06: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!!

Offline Dune

  • Member
  • *
  • Posts: 12366
  • Corkscrew Bird
    • www.ulco-art.nl
Re: A function only Landscape : Part One - A Pyramid
« Reply #14 on: July 04, 2013, 07: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.
In case you still haven't seen enough of my work: www.ulco-art.nl

 

anything