Planetside Software Forums

General => File Sharing => Terrains => Topic started by: David Burnett on February 18, 2007, 08:19:57 AM

Title: A function only landscape
Post by: David Burnett on February 18, 2007, 08:19:57 AM
This is the TGD file for the image posted at http://forums.planetside.co.uk/index.php?topic=828.0 (http://forums.planetside.co.uk/index.php?topic=828.0)
It's an attempt to create a reasonable image solely using functions for the terrain (plus the requisite displacement shader)

Eventually, if there is any interest, my intentions are to break this down and post a tutorial to supplement my older tutorial
@ http://forums.planetside.co.uk/index.php?topic=195 (http://forums.planetside.co.uk/index.php?topic=195) 

Dave

Edit: Ooops, this time I've actually attached the file
Title: Re: A function only landscape
Post by: Will on February 18, 2007, 08:20:59 AM
Thanks :)

EDIT: um where is it?

Regards,

Will
Title: Re: A function only landscape
Post by: groverwa on February 19, 2007, 01:37:39 AM
Gday Dave

Thanks for tgd - very interesting - had a bit of a play already - see attachment

Yes, please do make a tutorial of your tgd/ functions, explain what each part does and why and what will happen if constants for example are changed

Mike
Title: Tutorial Part One, A Pyramid
Post by: David Burnett on February 19, 2007, 07:03:45 PM
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 vector 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.
Add a 'Clamp scalar' function and connect the zero constant to min and the max pyramid height 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 height 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 height,0 and the rotation to -90,0,0 and your pyramid should be right below you.


Title: Re: A function only landscape
Post by: groverwa on February 19, 2007, 08:24:32 PM
Gday Dave

Thanks for the tutorial - much appreciated

Mike
Title: Re: A function only landscape
Post by: old_blaggard on February 19, 2007, 08:29:46 PM
Great job!  This is going to be very useful.  Thanks.
Title: Re: A function only landscape
Post by: Tangled-Universe on February 20, 2007, 05:14:31 AM
Thanks for sharing us insight in the function nodes and your workflow, very useful!

Martin
Title: Tutorial Part Two.... Linear Dunes
Post by: David Burnett on February 27, 2007, 05:13:06 PM
Linear dunes.

To add linear dunes to a scene we again need an algorithm.

The idealised cross section of a dune looks like this...

[attachimg=1]

It has a straight line rise and then a concave fall.
The formula for a straight line is y = mx + c where m is the gradient and c is the position
on the y-axis where the line crosses the axis.

Lot of different algorithms could give us the concave part of the equation, but I want a simple one,
plus my maths is not that hot this days, so its back to my 'O'-level Maths.
The first thing that came to mind was a quadratic equation, most school kids probably know these, but as a refresher its the
ax2 + bx + c type of equation that you get to try an resolve into (dx + e)(fx + g)
e.g.   2x2 + 5x + 2 = (2x + 1)(x + 2) . Plotting one gives a line that looks like a U or a V.

The equations I picked where y = 0.2x and y = x2 - 2x + 1 which conveniently resolves to (x-1)(x-1)

If you plot these two equations you get.

[attachimg=2]

If we just use the lowest value of the two plot lines for any value of x we can see something which looks like our cross section
between x = 0 and x = 1. You may notice that I've gone for a quadratic equations of the form
(ax - a)(ax - a) as I know that at x = 1 the y value will be 0. If you increase 'a' from 1.0 to 2.0 you get a steeper concave slope.
So using (2x-2)(2x-2) instead you get this...

[attachimg=3]

I'll add a way of adjusting this easily in the node tree so you can play with the values
later and pick a values that gives the nicest looking dunes.

So the algorithm we end up with is y = min(0.2x, (x-1)(x-1)) which looks like this...

[attachimg=5]

As you can see the sand dune cross section  sits between x = 0 and x = 1, outside of those
values we basically have a big slope, so we'll need to restrict the x values somehow. 

Now we need to use that algorithm in TG2. First we need the x co-ordinate and we've been there before.



To restrict the x value to between 0 and 1 we could use clamp, but there's a more interesting option
the Modulo Scalar node (Get Function/Divide/Modulo Scalar). Modulo return the reminder from a division
so 3.5 modulo 3.0 returns 0.5 . If we use 1.0 then we restrict the value between 0 and 1. It also has the
added bonus of repeating, so 0.5 mod 1 is 0.5, 1.5 mod 1 is 0.5, so we get a linear dune for every unit where as
Clamp Scalar would have given just one dune. 

Add a Modulo Scalar and a Constant Scalar set to 1.0.
Connect the X to Scalar node to the Modulo Scalar left hand side input (Input node) and the Constant Scalar to the right hand side input (Input 2).

The rest is simple maths, first we need to multiple x by 0.2. The next new node in the tutorial is
the Multiply Scalar node (Get Function/Multiply/Multiply Scalar) it multiplies two scalar values. 


(x-1)(x-1) breaks down to two steps,subtract 1 from x, then multiply the result by itself. However
I'm going to use three steps, multiply x by 1, subtract 1, then multiply the result by itself.


The next new node is the Subtract Scalar node (Get Function/Subtract/Subtract Scalar), like the multiply node does exactly
what it sounds like and subtracts two scalars.


By connecting the Constant Scalar Node to the multiply and the Subtract node it's easy to change the steepness of the
concave slope by changing the value of the Constant Scalar. The Constant Scalar is the a in (ax - a).

TG2 provides us with a Square Scalar node (Get Function/Power/Square Scalar) which takes a single input
and squares it, which will does the next step nicely.


Finally we need a min function which, as you may be able to guess if you've read Part 1 of this Tutorial, is the Conditional Scalar Node.
The condition we want is 'if Linear is Less than Quadratic then Linear else Quadratic' so the feed from


Finally...


If you followed all that you should end up with this node tree.

[attachimg=4]

Render the image to find a row and rows of perfectly linear sand dunes that run as far as the eye can see.

To make them less linear see the next part of the tutorial.



Title: Re: Tutorial Part Two.... Linear Dunes
Post by: §ardine on February 27, 2007, 06:18:41 PM
ah... I need more of this...
stretching my mind on well explained (with illustrations at that) TG2 math functions that do something 8)

Quote from: David Burnett on February 27, 2007, 05:13:06 PM
Lot of different algorithms could give us the concave part of the equation, but I want a simple one,
plus my maths is not that hot this days, so its back to my 'O'-level Maths.

You think your math skills aren't as good as they used to be,
I'll be reading this more than a couple of times before I get my mind around it  ;D

Thanks a lot for your time and effort here David! I will be using this.

~§ardine
Title: Re: A function only landscape
Post by: dhavalmistry on March 01, 2007, 09:14:42 PM
I am lost  :'(
Title: Re: A function only landscape
Post by: king_tiger_666 on March 02, 2007, 05:56:31 AM
Quote from: dhavalmistry on March 01, 2007, 09:14:42 PM
I am lost  :'(

You're not the only one...
Title: Re: A function only landscape
Post by: David Burnett on March 02, 2007, 08:09:05 AM
Tell me where you get lost and I'll try and clarify the bit's you don't understand.

Dave
Title: Re: A function only landscape
Post by: old_blaggard on March 02, 2007, 12:19:10 PM
While it's very complicated, it's extremely well explained in my opinion.  I think you should stick these posts up in the "User-contributed tutorials" section.
Title: Re: A function only landscape
Post by: Dark Fire on March 02, 2007, 02:48:56 PM
It's complicated, but I think I understand...
Title: Re: A function only landscape
Post by: RedSquare on March 02, 2007, 05:26:46 PM
QuoteI think you should stick these posts up in the "User-contributed tutorials" section.
I second that, too valuable to be lost in a forum.
Title: Re: A function only landscape
Post by: David Burnett on March 03, 2007, 08:43:56 AM
I will go in the tutorial section eventually, I've put it here for now for better feedback.

Dave
Title: Re: A function only landscape
Post by: cyphyr on March 03, 2007, 12:03:57 PM
This looks extremly prommising, thanks for the file and the explanations.

On an allied subject, I was wondering if it would be possible to use functions to work out the "depth" of a water plane (it may be necessary to use a simple imported plane with a water shader attached, or even construct a custom water shader more fit for pourpose) so one could give it a degrading transparency dependant on the virtical distance to the terrain benieth it. Hopefully this would allow us to have transparant edges to our water effects and the possibility of changing the hue of the water according to the derrived "depth". I'll have an investigate when I get home after the eclipse and if I can understand Davids tutorial I'll post my results.

Richard Fraser
cyphyr
Title: Re: A function only landscape
Post by: dhavalmistry on March 07, 2007, 10:41:46 AM
Quote from: David Burnett on March 02, 2007, 08:09:05 AM
Tell me where you get lost and I'll try and clarify the bit's you don't understand.

Dave

I am sorry Dave I didnt meant to say I was lost in your tutorial but I am lost because I dont know what any of the functions mean and what they do.
Title: Re: A function only landscape
Post by: Sengin on March 08, 2007, 07:58:42 PM
I doubt it, but is there a way to "trick" TG2 into using functions that can have more than one z value for an x value?  (yes, I know it's not called a function then)  Maybe by using a few condintional scalars or something?
Title: Re: A function only landscape
Post by: David Burnett on March 09, 2007, 05:54:28 AM
I'm not at my Mac at the moment however from memory in Get Functions/Convert there's a function called ...erm... something like Build Vertex.

It excepts co-ordinates in the input node then allows you to replace the x, y and/or z co-ordinates with another scalar feed using the three other input. If you replace all three you probably do not need  anything attached the input node.

So for example
Using Get Position feeding into a Z to scalar and the Build Vertex (or whatever it is called) input node, with the Z to Scalar feed into the y input, you would get co-ordinates using x,z,z.

You could use a similar arrangement but with a conditional scalar between the Z to scalar and Build Vertex, with the conditional scalar feeding into the Build Vertex's z input.

You could feed Get Position into a number of Build Vertex's and replace the z co-ordinate with different scalars.


Do any of those fit your needs?

Dave
Title: Tutorial Part Three - A Detour into Perlin's Noise.
Post by: David Burnett on March 10, 2007, 03:53:14 PM
Tutorial Part Three

A Detour into Perlin's Noise.


Ken Perlin's noise function forms the basis of much that is good about Terrain Generators, from
Ken Musgrave's early images to the quite possibly the last thing you rendered in TG2.

At its heart it's very simple, it just interpolates between a grid of random vectors, and
it creates noise that looks like this.

Figure 1.
[attachimg=1]

Not very terrain like is it. To make it more interesting Perlin introduced Turbulence.
Given a function perlin(x, y, z) we then add 0.5 * perlin (x*2.0, y*2.0, z*2.0)
then 0.25 * perlin (x*4.0, y*4.0, z*4.0) and so on....

value =
   perlin(x, y, z)  +
   0.5     * perlin (x*2.0,  y*2.0,  z*2.0) +
        0.25    * perlin (x*4.0,  y*4.0,  z*4.0) +
        0.125   * perlin (x*8.0,  y*8.0,  z*8.0) +
        0.0625 * perlin (x*16.0, y*16.0, z*16.0)


Each line is called an octave, a word you might have seen on the power fractal shader.
The effect of each octave is to shrink the grid of random vectors, adding more detail to
the noise. This is why decreasing the smallest scale on the Power Fractal Shader increases the number of
Noise Octaves and vice versa, to add more detail you need to add more octaves.

Figure 2.
[attachimg=2]


The Perlin Function in T2TP is very simple, there's no turbulence to make things interesting
unless you willing to manually create a node tree to do it. This however does not make it totally unless,
and I'll use it twice for the function only image we're creating.

Let's a see see what we can do with it first.

Start with a new TGD, delete the height field shader and generator.
Add the Displacement Shader and join it to Compute Terrain.

Add the Perlin noise function, Create Function/Noise/Perlin 3D scalar
Connect it to the Displacement Shader function input

The 3D preview will still be flat, we need to feed it co-ordinates.

Add a Get Position function
Connect it the the left hand input (input node) on the Perlin 3D scalar function.

It still looks flat, but you may notice some patterning. The problem is the camera is
too high, we start a 1000 metres up, bring into down to 10 metres, and volia bumps
on the ground. If you move your cursor over the preview you'll notice that the bumps
are around metre apart. This gives a degree of predictabilty and makes it useful for distorting things.
It's also the reason you need turbulence to make interesting terrains.

The Perlin 3D scalar function has two other inputs, the first is scale. This scales the co-ordinates going into the noise.
The second is seed, which changed the random value generation, change it an you get another variation on the same noise.

Add a Get Constant Scalar function. Set the value to 2.
Attach it to the scale input of the  Perlin 3D scalar function

The distance between peaks should now be around 2 metres. Change the constant to 10, the peaks are now 10 metres apart,
and the terrian has a more gentle look to it.

Scale does not have to be a constant, lets have some fun.

Move the Render camera to 0,10,0 with a rotation of -90,0,0 which is looking straight down.
Disconnect the Constant from the scale input.
Add a Sin function (Get Function/Trig/Sin Scalar).
Connect the Sin function to the scale input of the Perlin 3D scalar.

If you select the Sin function you'll see you get a series of rings in the noise preview.

In the 3D preview the peaks are close together where the Sin function returns small values,
and further part where the Sin function returns larger values. A rendered version looks like this...

Figure 3.
[attachimg=3]

Another common use for Perlin's Noise is to distort things. There's a number of ways to do this. We could
simply add the noise to roughen things up, add the noise to co-orinates going into other functions or shaders
or to simply add the noise to other parameters into into functions.

Lets start from scratch.

Add a Get Position Function, an X to Scalar Function, and a Sin scalar function, and join them together
in that order.
Add a Displacement shader and join the Sin function to the function input of the Displacement shader and the output
of ther Displacement to the Compute Terrain as usual.
Change the Camera to position 0,25,0 with a rotation of -90,0,0.
Change the Sun to a angle of 45.

You should have a ploughed field look. Let's add some noise to the X co-ordinate.

Add a Perlin 3D scalar and an Add Scalar function.
Connect the Get Position to the Perlin 3D scalar, The Perlin 3D Scalar and the X to Scalar to the Add Scalar.
Connect the Add Scalar node to the Sin Scalar node.

There should now be indentations now (Fig 4 'a') 

Add a Constant Scalar, set to 20, and connect it to the Scale input of the Perlin 3D scalar.

The smoothnes is back, but you may notice some subtle distortions, the poughing is not as straight as
it used to be. Set the Camera to 0,100,0 to see it a little better. (Fig 4 'b')

Perlin noise tends to give values between -1.0 and +1.0 so lets increase those and see what happens.

Add a Mulitply Scalar. Connect the Perlin 3D scalar and the Constant Scalar to the Multiply scalar.
Use the Multiply Scalar output to replace the Perlin 3D Scalar input to the Add Scalar.

That distortion is not so subtle now is it (Fig 4 'c') :-)


Now lets change things around.

Delete the Multiply Scalar node and the Constant Scalar.
Connect the X to Scalar node back directly to the Sin Scalar node, and feed the Sin Scalar node
and Perlin 3D Scalar node into the Add Node. The Add Node now feeds into the Displacemet Shader.

This looks like the original distored render but is subletly different (Fig 4 'd').

Figure 4.
[attachimg=4]
Title: Re: A function only landscape
Post by: old_blaggard on March 11, 2007, 12:30:56 AM
Thanks for the very descriptive tutorial!  You're really helping to make the functions more understandable to those of us who haven't got math degrees ;).
Title: Re: A function only landscape
Post by: Sengin on March 11, 2007, 12:55:14 AM
Quote from: David Burnett on March 09, 2007, 05:54:28 AM
Do any of those fit your needs?

Hmmm...I'm not sure.  Basically I had an idea that it might be possible to create waves with crests using functions to connect to the water shader of a lake object.  I came up with two intersecting circles that I thought would at least be a proof on concept (see image below, yes, I know those aren't circles, it's just a quick image in ms paint).  But the condition statement would have to be if the calculated value is less than Eq 1 AND greater than Eq 2, then use that value.  But it would also have more than one height for a value of x, and it wouldn't be considered a "function" anymore.  I believe the equations I used were y=sqrt((x-0.5)^2 - 0.55)-0.25 and y=sqrt((x-0.25)^2 - 0.32)-0.25, butI could be mistaken because I don't have the calculator I used to try those equations with me and have since changed the equation in the .tgd.  I do know the equations are similar to the ones above, just some of the constants might be a little off.  I also tried using two intersecting circles that didn't have more than one value for every x, but the terrain rendered wasn't there (it just rendered black, and I made sure the camera was above ground), so I don't think terragen likes the equation for circles (it probably has to do with the fact of the square root of negative numbers and such - I used the min conditional you had used for your sand dunes, but modified for my function).  Do you have any ideas on how this idea could be implemented with functions?  If the circles can be a proof of concept, then I'm sure a more complicated a more realistic looking wave/crest could be thought up (using ellipses/more than 2 equations/etc...).
Title: Re: A function only landscape
Post by: David Burnett on March 12, 2007, 10:00:05 AM
Okay I get what to want now but I'm not sure if I can help you.

Using the displacement shader is more about moving terrain straight up, well along the normal to be accurate.
I would guess that your algorithm requires new geometry, or volumetrics.

It might be interesting to try an acute triangle as a wave and then use the redirection shader to curve it based on
height.

Dave
Title: Re: A function only landscape
Post by: David Burnett on March 13, 2007, 04:25:08 PM
All right so an acute triangle was not that good so I tried exp(sin(x)) instead.
Anyone got a board...

[attachimg=1]



Title: Re: A function only landscape
Post by: Sengin on March 13, 2007, 07:07:49 PM
Hey, cool.

Ok, I came up with another idea for using functions to make wave crests involving ellipses (http://www.analyzemath.com/EllipseEq/EllipseEq.html).  But instead of trying it the same way, I'm trying it a bit differently.  First, I want two equations for ellipses to be computed, but only used if the number before taking the square root is positive (to get rid of any sqare root of negative numbers - that would be bad because I don't think TGD2 can support imaginary numbers :P).  Let's call that result Q1 and Q2.  I then want to get the altitude of that position where the X value computed came from (let's call that value Y because it's the altitude).  If Y is less than or equal to Q1 AND greater than or equal to Q2, I want the computer terrain to use that Y value for it's generation of terrain.  But as you can guess, it doesn't work (all I get is a flat terrain).  I'm guessing my problem is not knowing what shader or something to use the functions for, or an error on using the altitude.  I've tried using a displacement shader into the compute terrain, and I've tried using it into the displacement input for a surface layer.  I don't know anything else to try to acheive my idea, but I have a feeling it can work because it's not relying on functions to generate the terrain, but rather the boundaries.  Can anyone help me here on a correct shader or something?  Oh, nevermind the default shaders, the names are just reference for the equations used and the default equation for an ellipse.
Title: Re: A function only landscape
Post by: old_blaggard on March 13, 2007, 07:16:59 PM
I wonder if a similar thing could be done using some form of calculus.  In class right now we're doing integrals, which (for those who don't know) is using calculus functions to find the area under a curve.  When you subtract two integrals, you find the area between the curves.  I wonder if you could define a repeating curve (maybe a sine function of some sort) and another (maybe a slightly offset sine curve), take the integrals, subtract them, and have your waves.

I don't pretend to be an expert on this, as I haven't even finished the calculus class and am just diving into function nodes, but it seems like a possibility.
Title: Re: A function only landscape
Post by: Sengin on March 13, 2007, 09:20:06 PM
Hmm..I don't think so.  Integrals are used to find only the area between two curves, it doesn't define any shape (the "shape" is defined by the two curves).  If you were to find the integral, you're left with just a number, the area.  You wouldn't be able to do anything with that number.
Title: Re: A function only landscape
Post by: old_blaggard on March 13, 2007, 09:26:35 PM
Well, for the record, you can also use integrals to rotate images and find their volume, but in this case the next step would be to stretch the two-dimensional area laterally to get a straight 3-D figure shaped like a wave.
Title: Re: A function only landscape
Post by: Sengin on March 13, 2007, 10:13:19 PM
Quote from: old_blaggard on March 13, 2007, 09:26:35 PM
Well, for the record, you can also use integrals to rotate images and find their volume

Right, but I meant for the example you provided.
Title: Re: A function only landscape
Post by: rcallicotte on March 15, 2007, 11:07:19 AM
Thanks for help in understanding the functions.  There's no way to have any sense that I even am beginning to understand this, though.  I hope someone will write an extensive explanation of these and maybe write a book on what all can be done.  Someday.  Thanks again.  This has been great.

The waves below were created using some of these functions.  Ooolala!
Title: Re: A function only landscape
Post by: Oshyan on March 15, 2007, 06:29:41 PM
Calico, I think it's a lot more about understanding the mathematical basis for all of it than understanding any particular TG2-specific aspects. The people who seem to have achieved good results with functions also seem to have a good grasp on math and most of the existing function operators will be familiar to anyone versed in that level of math. The connections of the functions to perform mathematical operations may require a little explanation, but beyond that it's really more important to know the math than the system I think. So in other words pick up a math book, or perhaps better yet some sort of "applied shader development" book. Jo Meder posted a good example here, although it's a bit pricey: http://forums.planetside.co.uk/index.php?topic=151.msg1417#msg1417 (read the replies below it as well)

- Oshyan
Title: Re: A function only landscape
Post by: Arandil on March 15, 2007, 11:02:59 PM
Quote from: calico on March 15, 2007, 11:07:19 AM
Thanks for help in understanding the functions.  There's no way to have any sense that I even am beginning to understand this, though.  I hope someone will write an extensive explanation of these and maybe write a book on what all can be done.  Someday.  Thanks again.  This has been great.

The waves below were created using some of these functions.  Ooolala!

The larger wave forms appear too much like a layer of watery foam padding to me, but the detail on the waves and the color is excellent!  Post another with the larger wave forms tweaked a bit!  ;D
Title: Re: A function only landscape
Post by: rcallicotte on March 16, 2007, 09:51:13 AM
Thanks, Oshyan.  I was just discussing this with my brother (a math major) and both of us love the algebra here, but he loves it with math knowledge.   :P  Thanks for the recommendation.  I'm going to Amazon right now to find the book.  Thanks for your attention.  It keeps us going.  Thanks.

Quote from: Oshyan on March 15, 2007, 06:29:41 PM
Calico, I think it's a lot more about understanding the mathematical basis for all of it than understanding any particular TG2-specific aspects. The people who seem to have achieved good results with functions also seem to have a good grasp on math and most of the existing function operators will be familiar to anyone versed in that level of math. The connections of the functions to perform mathematical operations may require a little explanation, but beyond that it's really more important to know the math than the system I think. So in other words pick up a math book, or perhaps better yet some sort of "applied shader development" book. Jo Meder posted a good example here, although it's a bit pricey: http://forums.planetside.co.uk/index.php?topic=151.msg1417#msg1417 (read the replies below it as well)

- Oshyan
Title: Re: A function only landscape
Post by: Dark Fire on March 16, 2007, 01:58:49 PM
In my opinion, 'Decision mathematics' (http://www.edexcel.org.uk/VirtualContent/83442/GCE_Decision_D1_D2_specimen_paper_mkscheme.pdf) is the most useful area of maths to know about when using T2TP - it's all about things like node networks, critical path analysis, algorithms and linear programming. (CPA and linear programming are only relevant when trying to optimise render quality and size).
Title: Re: A function only landscape
Post by: Sengin on March 19, 2007, 07:16:27 PM
Does anyone know exactly how a Build Vector function node works (create -> function -> convert -> Build Vector)?  It takes 4 inputs, an input node, an x value, a y value, and a z value.  First intuition tells you to simply put a value in there that you want.  However, if that were true, you could use a Get Position node feeding into 3 nodes (x to scalar, y to scalar, and z to scalar), and then plug those 3 values into the x, y, and z inputs of the Build Vector node feeding into a displacement shader's function input and that output to the compute terrain node, and get the same terrain you started with (you are saying, given this point (x,y,z), build a vector that has it's 3 values as (x,y,z)).  However, this is not the case, as the result is that the spherical planet is now an upside-down cone (yes, a cone, all sides circular coming to a point at (0,0,0)).  The only solid information I've come up with is that if you have a build vector and have a constant as it's y input (say the constant scalar is 10), every point would be 10 meters higher (so in essence, you move the terrain up).
Title: Re: A function only landscape
Post by: David Burnett on March 21, 2007, 11:59:23 AM
The displacement shader is expecting a scalar feed into the function input. Feeding a vector into something expecting a scalar seems to have a defined behaviour, for example
feeding Get Position into a Sine Function gives you concentric rings of peaks and troughs.
See...
http://forums.planetside.co.uk/index.php?topic=843.msg9911#msg9911 (http://forums.planetside.co.uk/index.php?topic=843.msg9911#msg9911)

The build vector node works as you've described it plus, IIRC, if you populate the 'input node' with a vector feed, scalar feeds into x, y or replace the x, y or z of the input node.
Title: Tutorial Part 4 - Putting it all together.
Post by: David Burnett on March 21, 2007, 04:07:03 PM
To create my function only landscape I'm going to use the pyramid, the linear sand dunes and Perlin's noise.

To to start off create a linear sand dune node network and add a pyramid node network, or load the tutorial4_start tgd file.

[attachurl=1]

Now we will put some kinks in those straight lines, using Perlin's noise.


To add the pyramid into the scene we need to use our old friend the Condition Scalar.
Were the pyramid overlaps the sand dunes we want to pick the highest value, so the
condition we want is "Greater than".


You may have to look around for the pyramid or you could just set the camera to position 395, 15, -800 and rotation -0.5,-35, 0

It's a bit flat so lets add some big dunes, using Perlin's noise again.


This time we do not want the Highest value to use used as we want linear dunes on the other dunes
so to do this we add the new Perlin noise on the linear dunes.


Now we need to tie the the dunes into the Conditional Scalar before the Displacement shader, however I'm
going to do it in a Surprisingly different way.


I've left linear dune node network feeding into the Input Node. This means that where the linear dunes
were visible before the new dunes will be used. All we need to do now is change the Base Color Shader
to something that looks Sandy and hopefully you have something that looks like this..

[attachimg=2]

Here's the finished tgd in case you got lost

[attachurl=3]

You might want to connect the dunes to the Input Node to see the effect, and for extra marks work how to make the plains
it creates use the linear dunes.

Title: Re: A function only landscape
Post by: Sengin on March 22, 2007, 03:03:51 AM
Quote from: David Burnett on March 21, 2007, 11:59:23 AM
The displacement shader is expecting a scalar feed into the function input.  Feeding a vector into something expecting a scalar seems to have a defined behaviour

Oh, ok.  That would explain the cone then.  But how can I use the Build Vector node into anything so that I can create a terrain using those vectors?  Is there a shader, or do I just plug the output into something?  I've tried just connecting the output to the compute terrain, but the ground stayed flat.  Any ideas?
Title: Re: A function only landscape
Post by: David Burnett on March 22, 2007, 08:39:33 AM
Quote from: Sengin on March 22, 2007, 03:03:51 AM
Oh, ok.  That would explain the cone then.  But how can I use the Build Vector node into anything so that I can create a terrain using those vectors?

Maybe the Redirection shader, but you propably would not use the build vector in the first place as you'd have to feed the X, Y and Z scalars into displacement shaders, then into the redirection shader.
I think you would also need to substract your vector from the original position to make it an offset.

Something to try when I gt home.

Dave
Title: Re: A function only landscape
Post by: David Burnett on March 25, 2007, 02:35:13 PM
I've now copied the tutorial parts to the User-contributed Tutorials
Title: Re: A function only landscape
Post by: Arandil on March 25, 2007, 04:36:06 PM
Thanks a lot David!  This is great stuff.
Title: Re: A function only landscape
Post by: old_blaggard on March 25, 2007, 05:26:35 PM
You've spent a lot of time clarifying these.  Thanks for your efforts!
Title: Re: A function only landscape
Post by: nethskie on August 10, 2010, 09:32:19 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
Post by: Henry Blewer on August 10, 2010, 09:54:27 PM
That's a neat image. Nice work.
Title: Re: A function only landscape
Post by: nethskie on August 14, 2010, 10:37:42 AM
thanks!