This tutorial demonstrates how to use Texture Operators (TOPs) for instancing in TouchDesigner. Using TOPs for instancing is particularly helpful when working with hundreds of thousands of instances, as it leverages GPU-based texture data for efficient rendering.

Why Use TOPs for Instancing?

While CHOPs are commonly used for instancing, TOPs offer significant advantages when dealing with massive numbers of instances. Point file data can be loaded directly to the GPU through texture operators, making this approach highly efficient for large-scale visualizations.

Getting Started with Point File In TOP

Loading Point Data

Begin by adding a Point File In TOP to your network. This operator allows you to load point file data directly to the GPU.

Understanding the Channel Layout

By default, the Point File In TOP displays a normalized split view of your point file contents:

  • Red Channel - X position data
  • Green Channel - Y position data
  • Blue Channel - Z position data
  • Alpha Channel - Active data (true/false for whether a point exists)

The Active Channel

The Alpha channel’s “active” data is crucial. Point files need to fit inside a square texture, which means some pixels may not contain actual point data. An active value of zero indicates these empty pixels, helping the system know which instances to render.

Setting Up the Basic Workflow

Step 1: Connect to a Null TOP

Connect your Point File In TOP to a Null TOP. You can view the points spatially by:

  1. Turning on the viewer active flag for the Null TOP
  2. Right-clicking inside the viewer
  3. Selecting “Viewer Points”
  4. Pressing H to home the view

Step 2: Create Instance Geometry

Set up your instance geometry using SOPs:

  1. Add an Add SOP and turn on “Add Points”
  2. Connect to a Convert SOP
  3. Set the Convert SOP to convert “To Particles Per Point”
  4. Connect to a Geometry Component

Step 3: Configure Instancing

On the Geometry component’s Instance page:

  1. Turn on the Instancing parameter
  2. Set your Null TOP as the translate information source
  3. Map the channels correctly:
    • Active - Alpha channel
    • Translate X - Red channel
    • Translate Y - Green channel
    • Translate Z - Blue channel

Visualizing Instances with Materials

To better see your instances, add a Line Material:

  1. Open the OP Create dialogue and select Line Material
  2. Drag and drop it onto your Geometry component
  3. On the Line page, turn off “Draw Lines”
  4. On the Point page, turn on “Draw Points”
  5. Set near and far colors to the same value (e.g., bright white)
  6. Adjust the point size multiplier as needed

Press A to make the Geometry component viewer active, then H to home the view.

Working with Different Point Files

Loading Custom Point Files

You can load different point files (like the banana.ply example) through the file browser in the Point File In TOP. After loading, reassign the channels:

  • Red = X position
  • Green = Y position
  • Blue = Z position

Extracting Additional Data with Point File Select TOP

Point files often contain more information than four channels can hold. Use the Point File Select TOP to extract additional data:

  1. Add a Point File Select TOP
  2. Drag and drop your point file onto it
  3. Select which information to pack into each channel (e.g., RGB and Alpha color values)

Normalizing Color Data

If your color data is in 0-255 range, use a Math TOP to normalize:

  1. Connect the Math TOP to your Point File Select TOP
  2. On the Range page, set “From Range” as 0 to 255
  3. Set “To Range” as 0 to 1
  4. Connect to a Null TOP (use Alt+N shortcut)

Applying Color to Instances

On the Geometry component’s Instance 2 page:

  1. Find the Color Operator parameter
  2. Drag and drop your color Null TOP
  3. Map R, G, B, and A channels to the corresponding color parameters

Using Rotation Data

Extracting Normal Vectors

For instances that need to align to surfaces, extract normal data:

  1. Add another Point File Select TOP
  2. Select NX (Normal X), NY (Normal Y), and NZ (Normal Z) for the RGB channels
  3. Connect to a Null TOP

Configuring Rotate To

On the Geometry component’s Instance 2 page:

  1. Set the Rotate To OP parameter to your normal data Null TOP
  2. Map the channels:
    • Rotate To Vector X = R channel
    • Rotate To Vector Y = G channel
    • Rotate To Vector Z = B channel

This allows instances to correctly align to surfaces, such as distributing circles across a sphere.

Using Different Instance Geometry

Instead of points, you can use any geometry for instances:

  1. Create a Circle SOP with a small radius (e.g., 0.06 for X and Y)
  2. Right-click on the Circle SOP output and add a Geometry Component
  3. Enable instancing and connect your point data Null TOP
  4. Map the channels as before

Key Takeaways

  1. TOPs for Scale - Use TOPs when working with hundreds of thousands of instances
  2. Point File In TOP - Loads point data directly to GPU
  3. Active Channel - Alpha channel indicates valid points in square textures
  4. Point File Select TOP - Extracts additional data like colors and normals
  5. Math TOP - Normalizes data ranges (e.g., 0-255 to 0-1)
  6. Rotate To - Uses normal vectors for instance orientation

This tutorial provides a foundation for TOP-based instancing. There are many more ways to drive instances with texture operators, opening up possibilities for complex, large-scale visualizations.

本教程演示如何在TouchDesigner中使用纹理操作符(TOPs)进行实例化。当处理数十万个实例时,使用TOPs进行实例化特别有用,因为它利用基于GPU的纹理数据实现高效渲染。

为什么使用TOPs进行实例化?

虽然CHOPs通常用于实例化,但在处理大量实例时,TOPs具有显著优势。点文件数据可以通过纹理操作符直接加载到GPU,使这种方法对于大规模可视化非常高效。

Point File In TOP入门

加载点数据

首先在网络中添加一个Point File In TOP。这个操作符允许你将点文件数据直接加载到GPU。

理解通道布局

默认情况下,Point File In TOP显示点文件内容的归一化分割视图:

  • 红色通道 - X位置数据
  • 绿色通道 - Y位置数据
  • 蓝色通道 - Z位置数据
  • Alpha通道 - 活动数据(表示点是否存在的真/假值)

Active通道

Alpha通道的”active”数据至关重要。点文件需要适配方形纹理,这意味着某些像素可能不包含实际的点数据。活动值为零表示这些空像素,帮助系统知道要渲染哪些实例。

设置基本工作流程

步骤1:连接到Null TOP

将Point File In TOP连接到Null TOP。你可以通过以下方式在空间中查看点:

  1. 打开Null TOP的查看器活动标志
  2. 在查看器内右键点击
  3. 选择”Viewer Points”
  4. 按H键归位视图

步骤2:创建实例几何体

使用SOPs设置实例几何体:

  1. 添加一个Add SOP并打开”Add Points”
  2. 连接到Convert SOP
  3. 将Convert SOP设置为转换”To Particles Per Point”
  4. 连接到Geometry Component

步骤3:配置实例化

在Geometry组件的Instance页面:

  1. 打开Instancing参数
  2. 将Null TOP设置为平移信息源
  3. 正确映射通道:
    • Active - Alpha通道
    • Translate X - 红色通道
    • Translate Y - 绿色通道
    • Translate Z - 蓝色通道

使用材质可视化实例

为了更好地查看实例,添加一个Line Material

  1. 打开OP Create对话框并选择Line Material
  2. 将其拖放到Geometry组件上
  3. 在Line页面,关闭”Draw Lines”
  4. 在Point页面,打开”Draw Points”
  5. 将近色和远色设置为相同的值(例如,亮白色)
  6. 根据需要调整点大小倍数

按A键使Geometry组件查看器激活,然后按H键归位视图。

使用不同的点文件

加载自定义点文件

你可以通过Point File In TOP中的文件浏览器加载不同的点文件(如banana.ply示例)。加载后,重新分配通道:

  • 红色 = X位置
  • 绿色 = Y位置
  • 蓝色 = Z位置

使用Point File Select TOP提取额外数据

点文件通常包含超过四个通道所能容纳的信息。使用Point File Select TOP提取额外数据:

  1. 添加一个Point File Select TOP
  2. 将点文件拖放到上面
  3. 选择要打包到每个通道的信息(例如,RGB和Alpha颜色值)

归一化颜色数据

如果颜色数据在0-255范围内,使用Math TOP进行归一化:

  1. 将Math TOP连接到Point File Select TOP
  2. 在Range页面,将”From Range”设置为0到255
  3. 将”To Range”设置为0到1
  4. 连接到Null TOP(使用Alt+N快捷键)

将颜色应用到实例

在Geometry组件的Instance 2页面:

  1. 找到Color Operator参数
  2. 拖放你的颜色Null TOP
  3. 将R、G、B和A通道映射到相应的颜色参数

使用旋转数据

提取法向量

对于需要对齐到表面的实例,提取法线数据:

  1. 添加另一个Point File Select TOP
  2. 为RGB通道选择NX(法线X)、NY(法线Y)和NZ(法线Z)
  3. 连接到Null TOP

配置Rotate To

在Geometry组件的Instance 2页面:

  1. Rotate To OP参数设置为法线数据Null TOP
  2. 映射通道:
    • Rotate To Vector X = R通道
    • Rotate To Vector Y = G通道
    • Rotate To Vector Z = B通道

这允许实例正确对齐到表面,例如在球体上分布圆形。

使用不同的实例几何体

除了点之外,你可以使用任何几何体作为实例:

  1. 创建一个半径较小的Circle SOP(例如,X和Y都为0.06)
  2. 右键点击Circle SOP输出并添加Geometry Component
  3. 启用实例化并连接点数据Null TOP
  4. 像之前一样映射通道

关键要点

  1. TOPs用于大规模 - 处理数十万个实例时使用TOPs
  2. Point File In TOP - 将点数据直接加载到GPU
  3. Active通道 - Alpha通道指示方形纹理中的有效点
  4. Point File Select TOP - 提取颜色和法线等额外数据
  5. Math TOP - 归一化数据范围(例如,0-255到0-1)
  6. Rotate To - 使用法向量进行实例方向控制

本教程为基于TOP的实例化提供了基础。还有更多方法可以用纹理操作符驱动实例,为复杂的大规模可视化开辟了可能性。