• 🔺 改写成 HLSL 中看 Niagara Grid2D 和 RT

法一:直接操作

Niagara 中的 Grid2D 本质上就是一个 Texture2DArray<float> + 一个 RWTexture2DArray<float>,每个 Attribute 对应特定的切片,可以查看生成的 HLSL 代码:

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 索引即可。

法二:调用节点函数

如果在之前调用过对应的节点,那么就可以直接调用节点所生成的函数。

HLSL
#函数名_#域_#对象名_#属性名(int X, int Y, out Value)
#函数名_#域_#对象名_#属性名(float2 UV, out Value)
点击展开查看更多

函数名:

  • GetPreviousFloatValue
  • SamplePreviousGridFloatValue

HLSL
#函数名_#域_#对象名_UEImpureCall_Attribute#属性名(int X, int Y, Value)`
点击展开查看更多

函数名:

  • SetFloatValue

索引

HLSL
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:

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;
点击展开查看更多

版权声明

作者: Cheyne Xie

链接: https://chaim.eu.org/posts/910a8d6e/

许可证: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.

开始搜索

输入关键词搜索文章内容

↑↓
ESC
⌘K 快捷键