UE5.1_Niagara高级1.2_ Advect Grid 2D Collection
1.2 Advect Grid 2D Collection【平流输送网格2D集合】
We first make ourselves a Texture Sample, a Render Target, and a Grid2d Collection. The Grid2D collection is an array of 2d buffers which can hold float attributes. Right now we don't worry about how many attributes the grid collection has, because we will add them automatically with a custom namespace below.
(eventually we want 4 floats, which add up to an RGBA texture output)
【我们首先设置了纹理采样,渲染目标,和网格2D集合这三个变量。网格2D集合是一个用于存放浮点属性的2D缓冲区数组。现在我们不用担心网格集合里有多少属性,因为我们将用一个自定义命名空间来自动添加它们】
【(最终我们想要4个浮点数,用于RGBA纹理输出)】
The performance of these grids is entirely constrained by their resolution, and the precision of the underlying data. Almost all grids can get away with being Half Float precision, and in this case since we are working with 0-1 texture channel data, we can choose Normalized Float for even greater savings. You almost never need full float precision on a grid.
【这些网格性能完全受限于它们的分辨率,和下层数据的精度。几乎所有网格都只需要半精度浮点数,和在此示例因为我们是使用0到1的纹理通道数据,所以我们为了更好地节省性能消耗可以选择标准化的浮点数。我们几乎从不需要在网格上使用全精度浮点】
First we fill our grid collection with a texture. The iteration source on this Simulation Stage is our grid collection, i.e. we want to iterate over every grid cell and take some action. If we want this to only happen once on emitter spawn, we can check "Emitter Reset Only". Otherwise, we use a oscillating sine wave to fill the grid with the texture when the emitter loops. This way the advection evolves with the emitter, and when the emitter loops, it re-fills the grid and starts anew.
【首先我们用纹理填充网格集合。这里的模拟阶段的迭代源为网格集合。我们想要迭代在每个网格单元格并执行某些行动。如果我们只想在发射器生成时发生一次,我们可以勾选“Emitter Reset Only”。否则,当发射器循环时我们使用一个振荡的正弦波来用纹理填充网格。这时平流输送与发射器共同演变,并当发射器循环时,它重新填充网格并重新开始】
Notice the use of a new namespace called StackContext. This namespace is adaptive to the stack it is used in. In Particle stages, it converts itself to the Particles.X namespace. When used in a Simulation Stage, it takes on the properties of whatever data interface is set as the iteration source. In this case, a Grid Collection. Writing to StackContext.RGBA automatically creates a named Vector4 attribute on the grid collection which can be read from or written to in subsequent stages, similar to a Particle Attribute in particle scripts.
【留意使用的叫“StackContext”的新命名空间。这个命名空间适应于使用它的堆叠。在粒子阶段,它自身转换为“Particles.X”命名空间。当在模拟阶段使用时,它承担迭代源设置的数据接口的属性。在此示例,为网格集合。写入为StackContext.RGBA时自动在网格集合里创建名为Vector4属性,这属性可在随后阶段读取或写入,与粒子脚本中的粒子属性相似】
Next, we advect our texture by stepping backwards along a curl noise vector, sampling the grid, and then writing that sampled position to the current grid cell. We use the curl noise data interface for simplicity, but this could easily be driven by a separate velocity grid (in the case of a fluid simulation), a sampled texture, or other means.
【随后,我们通过沿卷曲噪声向量向后移动来平流输出纹理,采样网格,然后在当前网格单元格写入采样位置。为了简单我们使用卷曲噪声数据接口,但这可容易地通过单独的速度网格来驱动(在流体模拟的情况),一个采样的纹理,或其他方式】
Lastly, we have a stage with the iteration source set to our render target. We sample the grid cells via a UV, and write those directly to the render target which we send to the material using an entry in the "Material Parameter Bindings" array.
【最后,我们有一个阶段的迭代源设置为我们的渲染目标。我们通过UV采样网格单元格,并直接写入到渲染目标,并将渲染目标通过“Material Parameter Bindings”的入口发送到材质里】
Grid2D Collection变量:网格2D集合接口
Cus_SampleTextureToGrid2DCollection模组
Cus_AdvectGrid2DCollection模组
Cus_SampleToRenderTarget2D模组