Game Development Reference
In-Depth Information
While rendering a full-screen quad, the pixel shader reconstructs the world-
space position and the normal for each pixel. According to the world-space po-
sition, the previously generated grid (in the form of three 2D texture arrays) is
sampled with linear hardware filtering. Therefore we manually only have to per-
form a filtering in the third dimension so that we retrieve smooth results. With
the help of the sampled SH-coecients and the surface normal, we can perform
an SH-lighting for each pixel. See Listing 7.4 for details.
// pixel shader
Texture2DArray inputRedSHTexture: register (t0);
Texture2DArray inputGreenSHTexture: register (t1);
Texture2DArray inputBlueSHTexture: register (t2);
PS_OUTPUT main(GS_OUTPUT input)
{
PS_OUTPUT output;
float depth = depthBuffer.Sample(depthBufferSampler,input.texCoords).r;
float4 position = ReconstructPositionFromDepth(depth);
float3 albedo = colorMap.Sample(colorMapSampler ,input.texCoords).rgb;
float3 normal =
normalBuffer.Sample(normalBufferSampler,input.texCoords).xyz;
// Get offset into grid.
float3 offset = (position.xyz-constBuffer.snappedGridCenter)*
constBuffer.invGridCellSize;
// Get texCoords into Texture2DArray.
float3 texCoords = float3(16.5f,16.5f,16.0f)+offset;
texCoords.xy /= 32.0f;
// Get texCoords for trilinear sampling.
int lowZ = floor(texCoords.z);
int highZ = min(lowZ+1,32-1);
float highZWeight = texCoords.z-lowZ;
float lowZWeight = 1.0f-highZWeight;
float3 tcLow = float3(texCoords.xy,lowZ);
float3 tcHigh = float3(texCoords.xy,highZ);
// Perform trilinear sampling of red, green, and blue SH-coefficients
// from Texture2DArray.
float4 redSHCoeffs =
lowZWeight*inputRedSHTexture.Sample(linearSampler ,tcLow)+
highZWeight*inputRedSHTexture.Sample(linearSampler ,tcHigh);
float4 greenSHCoeffs =
lowZWeight*inputGreenSHTexture.Sample(linearSampler ,tcLow)+
highZWeight*inputGreenSHTexture.Sample(linearSampler ,tcHigh);
float4 blueSHCoeffs =
lowZWeight*inputBlueSHTexture.Sample(linearSampler ,tcLow)+
highZWeight* inputBlueSHTexture.Sample(linearSampler ,tcHigh);
// Calculate clamped cosine lobe SH-coefficients for surface normal.
float4 surfaceNormalLobe = ClampedCosineSHCoeffs(normal);
// Perform diffuse SH-lighting.
float3 diffuseGlobalIllum;
diffuseGlobalIllum.r = dot(redSHCoeffs ,surfaceNormalLobe);
 
Search Nedrilad ::




Custom Search