# Difference between revisions of "Node Input Type Conversion"

(Created page with '==Node Input Type Conversion== Terragen 2 is pretty flexible about what can be used for input to nodes. Particularly in the case of function nodes, nodes are designed to handle ...') |
|||

(2 intermediate revisions by the same user not shown) | |||

Line 1: | Line 1: | ||

− | + | 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 | + | 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'''<br /> When converting a vector to a colour, a piecewise component copy is done : | + | '''Vector to colour'''<br /> |

+ | When converting a vector to a colour, a piecewise component copy is done :<br /> | ||

− | colour.red | + | colour.red ''becomes'' vector.x<br /> |

+ | colour.green ''becomes'' vector.y<br /> | ||

+ | colour.blue ''becomes'' vector.z<br /> | ||

− | |||

− | + | '''Colour to vector'''<br /> | |

+ | When converting a colour to a vector, a piecewise component copy is done :<br /> | ||

− | ''' | + | vector.x ''becomes'' colour.red<br /> |

+ | vector.y ''becomes'' colour.green<br /> | ||

+ | vector.z ''becomes'' colour.blue<br /> | ||

− | |||

− | ''' | + | '''Vector to scalar'''<br /> |

+ | When converting a vector to a scalar, the scalar is set to the magnitude of the vector using the following formula:<br /> | ||

− | + | scalar ''becomes'' <u>square root of</u> ( vector.x x vector.x + vector.y x vector.y + vector.z x vector.z )<br /> | |

− | |||

− | + | '''Scalar to vector'''<br /> | |

+ | When converting a scalar to a vector, each component of the vector is simply set to the value of the scalar :<br /> | ||

− | ''' | + | vector.x ''becomes'' scalar<br /> |

+ | vector.y ''becomes'' scalar<br /> | ||

+ | vector.z ''becomes'' scalar<br /> | ||

− | scalar '''becomes''' luminance of colour | + | |

+ | '''Scalar to colour'''<br /> | ||

+ | When converting a scalar to a colour, each component of the colour is simply set to the value of the scalar :<br /> | ||

+ | |||

+ | colour.red ''becomes'' scalar<br /> | ||

+ | colour.green ''becomes'' scalar<br /> | ||

+ | colour.blue ''becomes'' scalar<br /> | ||

+ | |||

+ | |||

+ | '''Colour to scalar'''<br /> | ||

+ | When converting a colour to a scalar, the scalar is set to the luminance value of the colour :<br /> | ||

+ | |||

+ | scalar ''becomes'' luminance of colour<br /> | ||

+ | |||

+ | |||

+ | [[Terragen 2 Network View Guide|Back to Network View Guide]] |

## Latest revision as of 01:55, 27 December 2013

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

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

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.