Get Position in Texture
The Position in Texture nodes provides the "position in texture" of the current Render State. The Render State is affected by any shaders which were called before this function is called, among other things.
The input connection is not used by this node (consistent with all Get nodes).
Position in Texture provides the 3D texture coordinates at the current point. On imported objects such as OBJs or TGOs, these coordinates are often the UV texture coordinates (where X = U, Y = V, Z = 0). On terrains these coordinates are initially set to the position on the flat planet from which the terrain was displaced, but may be updated by Compute Terrain or Tex Coords From XYZ nodes to provide fully 3D texture coordinates. Transform Shader and Warp Shader modify Position in Texture for any networks connected to their Shader inputs, and other shaders may do so.
Even when texture coordinates are not clearly needed, Get Position in Texture has a couple of advantages over Get Position. First, in a typical Terragen scene, Position in Texture is set by Compute Terrain or Tex Coords From XYZ to provide a consistent value between displacement contexts and colour/lighting contexts for any shaders that are computed after those nodes. Second, in order to make use of transforms from Transform Shader or Warp Shader, you need to use Position in Texture.
In contexts where Position in Texture has not been updated (e.g. displacement before Compute Terrain or Tex Coords From XYZ), Get Position may be more useful.
- Name: This setting allows you to apply a descriptive name to the node, which can be helpful when using multiple Get Position in Texture nodes in a project.
- Enable: When checked, the node is active, and when unchecked the node is ignored.
Fun with Get Position in Texture
Let’s explore the Get Position in Texture node and how to modify its output to create interesting shapes which can be used to drive displacement or colour functions.
Many 3D objects, like those you would import into Terragen for populations, have internal UV texture coordinates which define their texture space. In the example below, the cube object’s vertices have been laid out on the UV grid and a texture map has been constructed based on the vertex positions. When the image is mapped to the geometry using the UV coordinates the texture aligns properly to the object.
Terragen’s built-in objects, such as the planet or sphere, use texture coordinates which are accessible via the Get Position in Texture node. The examples below help to visualise the texture coordinates for a spherical object or planet by means of different shaders.
Let’s use a Voronoi 3D cell colour node to apply some pretty colours to the surface of the terrain in the default project. In order to have control over where the Voronoi noise pattern appears in the project, we’ll start by adding a new Surface Layer, which will provide constraints for altitude and slope as well as masking abilities.
- Click on the “Shaders” button on the toolbar.
- Click the “Add Layer” button then select “Surface Layer”.
Procedural noise functions like Perlin 3D scalar and Voronoi 3D require a Get Position in Texture node in order to know where the sampled point exists within the texture coordinates. They also have two additional inputs, one to set the scale of the noise pattern and the other to randomize the pattern.
- Click on an empty space in the Node Network pane to focus the program's attention there.
- Press the tab key or “N” key to open the Quick Node Palette window.
- Start typing the words “Voronoi 3D cell colour” and the closest match in the Node list will be highlighted.
- With “Voronoi 3D cell colour” highlighted, press the enter key to add it to the project.
- Add a “Get position” node to the project in the same manner.
- Drag a connection line from the “Output” of the Get position node to the ”Main input” of the Voronoi 3D cell colour node.
- Add two “Constant scalar” nodes to the project.
- Double-click on the first Constant scalar node to open its dialog window.
- Set “Name” to “Constant scalar SCALE”, or something descriptive.
- Set “Scalar” to “100”.
- Drag a connection line from the “Output” of the Constant scalar to the “Scale value” input of the Voronoi 3D cell colour node.
- Double-click on the second Constant scalar node to open its dialog window.
- Set “Name” to “Constant scalar SEED”.
- Set “Scalar” to any number you desire, such as “112862”.
- Drag a connection line from the “Output” of the Constant scalar node to the “Seed” input of the Conditional scalar.
- Drag a connection line from the “Output” of the Voronoi 3D cell colour node node to the “Colour function” input of the Surface layer.
This voronoi noise pattern created a colourful but fairly uniform pattern across the landscape. To modify the shape of the noise pattern cells, you can manipulate the output of the Get position in texture node before the Voronoi 3D cell colour node receives it. One way to do this is to add a Mulitply vector node in-between the Get position in texture node and the Voronoi 3D cell colour nodes.
- Add a “Multiply vector” node to the project.
- Connect the “Output” of the Get position in texture node to the “Input 2” of the Multiply vector node.
- Connect the “Output” of the Multiply vector node to the “Main input” of the Voronoi 3D cell colour node.
- Add a “Constant vector” node to the project.
- Connect the “Output” of the Constant vector node to the “Main input” of the Multiply vector node.
- Double-click on the Constant vector node to open its dialogue window.
- Modify the “Vector” parameters. For example, enter a value of “4” in the X input, “1” in the Y input, and “0.5” in the Z input.
Furthermore, we can warp the shape of the noise pattern cells to add more details and break-up any patterns, with Power fractal shaders and warp shaders.
- Add a Fractal warp shader to the project.
- Connect the “Output” of the Fractal warp shader to the “Main input” of the Voronoi 3D cell colour node.
- Connect the “Output” of the Multiply vector node to the “Main input” of the Fractal warp shader.
- Double-click on the Fractal warp shader node to open its dialog window.
- Click on the “Shader preview” button to open the shader’s preview window.
- Adjust the shader’s parameters to see the effect on the noise pattern in the Shader preview.
Now you have an idea of how to use the Get position in texture node, and manipulate its output. This data can then be used to drive displacement and colour functions.
Literally, to change the position of something. In graphics terminology to displace a surface is to modify its geometric (3D) structure using reference data of some kind. For example, a grayscale image might be taken as input, with black areas indicating no displacement of the surface, and white indicating maximum displacement. In Terragen 2 displacement is used to create all terrain by taking heightfield or procedural data as input and using it to displace the normally flat sphere of the planet.
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.
In a graphical user interface (GUI) on a computer a toolbar is a row, column, or block of onscreen buttons or icons that, when clicked, activate certain functions of the program.
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.
A shader is a program or set of instructions used in 3D computer graphics to determine the final surface properties of an object or image. This can include arbitrarily complex descriptions of light absorption and diffusion, texture mapping, reflection and refraction, shadowing, surface displacement and post-processing effects. In Terragen 2 shaders are used to construct and modify almost every element of a scene.