- 🔺 改写成 HLSL 中看 Niagara Grid2D 和 RT
小心
现在才发现,只要把 Grid2D Collection 对象传进 Custom HLSL 节点,输入 对象名. 获取补全,根据补全写的代码会自动生成对应的 HLSL 代码。醉了,当时以为 Attribute Index 是硬编码的才有了这篇文章,现在这篇文章不用看了。
法一:直接操作
Niagara 中的 Grid2D 本质上就是一个 Texture2DArray<float> + 一个 RWTexture2DArray<float>,每个 Attribute 对应特定的切片,可以查看生成的 HLSL 代码:
void SetVector2DValue_Emitter_Grid2DCollection2_UEImpureCall_AttributeT(int In_IndexX, int In_IndexY, float2 In_Value) {
int In_AttributeIndex = 1;
Emitter_Grid2DCollection2_OutputGrid[int3(In_IndexX, In_IndexY, In_AttributeIndex + 0)] = In_Value.r;
Emitter_Grid2DCollection2_OutputGrid[int3(In_IndexX, In_IndexY, In_AttributeIndex + 1)] = In_Value.g;
}那么只需使用 Get XXX Attribute Index 获取 Attribute 索引即可。
法二:调用节点函数
如果在之前调用过对应的节点,那么就可以直接调用节点所生成的函数。
跨阶段调用与注意事项
读
#函数名_#域_#对象名_#属性名(int X, int Y, out Value)
#函数名_#域_#对象名_#属性名(float2 UV, out Value)函数名:
GetPreviousFloatValueSamplePreviousGridFloatValue
写
#函数名_#域_#对象名_UEImpureCall_Attribute#属性名(int X, int Y, Value)`函数名:
SetFloatValue
索引
ExecutionIndexToGridIndex_#域_#对象名(out int X, out int Y)
ExecutionIndexToUnit_#域_#对象名(out float2 UV)
GetNumCells_#域_#对象名(out int W, out int H);例子
卷积平均模糊
Parameters:
- Grid2D Collection 1
- Grid2D Collection 2
Custom HLSL 节点前调用每个对象的对应节点以生成函数。
Custom HLSL:
// KernelSize = KernelSizeHalf * 2 + 1
#define KernelSizeHalf 3
int u, v;
ExecutionIndexToGridIndex_Emitter_Grid2DCollection2(u, v);
float sum = 0;
for (int x = -KernelSizeHalf; x <= KernelSizeHalf; x++) {
for (int y = -KernelSizeHalf; y <= KernelSizeHalf; y++) {
float value;
GetPreviousFloatValue_Emitter_Grid2DCollection1_AttributeA(u + x, u + y, value);
sum += value;
}
}
float KernelSize = KernelSizeHalf * 2 + 1;
float new_v = sum / KernelSize / KernelSize;
SetFloatValue_Emitter_Grid2DCollection2_UEImpureCall_AttributeA(u, v, new_v);
Out_Placeholder = 0.0;