Difference between revisions of "Get Position in Texture"

From Terragen Documentation from Planetside Software
Jump to: navigation, search
(Get Position in Texture)
(Updated descriptions and added example images.)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:IMPORT]]
+
<div style="float:right; border-style:solid; padding:20px"><categorytree mode=pages hideroot=off>Get</categorytree></div>
='''Get Position in Texture'''=
 
  
[[Image:drex_module_40_image_0.png|485pxpx|Get Position in Texture]]
+
[[File:GetPositionInTexture_00_GUI.png|none|470px|Get Position in Texture]]
  
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. Get 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.
 
  
Get Position in Texture has a couple of advantages over [[Get Position]]. First, in a typical Terragen 2 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 for [[Transform Shader]] and [[Warp Shader]] to have any effect on networks connected to their Shader inputs, those networks must use Position in Texture.
+
__TOC__
 +
 
 +
 
 +
== Overview ==
 +
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|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.
 
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.
  
The Input connection is not used by this node.
+
 
__NOTOC__
+
'''Settings:'''
<!-- imported from file: module_40.html-->
+
 
 +
*'''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.
 +
 
 +
[[File:VisTexCoord 31 OnUVObj.jpg|none|800px|UV mapped 3D 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.
 +
 
 +
[[File:GetPositionInTexture_10_TextureSpace.jpg|none|800px|Examples of shaders and textures in the texture coordinate space.]]
 +
 
 +
 
 +
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'''”. 
 +
<ul>
 +
{|
 +
|-
 +
|[[File:GetPositionInTexture_11_AddSurfLay.jpg|none|800px|Add a Surface layer to the project.]]
 +
|-
 +
|[[File:GetPositionInTexture_01_RenderStep0.jpg|none|800px|A render of the base scene without any Voronoi 3D cell colour.]]
 +
|}
 +
</ul>
 +
 
 +
 +
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.
 +
<ul>
 +
{|
 +
|-
 +
| [[File:GetPositionInTexture_02_NodesStep1.jpg|none|800px|Node Network view step 01.]]
 +
|-
 +
| [[File:GetPositionInTexture_03_RenderStep1.jpg|none|800px|Render step 01.]]
 +
|}
 +
</ul>
 +
 
 +
 
 +
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.
 +
<ul>
 +
{|
 +
|-
 +
| [[File:GetPositionInTexture_04_NodesStep2.jpg|none|800px|Node Network view Step 2.]]
 +
|-
 +
| [[File:GetPositionInTexture_05_RenderStep2.jpg|none|800px|Render Step 2.]]
 +
|}
 +
</ul>
 +
 
 +
 +
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.
 +
<ul>
 +
{|
 +
|-
 +
| [[File:GetPositionInTexture_06_NodesStep3.jpg|none|800px|Node Network view Step 3.]]
 +
|-
 +
| [[File:GetPositionInTexture_07_RenderStep3.jpg|none|800px|Render Step 3.]]
 +
|}
 +
</ul>
 +
 
 +
 +
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.
 +
<ul>
 +
{|
 +
|-
 +
| [[File:GetPositionInTexture_08_Render4.jpg|none|800px|Render of displaced surface using above settings.]]
 +
|-
 +
| [[File:GetPositionInTexture_09_Render5.jpg|none|800px|By changing the XYZ values in the Constant vector node assigned to the Input 2 setting of the Multiply node, you can affect the shape and flow terrain features.]]
 +
|}
 +
</ul>
 +
 
 +
 
 +
<br /n>
 +
 
 +
[[Category:Get]]

Latest revision as of 02:24, 29 March 2022

Get Position in Texture



Overview[edit]

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.


Settings:

  • 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[edit]

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.

UV mapped 3D 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.

Examples of shaders and textures in the texture coordinate space.


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”.
    Add a Surface layer to the project.
    A render of the base scene without any Voronoi 3D cell colour.


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.
    Node Network view step 01.
    Render step 01.


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.
    Node Network view Step 2.
    Render Step 2.


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.
    Node Network view Step 3.
    Render Step 3.


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.

    Render of displaced surface using above settings.
    By changing the XYZ values in the Constant vector node assigned to the Input 2 setting of the Multiply node, you can affect the shape and flow terrain features.



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.