Function help

Started by NWsenior07, August 12, 2007, 02:12:00 PM

Previous topic - Next topic

NWsenior07

I understand the under lying concpets behind the functions present in TG2, problem is I'm quite lost when it comes to using them. I can't figure out where to plug functions in, which ones work where, yadda yadda. Do certain functions and nodes apply soley to the terrain shaders and others to surface shaders? Where should functions be plugged into to make them actually work? Any guidance on this would be greatly appreciated.
Allen

old_blaggard

Usually functions are plugged in as displacement shaders or as blend shaders.  You usually will start with "Get position," then convert that vector to scalars using "X to scalar, Y to scalar," etc.  Afterwards, you can then use the functions to modify and use those results, which can eventually be plugged into a shader to lead to some interesting displacements or distributions.
http://www.terragen.org - A great Terragen resource with models, contests, galleries, and forums.

David Burnett

I take it you've read the tutorials in the  User-contributed Tutorials
http://forums.planetside.co.uk/index.php?board=6.0;sort=subject

In the end the functions have to plugged into a shader than accepts functions, the displacement shader is used in
the function only landscape tutorials, but there is also the default shader and the surface layer which accept functions for colour and luminosity as well as displacement.

Functions in the end just generate a stream of numbers so there are no real reasons while they can't be used in any type of the shaders
that accept functions. Having said that of course certain things work better than others. functions that cause sudden changes in values are
not very good for terrain and are also really slow to render. Values that run off to infinity need to reigned in, unsurprisingly.


NWsenior07

I read through a couple of the tutorials and I'm still having a hard time wraping my head around the concept. Are there a specific set of functions that should be used to start every function I create, or is it more of a trial and error kind of thing? Then in order to produce effects are there certain shaders/functions that are better at some effects than others?

David Burnett

You need something to drive the function, as in if y = f(x) you need to supply the x.

The things what are useful are mostly the Get functions

Create Functions/Get/...

which provide you with things like the the current co-ordinates in 3D space, altitude,
current colour, current frame number. All of which could be used to drive the function.

You may want to combine those with the Convert Functions

Create Functions/Convert/...

to extract scalar values from the vectors, that is X, Y or Z from the co-ordinates
or red, green or blue from the colour.



 

Oshyan

It helps a tremendous amount to have some decent math knowledge and/or prior experience writing shaders for graphics. The Function nodes are not intended for everyone to use and are not necessary to achieve a wide variety of effects.

The Function nodes are math-based, extremely flexible and their applications quite broad. It would be impossible to make more than very general statements about where or how they might be connected. This is where baseline mathematical or shader knowledge will help a lot as the concepts and methods used are common to many such systems.

The art of shader writing is somewhat unique unto itself. If you're mathematically inclined then it may be worth experimenting with and delving further into their workings, otherwise I'd advise not worrying about it and sticking instead to experimentation with the more fleshed-out stand-alone nodes or re-using and adapting other people's function creations.

- Oshyan

dandelO

 ???

I'm having a little trouble here...
I've been looking at the function only landscape tutorials and my problem is:
Setting the coordinates of where an actual function displacement will appear on planet1.
If I create a function only terrain and plug it into 'compute terrain' the displacement will obviously appear at the default x=0 y=0 z=0.
What function do I need in the initial 'function terrain' nodes, or, between that and the compute terrain node to set the co-ord's of the actual area of the planet to be affected by the function?
This has been driving me batty for days now, I'm no mathematician but I imagine that there would be a way to do this somehow.
If anyone knows of a way to help it would be greatly appreciated!

Thanks in advance!  :)

rcallicotte

dandelO, I'd say many of us are still learning how the functions work and yet I think what you might want to do is even further than the normal request.  If I understand you correctly, you want to put a specific effect in a particular place.  I personally don't know how to do that.  Usually, I start my functions with a Get Position function which just calculates each position in the TGD world accordingly.
So this is Disney World.  Can we live here?

David Burnett

#8
The functions are applied to all the surface points on a landscape.

If you want to want to apply a certain feature at a difference place to where it is calculated by default,
for example to move the pyramid in the tutorials so is not centred at 0,0,0
then you want to apply the following between 'Get Position" and the 'X to Scalar' and 'Y to Scalar' nodes...
(And I'm taking it for granted the displacement shader does the right thing, regarding the direction of displacement).

TG2 works on a 3D co-ordinate system where 0,0,0 is the 'North Pole' of planet1 due to the planet1 being centred at 0, -r, 0 (well near enough)
where r is planet1's radius.

So to 'move' a point to need to

  • vector add 0, r, 0
  • apply a rotation or two to point the vector in the right direction, see Create Function/Rotate/..
  • vector subtract 0, r, 0

Of course you could avoid the vector add and subtract by altering the planet to be centred at 0,0,0

Working out the rotations is a mater of applying a little bit of Pythagoras. Do however remember you need to work the rotation 'backwards' to get from the place you want the feature to render back to the co-ordinates where TG2 wanted to render the feature.

For example say we want to put the pyramid at the 'South Pole' which is the other side of the planet, so that is 180 degrees on the x axis (or z axis).

Get Position returns the point at the 'South Pole'  ---> 0,-r * 2, 0
we add 0, r, 0  ---> 0, -r, 0
we rotate by 180 degrees on the x axis ---> 0, r, 0
we subtract 0, r, 0  ---> 0, 0, 0

So we are now feeding the 0,0,0 value back into the orginal algorithm and applying the result of that point to the new point at the 'South Pole'.

 


dandelO

Thanks for the detailed explanation David. I did originaly imagine I could have replicated the function displacement, 9 times over, by having 9 seperate pyramid nodes layed out, each with a specific constraint set as to where it would be placed on the surface... Looks like that option is a 'terrain only' job then!

I've had a mess around with the add/subtract and rotate functions as you mentioned here, it isn't quite what I was looking for but it's another new thing learned so, for that, thankyou! :)


Matt

As David says, the basic principle is to modify the input coordinates that are supplied by the "Get position" or "Get position in texture" node before you use those coordinates in any computation. David's rotation method should work across the whole planet, but in many cases you can get away with simply subtracting an offset vector from the initial coordinates. For example, if you want your 'feature' to appear at (x = 100, z = 300), you could feed the Get position into a Subtract vector with a Constant vector of (100, 0, 300).

Matt
Just because milk is white doesn't mean that clouds are made of milk.