- ... ?
, .
, (16 x 16 x 16 ) .
, , 2d.
seodo CPU code ...
for(x)
for(z)
fill all voxels below ( GenerateY(x,z) )
, , ...
16 x 16 x 16 , 1024 , , 1024 .
[numthreads(16,16,16)] // <== Not sure if this thread count is correct?
, , [numthreads (16,1,16)], 16 x 16 x maxHeight, .
:
compute.Dispatch(0,1,0,0);
... , 16 x 16 .
, .
, , , , , .
, , - , mesh/scene .
, , - AppendBuffers.
!
:
, , 128 * 128 * 128 , 32 * 32 * 32 , ...
var size = 128*128*128;
var stride = sizeof(float);
ComputeBuffer output = new ComputeBuffer (size, stride);
computeShader.SetBuffer (0, "voxels", output);
computeshader.Dispatch(0, 4,4,4);
#pragma kernel compute
RWStructuredBuffer<float> voxels;
[numthreads(32,1,32)]
void compute (uint3 threadId : SV_GroupThreadID, uint3 groupId : SV_GroupID)
{
uint3 threadIndex = groupId * uint3(32, 1, 32) + threadId;
uint3 endIndex = uint(32, 0, 32) + threadIndex;
float height = Noise();
int voxelPos = voxPos.x+ voxPos.y*size+voxPos.z*size*size;
for(int y = threadIndex.y; y < endIndex.y; y++)
{
if(y < height)
{
voxels[voxelPos] = 1;
}
else
{
voxels[voxelPos] = 0;
}
}
( , ) 128 * 128 * 128 voxel , - "".
, , , , "if" , xyz threadIndex ( ).
, , , .
( ) - ...
... - . voxelbuffer.
( )...