Planetside Software Forums

General => Terragen Discussion => Topic started by: al91 on December 01, 2009, 11:30:24 AM

Title: problems understanding the functions
Post by: al91 on December 01, 2009, 11:30:24 AM
um i have problems understanding the functions shaders and what exactly they do..can anybody explain them to me?
Title: Re: problems understanding the functions
Post by: FrankB on December 01, 2009, 02:50:13 PM
they are primarily math functions that apply an operation to the color or position of the procedural geometry or anything really that you feed into it.

An example for a function could be to apply a sine to the color of a surface layer. To do that, you would

- start with a "get position in texture" node
- feed that into "x from scalar" (for example, or y or z)
- feed that into sin
- feed that into the color function input of your surface layer.

This network of function nodes gives you color[-1;1] = sin(x)

For any function, you need to feed them coordinates at the top of the function chain. That's essentially how functions work. In a nutshell. A tiny nutshell.

Frank
Title: Re: problems understanding the functions
Post by: domdib on December 02, 2009, 09:38:47 AM
Dear Frank,

Please consider expanding the tiny nutshell to something more approaching coconut size  ;) Perhaps (as I've hinted elsewhere) there's an NWDA tutorial or product in there somewhere?

Regards,

Dominic
Title: Re: problems understanding the functions
Post by: PorcupineFloyd on December 02, 2009, 09:47:08 AM
Yes, a basic approach to functions is so much needed.
Title: Re: problems understanding the functions
Post by: Zairyn Arsyn on December 02, 2009, 11:05:06 AM
Quote from: PorcupineFloyd on December 02, 2009, 09:47:08 AM
Yes, a basic approach to functions is so much needed.
yes, i heavily agree.
Title: Re: problems understanding the functions
Post by: FrankB on December 02, 2009, 06:05:47 PM
Quote from: domdib on December 02, 2009, 09:38:47 AM
Dear Frank,

Please consider expanding the tiny nutshell to something more approaching coconut size  ;) Perhaps (as I've hinted elsewhere) there's an NWDA tutorial or product in there somewhere?

Regards,

Dominic

Ok, ok... I'll try to put something together after christmas. No time before that unfortunately :(
Title: Re: problems understanding the functions
Post by: domdib on December 03, 2009, 05:43:18 AM
Great news! Something to look forward to AFTER Christmas  :)
Title: Re: problems understanding the functions
Post by: PG on December 03, 2009, 06:26:19 AM
I think the biggest problem people have, I certainly do, is that they can see how you do it but can't understand why you'd want to. I can see what that function does but I wouldn't have the first clue how it works or what I could do with it. Maybe that's due to the awful syllabus that English schools are afflicted with, but if I wanted to create a swirling cloud mass or something like that I wouldn't have the first clue where to start. So I think a Terragen-centric maths lesson would be required first for a lot of people.
Title: Re: problems understanding the functions
Post by: FrankB on December 03, 2009, 09:14:49 AM
that's true, PG, and it gives me a headache when thinking about a tutorial that is to be broadly understood.
I don't feel inclined to teach maths as such, but then I also know that nobody will actually understand the use of functions, or use them purposefully without maths.

Secondly, I'm not a maths expert. I have once tried to create a cyclone function, but failed, because I don't know what the right math formula for it would be. Sometimes it's also difficult for me to translate pure math functions into node elements that are available in TG2. In maths, you often have to transform an equation, which is an art on its own, and requires a lot of knowledge in maths.

To take a very simple example, let's say you find in a book, that the formula you're looking to have is tan(x), and assume the TG2 doesn't have a TAN function node. If you don't know that you could transform TAN into sin(x)/cos(x) instead, you would be lost.

However, what i could do is explain the functions that I do understand, and how to a. build them in TG2, and b. apply them to a scene in TG2 in practice. That's as far as I can go with a tutorial. If that's still helpful, I'm happy to do it.

Cheers,
Frank

Title: Re: problems understanding the functions
Post by: PG on December 03, 2009, 09:42:34 AM
Yeah that seems the most sensible approach. I think that knowledge and teaching of mathematics varies too much between people and indeed between nations so even if we had a TG2-centric maths lesson it could still skip over areas that many don't understand.
Title: Re: problems understanding the functions
Post by: domdib on December 03, 2009, 10:42:12 AM
Perhaps some of the more mathematically inclined function experts might be able to supplement your work Frank? Maybe in that case it could go on the wiki, with links to some of the threads that have used functions in the past? Since I'm the one requesting it, I could do this.
Title: Re: problems understanding the functions
Post by: Oshyan on December 03, 2009, 11:17:04 PM
The wiki would be a great place for collaboration on this, to be sure. But I think everyone should also keep strongly in mind that the vast majority of scenes - even those of highest quality - are accomplished without the use of functions, or at least without the creation of new function networks (i.e. someone may use an existing function network clip, but is unlikely to create some new technique). Function nodes are very powerful, to be sure, but they are not by any means a necessity to using TG, or even to knowing it well and accomplishing very complex and realistic scenes. They are perhaps most useful for accomplishing the unusual, the otherworldly, etc. though of course they also have potential value in realistic settings. But no one should have the impression that they're missing out and their TG2 scenes aren't good *because* of their lack of knowledge of function nodes.

Additionally, for anyone who does have a real interest in this, there are books written that will give you as good an introduction as anyone here could give you, and quite frankly a more comprehensive understanding that will be applicable not just to TG2, but the many other CG industry applications that build shaders in similar ways. This book has been suggested quite a few times, and it remains one of the best references available:
http://www.amazon.com/Texturing-Modeling-Procedural-Approach-Kaufmann/dp/1558608486/ref=sr_1_1?ie=UTF8&s=books&qid=1244894170&sr=1-1

The bottom line is if you're really interested in using the power of function nodes, you'll need a strong understanding of math, and to spend a good amount of time learning to understand how math can build 3D graphics. It will require dedication. If you're not already inclined toward math, you may not want to stick with it long enough to really get much innovation and benefit from function nodes. But again that doesn't mean your scenes will suffer. :)

- Oshyan
Title: Re: problems understanding the functions
Post by: Henry Blewer on December 03, 2009, 11:50:15 PM
FrankB asked me to write about what I know. So I am going to be doing some experiments with them. When I think I have enough knowledge, I'll write up a tutorial about that group of functions.
Oshyan will probably need to make a bunch of corrections. ::) But, at least then the thing will be correct. 8)
It has been 15 years since I have done any real math, except for fractal programs like ChaosPro. But Chaospro makes it easy.
Title: Re: problems understanding the functions
Post by: Henry Blewer on December 04, 2009, 12:52:43 AM
The book is kind of pricey, but the excerpts I read are well written.
Title: Re: problems understanding the functions
Post by: Oshyan on December 04, 2009, 12:58:17 AM
Yeah, it's a bit steep. Maybe eBay?
http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=270358284404&rvr_id=&crlp=1_263602_263622&UA=WXO%3F&GUID=4211dbc21240a0aad3d40754ff6b8ba4&itemid=270358284404&ff4=263602_263622

- Oshyan
Title: Re: problems understanding the functions
Post by: Henry Blewer on December 04, 2009, 01:30:13 AM
Nice find! Can I just buy it, or do I need an EBay account? I really do not want an EBay account.
Title: Re: problems understanding the functions
Post by: Oshyan on December 04, 2009, 01:47:02 AM
Sadly I think you do need an eBay account.

- Oshyan
Title: Re: problems understanding the functions
Post by: FrankB on December 04, 2009, 02:46:47 AM
Hi Oshyan,

all your point are valid. However, there's an additional species of users beyond either the ones who are great at math and the ones who are not great. They're like me, I can do just some math, and just like to experiment with the functions - for fun. For me it started really simple with adding a sine form displacement to a steep canyon wall. I remember that very clearly. That's when I understood how functions in TG2 have to be constructed and applied. I then found the sine displacements too regular and thought about how I can deform the curve more. With that, I learned another bit. The next learning was how to create and use voronoi noise, which is actually very easy. Then I learned that voronoi can be useful in some situations, when they're strechted. And so it went on and on. I once made a ploughed field through functions. Trouble is, that I already chose my POV, and the clouds in the sky were ideal, but the field rows pointed into another direction. That was the first time I tried rotating a vector. I did not recall exactly what i.e. a cross product was, so I looked it up and it gave me an aha moment. These previous learnings led to the "cracks" clip that I shared here, that I still find in many renders that people show in the image sharing area and elsewhere.

All the while I had fun, and my little learnings contributed to the scenes I was working on.
It's true that nobody has to learn functions, though, to be great at TG2, or rather to be great at making realistic renders.

Still learning it is fun and useful.

Cheers
Frank
Title: Re: problems understanding the functions
Post by: PorcupineFloyd on December 04, 2009, 04:00:00 AM
You don't have to use functions to make some decent renders but on the other hand, how will you make voronoi displacement or sinusoidal wave without using functions?
Title: Re: problems understanding the functions
Post by: Henry Blewer on December 04, 2009, 05:55:10 AM
 Here hear. Anyway, what I have learned is that every function I tried needs a get function. Usually a Get location of ____. You can use the Get Camera Location for random seeds and scale. (Not so much for scale, tends to get caried away with itself) Then there are the scalar functions and clamp functions.
Scalar functions seem to enlarge or decrease the scale input. Clamp functions seem to work like a constraint. This is probably all wrong. But I am making guesses again from what I observed using them.
Title: Re: problems understanding the functions
Post by: Oshyan on December 05, 2009, 12:02:13 AM
Certainly there is basic information that would be helpful for anyone willing to experiment. My point though is that no matter how much someone tries to teach "how to do stuff with function nodes", success will always depend on a lot of experimentation. I've seen a lot of people who seem to be looking for simple instructions that will allow them to "unlock the secrets of function nodes", and maybe that's possible with some solid foundational information, but again it's important to remember that a lot of testing (and failure, and going down the wrong path) will need to happen. By their nature function nodes require experimentation, just as you have done Frank. As long as people are inspired to do that after getting the foundation, they have a good chance of success.

- Oshyan
Title: Re: problems understanding the functions
Post by: Henry Blewer on December 05, 2009, 08:35:31 AM
I am hoping to provide enough information on function nodes to make things a lot easier. One of the problems I have using them, is they do not follow the labels I learned in math. I graduated in 1982. But my real math teacher was my Grandmother. She began teaching math in 1930. Trig was an easy subject, but I have not used math much since 1995. So I need to relearn.

What I want to do is provide explanations of the functions. Then give good solid examples of their use. Sometimes things make more sense when someone can see how a thing is done. It will be a while, but I will get there. ( I made some excellent dunes the other night. But I think it was more by accident than knowledge.)
Title: Re: problems understanding the functions
Post by: Hetzen on December 05, 2009, 08:36:22 PM
I'm not sure you've got Scaler or Clamp functions absolutely right there chap.

Scaler is another word for "single number". So functions with the scaler name use numbers. Colour uses shades of grey (which from true black to true white equates 0 to 1, BUT, these colours in TG can in fact go into negative black and plus white. ie a value of 1.1 or 3 or 25 or 100,00 still looks white, anything below 0 will still look black). Clamp functions in their simplest form cut off anything above white or below black, or 1 & 0 in numerical terms. There is a clamp function that allows you to set the numerical cutoff points if you want a wider range.

The 0 to 1 concept is quite usefull to get your head around, because all the trig functions like Sine, Cosine, Tangent etc always output a value between 0 and 1, regardless of their input. The 0/1 concept is also usefull for creating logic arguments.

So if you wanted to increase the 'height' (amplitude) of a Sine wave, (as it's basic maximum value is 1, which in TG terms is one metre), you would have to multiply the output of the sin node.

If you want to increase the 'spacing' (frequency) of those peaks, you would divide the input to the sin function.

I'm warbling now, but another little gem to use is the modulo node. What this does, is break up an input value into divisional sequences. So if I wanted a Get Position to give me values between 0 & 360, I would set up the input2 of a modulo node to be 360, which would result in 361=1, 721=1, 381=1 etc. This is usefull if you want to have control of the phase into a trig function, where this number has to be converted from degrees into Radians. eg, if I want something to happen at halfway through a Sine cycle, I could use a conditional scaler node to check for values >= 180. Which is one of the methods I'm trying to use in generating shore waves at the moment.

I think one of the best ways of finding out what you can do with these functions, is grasp what is happening in a simple set up, then go through the wiki and have a look at all the other function descriptions (some are better than others, wink/nudge). It's a good way of understanding possible solutions to a problem you've had or imagine.

If I get some time, I could have a crack at doing a step through with pics.
Title: Re: problems understanding the functions
Post by: Henry Blewer on December 05, 2009, 08:49:24 PM
That is very helpful, Hetzen Thank you!
Title: Re: problems understanding the functions
Post by: Dune on December 06, 2009, 03:00:37 AM
I totally agree with njeneb, very helpful indeed to have this kind of explanation. I'm terrible at maths (hated it during my biology study), but TG has rekindled my interest (thanks, staff). And I understand the power of it in TG. Some examples (or indeed explanations) of interesting combinations would help a lot of us, I guess. I am especially interested in the shore waves you describe, and perhaps have another go at it with your description. Thanks.

---Dune
Title: Re: problems understanding the functions
Post by: Seth on December 06, 2009, 04:43:17 AM
damn, I only wish I could understand all this mathematical discussion in here :)
maybe i'll have to do some more testing on those function nodes... I still don't understand how they work !
Title: Re: problems understanding the functions
Post by: Cyber-Angel on December 06, 2009, 09:15:33 AM
What ever gets developed for this could it please be explained in a manner that visual learners can understand and for those not skilled in abstraction, if it can that's grate? ;D   

Regards to you.

Cyber-Angel
Title: Re: problems understanding the functions
Post by: Henry Blewer on December 06, 2009, 10:55:45 AM
That is my aim here. I also am in the fog with functions. So, I intend to experiment. When I think I have something that works consistently, and I can remember what I did and why; then I will write and post what I learned.
It's nice to look at a clip file or a node tree and say gee that's nice. My mind says, "Hey, what are you looking at?" "I don't know," is usually the answer I get. So I will have the node trees, but each part of it will have an explanation of what it does, why I used it, what is the whole doing, etc...
I may have some answers at the end of the month.
Title: Re: problems understanding the functions
Post by: bobbystahr on December 07, 2009, 06:42:00 PM
What I'd like is a cross reference from the math terms to layman's English so I could sort out wtf I'm going to get with a given function. From not having had the benefits of any higher math teaching I have a very difficult time trying to figure this out and a dictionary doesn't always help.. ...
Title: Re: problems understanding the functions
Post by: Henry Blewer on December 08, 2009, 12:55:22 AM
If you have any clips or tgd's with functions, please post them here.

http://forums.planetside.co.uk/index.php?topic=8199.0

Or PM me. I will keep your secrets. But I do need help to get this tutorial off the ground. RIght now I am still trudging through mud up to my hips.
Title: Re: problems understanding the functions
Post by: Dune on December 08, 2009, 03:00:57 AM
I'm teaming up with Hetzen to figure out how to get decent waves/surf/breakers. I've put a lot of time into this (mostly trial and error), and I believe he's good at maths. We'll see what this leads to and if we're willing to share our secrets...  ;D By the way, I'll post my latest breaker scene, which just rolled out later today.

---Dune
Title: Re: problems understanding the functions
Post by: Henry Blewer on December 08, 2009, 10:10:49 AM
Hetzen has offered some help here. Any help will be great. As I have said, when I get to understand them, or some of them, I will post what I know. Hopefully it will be so everyone can understand it.