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)
};
[numthreads(8,8,8)]
void main(uint3 GroupID: SV_GroupID,uint3 DispatchThreadID:
SV_DispatchThreadID,uint3 GroupThreadID: SV_GroupThreadID ,
uint GroupIndex: SV_GroupIndex)
{
// Get grid position of current cell.
int3 elementPos = DispatchThreadID.xyz;
// Initialize SH-coefficients with values from current cell.
float4 sumRedSHCoeffs = inputRedSHTexture.Load(int4(elementPos ,0));
float4 sumGreenSHCoeffs = inputGreenSHTexture.Load(int4(elementPos ,0));
float4 sumBlueSHCoeffs = inputBlueSHTexture.Load(int4(elementPos ,0));
[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.
float4 redSHCoeffs = inputRedSHTexture.Load(int4(samplePos ,0));
float4 greenSHCoeffs = inputGreenSHTexture.Load(int4(samplePos ,0));
float4 blueSHCoeffs = inputBlueSHTexture.Load(int4(samplePos ,0));
#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;
float3 occlusionNormal = GetClosestNormal(voxel.normalMasks ,
-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];
 
Search Nedrilad ::




Custom Search