Loop 示例
This material graph sample demonstrates how to use loops when creating materials.此材质图表示例演示了如何使用循环在创建材质时。
Albedo RGB data for the Mesh Opaque PBR material are generated in the loop: the initial texture (Texture node) is applied 32 times (Maximum Iterations) with a uniform UV shift along the points on a Vogel Disk controlled by the blur Slider parameter node (adjustable via the Parameters panel in UnigineEditor).Mesh Opaque PBR 材质的反照率RGB 数据在循环中生成:初始纹理(Texture 节点)应用 32 次 (Maximum Iterations),沿 Vogel Disk 上的点均匀 UV 偏移,由 blur Slider 参数节点控制(可通过 Parameters 调整UnigineEditor 中的面板)。
The Loop Begin node has the only variable Texture Sample float3 vector. The Maximum Iterations corresponds to the desired number of samples and is set to 32.Loop Begin 节点具有唯一的变量 Texture Sample float3 向量。 Maximum Iterations 对应于所需的样本数并设置为 32。
The logic of each iteration lays between the Loop Begin and Loop End nodes. Each time the following steps are performed:每次迭代的逻辑位于 Loop Begin 和 Loop End 节点之间。每次执行以下步骤:
- The Index of the current iteration and the number of all iterations are passed to the Vogel Disk node providing a uniform UV shift.当前迭代的 Index 和所有迭代的次数被传递给 Vogel Disk 节点,提供统一的 UV 偏移。
- The UV shift is multiplied by the blur value (divided by 10), i.e. the intensity of blur is changed.UV shift 乘以 blur 值(除以 10),即改变模糊的强度。
- The resulting UV shift is added to the texture coordinates (Vertex UV 0 node).产生的 UV 偏移被添加到纹理坐标(Vertex UV 0 节点)。
- The RGB value sampled from the texture is added to the previous Texture Sample value and passed to the Loop End node as the result of this iteration.将从纹理中采样的 RGB 值与之前的 Texture Sample 值相加,并作为本次迭代的结果传递给 Loop End 节点。
Thus the Texture Sample value is iteratively increasing up to the last iteration.因此 Texture Sample 值迭代地增加直到最后一次迭代。
The result of the Add node is also connected to the Divide node which performs color intensity reduction (divides the resulting value by the number of loop iterations - increments of color values).Add 节点的结果也连接到 Divide 节点,该节点执行颜色强度降低(将结果值除以循环迭代次数 - 颜色值的增量)。