Node Input Type Conversion

From Planetside Software Wiki
Jump to: navigation, search

Terragen is pretty flexible about what can be used for input to nodes. Particularly in the case of function nodes, nodes are designed to handle a particular type. For example the "Multiply scalar" node is designed to work with scalars, and the "Multiply colour" node is designed to work with colours. You can however use a node for input which is sending a different type for its output, i.e. you can connect a "Multiply scalar" node to an input of the "Multiply colour" node and you will still get a result.

Terragen does this through a process known as type conversion, also known as type casting. Type conversion can convert a vector into a scalar, or a scalar into a colour and so on. If you input a colour into a node expecting a scalar, the input colour will be converted to a scalar. Here is a list of the type conversion rules Terragen uses :


Vector to colour
When converting a vector to a colour, a piecewise component copy is done :

colour.red becomes vector.x
colour.green becomes vector.y
colour.blue becomes vector.z


Colour to vector
When converting a colour to a vector, a piecewise component copy is done :

vector.x becomes colour.red
vector.y becomes colour.green
vector.z becomes colour.blue


Vector to scalar
When converting a vector to a scalar, the scalar is set to the magnitude of the vector using the following formula:

scalar becomes square root of ( vector.x x vector.x + vector.y x vector.y + vector.z x vector.z )


Scalar to vector
When converting a scalar to a vector, each component of the vector is simply set to the value of the scalar :

vector.x becomes scalar
vector.y becomes scalar
vector.z becomes scalar


Scalar to colour
When converting a scalar to a colour, each component of the colour is simply set to the value of the scalar :

colour.red becomes scalar
colour.green becomes scalar
colour.blue becomes scalar


Colour to scalar
When converting a colour to a scalar, the scalar is set to the luminance value of the colour :

scalar becomes luminance of colour


Back to Network View Guide

A scalar is a single number. 1, 200.45, -45, -0.2 are all examples of scalar values.

A single object or device in the node network which generates or modifies data and may accept input data or create output data or both, depending on its function. Nodes usually have their own settings which control the data they create or how they modify data passing through them. Nodes are connected together in a network to perform work in a network-based user interface. In Terragen 2 nodes are connected together to describe a scene.

A vector is a set of three scalars, normally representing X, Y and Z coordinates. It also commonly represents rotation, where the values are pitch, heading and bank.

This is essentially the brightness of the colour. Terragen converts RGB colours to greyscale by taking the luminance of the colour.