UE5.1_Niagara高級(jí)1.1 _Simulation Stage Fill Render Target
Enable Simulation Stages on a GPU emitter by checking "Enable Simulation Stages" in advanced emitter properties
【通過(guò)勾選發(fā)射器屬性里的高級(jí)里的“Enable Simulation Stages”來(lái)給GPU發(fā)射器啟動(dòng)模擬階段(UE5.1更新為:點(diǎn)擊“+Stage”,選擇Generic Simulation Stage來(lái)添加模擬階段)】
Think of a simulation stage as an additional "stack" like Particle Update. The difference is it can iterate, meaning run multiple times on a single frame across all the elements in it.Think of it like a "For Loop" in the stack.
It is also unique because its "Iteration source" can be more than just particles. A Simulation Stage can iterate over every grid cell in a Grid 2d collection to create solvers, iterate over every pixel in a render target to write to it, or iterate over every particle.
【可以把模擬階段看作是另外的像粒子更新這樣的堆疊。區(qū)別是它可以迭代,意味著可以在單一幀中對(duì)所有元素重復(fù)運(yùn)行多次??梢钥醋髟诙询B里循環(huán)】
【它也是獨(dú)特的,因?yàn)樗摹暗础辈恢豢梢允橇W?。一個(gè)模擬階段可迭代在2d網(wǎng)格集合中的每個(gè)網(wǎng)格單元格來(lái)創(chuàng)造結(jié)算器,可迭代在一個(gè)渲染目標(biāo)的每個(gè)像素來(lái)寫(xiě)入,或迭代在每個(gè)粒子】
Up at the emitter level, we initialize a Render Target, and a Texture Sample.
【在發(fā)射器層級(jí),我們初始化一個(gè)渲染目標(biāo),和一個(gè)紋理采樣】
We set some emitter level variables for sprite properties, because our sprite renderer source mode is set to emitter, meaning our simulation contains no particles.
【我們?cè)O(shè)置一些發(fā)射器層級(jí)的變量作為圖片屬性,因?yàn)槲覀儓D片渲染器來(lái)源模式設(shè)為發(fā)射器,意味著我們模擬不包含粒子】
On the simulation stage settings, we choose the render target as our iteration source. this means the stage will iterate over every texel and perform work on? it directly
【在模擬階段設(shè)置中,我們選擇渲染目標(biāo)作為我們的迭代源。這意味著階段會(huì)迭代在每個(gè)紋素并直接作用于它】
In the simulation stage itself, we create a UV by dividing the index of the iteration source (in this case, each texel of our render target) by the size of the target. We use that to sample the texture, and then call a function to fill the render target directly. Note that in this context, Exec Index means the iteration source element, i.e. a render target cell, grid 2d cell, etc.
【在模擬階段本身,我們通過(guò)用渲染目標(biāo)的大小除迭代源(在此示例,我們渲染目標(biāo)的每個(gè)紋素)的索引創(chuàng)建一個(gè)UV(即:迭代源索引÷渲染目標(biāo)大小)。我們使用它來(lái)采樣紋理,然后使用函數(shù)直接填充渲染目標(biāo)。注意這里的語(yǔ)境,Execution Index指的是迭代源元素,如:一個(gè)渲染目標(biāo)單元格,網(wǎng)格2d單元格等】
Lastly, we need to make a texture object parameter in our assigned sprite material and name it. In this case, it is named "Fill RT".
On the sprite renderer, we add an entry to the "material parameter bindings" array and pick that named parameter, and assign the render target. Now the system passes the filled render target directly to the sprite renderer.
【最后,我們需要制作紋理目標(biāo)參數(shù)到我們使用的的圖片材質(zhì)并命名它。在這示例,它叫“Fill RT”。】
【在圖片渲染器,我們添加一個(gè)入口到“material parameter bindings”數(shù)組并選中命名參數(shù),和綁定渲染目標(biāo)?,F(xiàn)在系統(tǒng)直接傳遞填充的渲染目標(biāo)到圖片渲染器中】
Texture Sample【紋理采樣】變量:對(duì)紋理進(jìn)行采樣的數(shù)據(jù)接口
Render Target 2D【渲染目標(biāo)2D】變量:渲染目標(biāo)2D的數(shù)據(jù)接口
Simulation Stage【模擬階段】:數(shù)據(jù)流位置處于粒子更新與渲染之間
Generic Simulation Stage Settings【生成模擬階段設(shè)置】
Enable Binding【啟動(dòng)捆綁】
Num Iterations【迭代數(shù)量】
Num Iterations Binding【迭代數(shù)量捆綁】
Iteration Source【迭代源】:即對(duì)哪類(lèi)數(shù)據(jù)進(jìn)行迭代運(yùn)算,來(lái)源提供如元素?cái)?shù)量和堆疊環(huán)境變量等
Particle【粒子】
Data Interface【數(shù)據(jù)接口】
(僅Particle)Particle Iteration State Enable【粒子迭代狀態(tài)啟動(dòng)】
(僅Data Interface)Data Interface【數(shù)據(jù)接口】
(僅Data Interface)Execute Behavior【執(zhí)行行為】:控制什么時(shí)候模擬階段應(yīng)該執(zhí)行
Simulation Stage Name【模擬階段名字】
Override GPU Dispatch Type【重置GPU發(fā)送類(lèi)型】
Cus_SampleTextureToRenderTarget2D模組
Render Target 2D→Set Render Target Value節(jié)點(diǎn)
IndexX【設(shè)置元素的X索引】
IndexY【設(shè)置元素的Y索引】
Value【設(shè)置數(shù)值】
Texture Sample→Sample Texture 2D節(jié)點(diǎn)
UV【紋理坐標(biāo)】
Execution Index節(jié)點(diǎn):當(dāng)前執(zhí)行的索引號(hào),此處為迭代源的元素的線(xiàn)性索引號(hào)
Render Target 2D→Linear to Index節(jié)點(diǎn)
Linear【線(xiàn)性的】:輸入元素的線(xiàn)性索引號(hào),從而獲得元素在矩陣中的X/Y的索引號(hào)
Render Target 2D→Get Render Target Size節(jié)點(diǎn):獲得矩陣的Width(X)和Height(Y)的長(zhǎng)度
Convert節(jié)點(diǎn):將輸入類(lèi)型轉(zhuǎn)換為想要的輸出類(lèi)型,如:將兩個(gè)數(shù)轉(zhuǎn)換成一個(gè)Vector2D
Add節(jié)點(diǎn):矩陣坐標(biāo)Vector2D的X和Y都加0.5,使采樣點(diǎn)居中偏移
Divide節(jié)點(diǎn):矩陣坐標(biāo)Vector2D除以矩陣的寬高Vector2D,從而獲得元素在矩陣中標(biāo)準(zhǔn)化的位置,作為UV