Minimize node networks

Started by mogn, June 17, 2009, 07:51:07 AM

Previous topic - Next topic

mogn

One of the best tutorials is David Burnets:

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

Looking only at the blue function nodes lying above the displacement shader, can the complexity of these
nodes be optimised.

A  measurement of the complexity can be:

Each node has the complexity of 1.
Add 1 to the node complexity for each internal setting (e.g the conditional node has an internal setting of the
actual comparison done).
Add 1 to the node complexity for each connected outside input.

E.g. a conditional node with all 4 input tabs connected has a complexity of 1+1+4=6.

What is the minimum complexity of a node network creating D.B's pyramid?

This complexity measurement is not directly connected with the rendering time, but is essential to
understanding how a given network works.

edit: according to my rules, I think Davids network has a complexicty of 24

mogn

A more complex pyramid can be build with a complicity less than 24:

mogn

So nobody dares optimize D.B.'s network:

Here are some hints:
Get rid of the conditional node (replace it with functions)
Use "Get position in geometry" instead of "Get position" (You are only interested in the x,z part of the vector)
The documentation has an incomplete decription of the "Dot multiply node".
A better description is:
 [x, y, z] dot [a, b, c] = x*a + y*b + z*c

My best implementation uses 7 nodes with a complexity of 12.

So lets hear your bids.

mogn

Another variation and some of the node network revealed:

Hetzen

Just wanted to chime in and say that I'm trying to follow what you are doing with some interest, but not had a chance to try out what you are suggesting yet.

mogn

An N sided polygen, can be made in thefollowing:

Multiply the vector [x, 0, z] by a suitable function which is ONE in the directions 0, 2PI/N 4PI/N up until 2PI,
and a value greater than one in the middle directions, and clamp to a given radius.

This function can be calculated as:

v = atan2(x,z)  (v is the angel from the origin to x,z)
q = mod(v, 2PI/N)
w= cos(q - PI/N)/cos(PI/N) (w is the above function)

The atan2(x,z) function is not implemented in TG2, but if you searh for atan2, you can
see some implementations in TG2.

In case of the pyramid, this can be reduced to:

The vector [x, 0, z] can be rewritten as V = [R*cos(v), 0, R*sin(v)]  (R is the distance from origin to the point x,z)
Use symmetri by take the abs vector.
The functions above can then be written as:

v = Arccos(x/R)
q = mod(v, PI/2) = v  (since we work in first qudrant, limited by the abs function)
w = cos(q - PI/4)/cos(PI/4) = cos(v-PI/4)/cos(PI/4) = [cos(v)cos(PI/4) + sin(v)sin(PI/4)]/cos(PI/4) = cos(v) + sin(v)
multiply this the Length of V you get: tranformed distance = R*cos(v) + R*sin(v) = x + y = 1*x + 1*y (this is where the dot function come into play)
and clamp this to the wanted radius, and you have an inverted pyramid.







mogn

Ok so the full explanation. Look at the picture in reply #3:

1. Getposition in geometry 01.
    This node creates the vector [x, o, z], where x and z are all points in the groundplane.

2. Abs vector 01.
    This nodes maps all points in the 4. quadrants to quadrant 1 (positive x and z).
    i.e all transformations made on the output vector will be reflected to quadrant 2, 3, 4.

3. Constant scalar 01, The name is changed to  "Constant (0.01) for documentation purposes.
    The value is 1/max_radius i.e a pyramid with radius 100m.

4. A (Dot product 01)
    The noderef defines this node as:

   The Dot product node takes the Input and Input 2 vectors and outputs the dot product of the two vectors, which is a scalar value. The dot product is the cosine of the angle between the two input vectors.


   This is wrong! The output of the node is the angle multiplied by the product of the length of the 2 vectors.
   A more useful explanation is:
   Dot([x, y, z], [a, b, c]) = a*x + b*y + c*z

   In this case the output od this node is x/100 + z/100
   Remember if you divide by 100, one unit of the output is reflected back to the original as 100m.

   The result is an output unit of 1 along angle 0 and 90, is reflected back in the terrain to a length of 100 m,
   but the output unit of 1 along the 45 deg is reflected back to 100/sqrt(2) m.

5. B (Square scalar)
    Disregard this scalar (this is just a demonstration of anothe transformation, creating the curved sides of the pyramid)

6: C (Clamp 01 scalar 01)

   This restricts the output of the Dot node to a maximum of one in all directions. I.e along the x and z axis
   the reflected length is restricted between 0 and 100m.
   Along the 45 deg axis the reflected length is restricted to 100/sqrt(2) m.
   The max output is 1 unit. 0

7. D (Complement scalar 01)
    Output = 1 minus input.
    This inverts the pyramid.

8. E (Divide scalar 01)
    The right input is connected to the constant scalar with the value 0.01.
    This converts the output of scalar 7, to a displacment of 100 m.

Finally connect node E to the right node of a displacement node.
 



   

jo

#7
Hi mogn,

Quote from: mogn on June 26, 2009, 03:16:53 AM
4. A (Dot product 01)
   The noderef defines this node as:

  The Dot product node takes the Input and Input 2 vectors and outputs the dot product of the two vectors, which is a scalar value. The dot product is the cosine of the angle between the two input vectors.


  This is wrong! The output of the node is the angle multiplied by the product of the length of the 2 vectors.

You're right, that's my fault. To get the cosine of the angle you'd need to divide the dot product by the result of multiplying the lengths of the two vectors.

Edit: I'm only partly wrong. If the two vectors are unit vectors then the dot product gives the cosine of the angle between them.

I have to say your more useful explanation is certainly the definition but not a useful explanation. It doesn't really enlighten anyone to how it might be useful, which is what I tried and failed to do with the cosine explanation, sadly :-). When I was looking for a useful explanation I missed the distinction that the two vectors needed to be unit vectors to give the cosine of the angle between them.

Regards,

Jo