Game Development Reference
In-Depth Information
float4(PI/(2*sqrt(PI)),-((2*PI)/3.0f)*sqrt(3.0f/(4*PI)),0.0f,0.0f),
float4(PI/(2*sqrt(PI)),((2*PI)/3.0f)*sqrt(3.0f/(4*PI)),0.0f,0.0f)
};
// offsets to six neighbor cell centers
static int3 offsets[6] =
{
int3(0,0,1), int3(1,0,0), int3(0,0,-1),
int3(-1,0,0), int3(0,1,0), int3(0,-1,0)
};
uint GroupIndex: SV_GroupIndex)
{
// Get grid position of current cell.
// Initialize SH-coefficients with values from current cell.
[unroll]
for ( int i=0;i<6;i++)
{
// Get grid position of six neighbor cells.
int3 samplePos = elementPos+offsets[i];
// continue, if cell is out of bounds
if ((samplePos.x<0)||(samplePos.x>31)||(samplePos.y<0)||
(samplePos.y>31)||(samplePos.z<0)||(samplePos.z>31))
continue ;
// Load SH-coefficients for neighbor cell.
#ifdef USE_OCCLUSION
float4 occlusionCoeffs = float4(0.0f,0.0f,0.0f,0.0f);
// Get index of corresponding voxel.
int gridIndex = (samplePos.z*1024)+(samplePos.y*32)+samplePos.x;
VOXEL voxel = gridBuffer[gridIndex];
// If voxel contains geometry information , find closest normal to
// current direction. In this way the highest occlusion can be
// generated. Then calculate SH-coefficients for retrieved normal.
if (voxel.occlusion > 0)
{
float dotProduct;
-directions[i],dotProduct);
occlusionCoeffs = ClampedCosineSHCoeffs(occlusionNormal);
}
#endif
[unroll]
for ( int j=0;j<6;j++)
{
// Get direction for face of current cell to current neighbor
// cell center.
float3 neighborCellCenter = directions[i];