compute shaders....

Hi I want to update the screen on unity with the particles moving constantly, but not as fast as I thought … What should I do?

here is the code.

[shader code]
#pragma kernel PositionCS
struct Data{
float x;
float y;
float z;

float vx;
float vy;
float vz;
};

#define SIMULATION_BLOCK_SIZE 1024

StructuredBuffer _datacompare;
RWStructedBuffer _dataparsing;

int _MaxDataMun; // about 760000;

float _PositionX;
float _PositionY;
float _PositionZ;

groupshared Data group[SIMULATION_BLOCK_SIZE];

[numthreads(SIMULATION_BLOCK_SIZE,1,1)]

void PositionCS
(
uint3 DTid : SV_DispatchThreadID,
uint3 Gid : SV_GroupID,
uint3 GTid : SV_GroupThreadID,
uint GI : SV_GroupIndex
)

{
Data c = _datacompare[P_ID];
Data d = _dataparsing[P_ID];
[loop]
for (uint N_block_ID = 0; N_block_ID < (uint)_MaxDataMun; N_block_ID += SIMUALTION_BLOCK_SIZE)
{
group[GI] = _datacompare[N_block_ID+GI];
GroupMemoryBarrierWithGroupSync();
for (int N_tile_ID = 0; N_tile_ID < SIMULATION_BLOCK_SIZE; N_tile_ID++)
{
if (group[N_tile_ID].x == _PositionX && group[N_tile_ID].y == _PositionY && group[N_tile_ID].z == _PositionZ)
{
c.x = group[N_tile_ID].x;
c.y = group[N_tile_ID].y;
c.z = group[N_tile_ID].z;

c.vx = group[N_tile_ID].vx;
c.vy = group[N_tile_ID].vy;
c.vz = group[N_tile_ID].vz;
}
}
GroupMemoryBarrierWithGroupSync();
}
_dataparsing[P_ID] = c;
}
because ‘if statement’ seems to be slowing down, how can we speed it up?

For starters, could you use code block to format your code snippet? You find it in insert code button when you edit a message.

And to inform those who might take a look at this, does this code actually function, and you only have issues with some of it’s features/results? I’m asking as there’s some typos there (SIMUALTION_BLOCK_SIZE and SIMULATION_BLOCK_SIZE, for example.)