I would like to ask why Niagara is compiled successfully, but the running time of a certain simulation stage is N/A?
The data interface of this simulation stage is grid 2d, and I have initialized its num cells to non-zero values. Logically speaking, there should be elements in it that can be traversed.
If needed, it is what is in the module
Draw Depth
.It is module input.
It is module output.
It is custom hlsl in the middle.
const int2 IndexOffsets [ 9 ] =
{
int2(-1,-1),
int2(-1, 0),
int2(-1, 1),
int2(0,-1),
int2(0, 0),
int2(0, 1),
int2(1,-1),
int2(1, 0),
int2(1, 1)
};
OutDepth = 0;
#if GPU_SIMULATION
int3 Index;
NeighborGrid.UnitToIndex(float3(CellPos, 0), Index.x,Index.y,Index.z);
int3 NumCells;
NeighborGrid.GetNumCells(NumCells.x, NumCells.y, NumCells.z);
int MaxNeighborsPerCell;
NeighborGrid.MaxNeighborsPerCell(MaxNeighborsPerCell);
float minDepth = 1 / 0;
int minDepthIdx = -1;
for(int xxx = 0; xxx < 9; ++xxx)
{
for(int i = 0; i < MaxNeighborsPerCell; i++)
{
const int3 IndexToUse = int3(Index.x + IndexOffsets[xxx].x, Index.y + IndexOffsets[xxx].y, 0);
int NeighborLinearIndex;
NeighborGrid.NeighborGridIndexToLinear(IndexToUse.x, IndexToUse.y, IndexToUse.z, i, NeighborLinearIndex);
int CurrNeighborIdx;
NeighborGrid.GetParticleNeighbor(NeighborLinearIndex, CurrNeighborIdx);
bool myBool;
float2 ProjectedParticlePos;
ParticleReader.GetVector2DByIndex<Attribute="ProjectedPos">(CurrNeighborIdx, myBool, ProjectedParticlePos);
float ParticleDepth;
ParticleReader.GetFloatByIndex<Attribute="Depth">(CurrNeighborIdx, myBool, ParticleDepth);
float DistanceFromCellToParticle = length(ProjectedParticlePos - CellPos);
float ProjectedRenderSpriteSize = RenderSpriteSize/ParticleDepth;
if(CurrNeighborIdx != -1
&& DistanceFromCellToParticle < ProjectedRenderSpriteSize
&& ParticleDepth != 0)
{
minDepth = minDepth < ParticleDepth ? minDepth : ParticleDepth;
minDepthIdx = minDepth < ParticleDepth ? minDepthIdx : CurrNeighborIdx;
}
}
}
OutDepth = minDepth;
#endif
Furthermore, if you want to know what does the module do:
For each pixels in screen space, find particles projected in the screen space position of pixel. To do this, create a new Neighbor Grid 3D, which is used for accelerating searching particles. From the view of occupying space, the Neighbor Grid 3D should occupys full space of screen, so one cell of Neighbor Grid 3D may overlaps with many pixels.
Set Iteration Source
as Data Interface
, and drag RenderGrid2D
to Data Interface
, then in the module, if you set namespace of a value in map out as STACKCONTEXT
, the value will be stored into Data Interface
automatically.
Now, if you want for loop
pixels, logically you first traverse Grid 2D, stored your desired value into cells of Grid 2D. After travering finished, you write value from Grid 2D to a render target.