Game Development Reference
In-Depth Information
int index;
if (maximum==dotProducts.x)
index = 0;
else if (maximum==dotProducts.y)
index = 1;
else if (maximum==dotProducts.z)
index = 2;
else
index = 3;
dotProduct = dotProducts[index];
return normalMatrix[index];
}
PS_OUTPUT main(GS_OUTPUT input)
{
PS_OUTPUT output;
// Get index of current voxel.
int3 voxelPos = int3(input.position.xy,input.rtIndex);
int gridIndex = (voxelPos.z*1024)+(voxelPos.y*32)+voxelPos.x;
// Get voxel data and early out, if voxel has no geometry information.
VOXEL voxel = gridBuffer[gridIndex];
if (voxel.occlusion==0)
discard;
// Get world-space position of voxel.
int3 offset = samplePos-int3(16,16,16);
float3 position = (float3(offset)*constBuffer.gridCellSize)+
constBuffer.snappedGridCenter;
// Decode color of voxel.
float3 albedo = DecodeColor(voxel.colorMask);
// Get normal of voxel that is closest to the light direction.
float nDotL;
float3 normal = GetClosestNormal(voxel.normalMasks,lightVecN,nDotL);
// Calculate diffuse lighting according to current light type.
float3 diffuse = CalcDiffuseLighting(albedo,nDotL);
#ifdef USE_SHADOWS
// Calculate shadow term according to current light type with the help
// of a shadow map.
float shadowTerm = ComputeShadowTerm(position);
diffuse *= shadowTerm;
#endif
// Calculate clamped cosine lobe SH-coefficients for VPL.
float4 coeffs = ClampedCosineSHCoeffs(normal);
// Output SH-coefficients for each color channel.
output.fragColor0 = coeffs*diffues.r;
output.fragColor1 = coeffs*diffuse.g;
output.fragColor2 = coeffs*diffuse.b;
return output;
}
Listing 7.2. VPL creation.
 
Search Nedrilad ::




Custom Search