-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlagOctree.hlsl
91 lines (64 loc) · 1.27 KB
/
FlagOctree.hlsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
cbuffer cbInfo
{
uint curLevel;
uint totalLevel;
uint sumVoxels;
uint curNode;
};
cbuffer cbGroupInfo
{
uint3 groupSize;
};
struct Node
{
uint brickPtr;
uint childPtr;
};
struct Voxel
{
float3 pos;
uint normal;
uint color;
};
/*
Fragments List
Read
*/
StructuredBuffer<Voxel> FragmentsList;
/*
Nodes Pool
Read-Write
*/
RWStructuredBuffer<Node> nodesPool;
uint extractPos(uint childPtr)
{
return (childPtr & 0x3FFFFFFF);
}
[numthreads(16, 16, 1)]
void main( uint3 DTid : SV_DispatchThreadID )
{
uint voxelIndex = DTid.x + DTid.y*groupSize.x * 16;
if (voxelIndex >= sumVoxels)
return;
Voxel voxel = FragmentsList[voxelIndex];
uint curIndex = 0;
for (uint level = 0; level < curLevel; ++level)
{
int tt = pow(2.f, level);
uint xx = uint(frac(voxel.pos.x*tt)*2.f);
uint yy = uint(frac(voxel.pos.y*tt)*2.f);
uint zz = uint(frac(voxel.pos.z*tt)*2.f);
curIndex = extractPos(nodesPool[curIndex].childPtr) + xx + yy * 2 + zz * 4;
}
if (curLevel == totalLevel - 1)
{
/*
赋予叶节点标记,叶节点不需要划分,但是需要赋予brick
*/
InterlockedOr(nodesPool[curIndex].childPtr, 0x40000000);
// log[curIndex] = 1;
// log0[curIndex] = nodesPool[curIndex].childPtr;
return;
}
InterlockedOr(nodesPool[curIndex].childPtr , 0x80000000);
}