Game Development Reference
In-Depth Information
// lower-left vertex
output[0].position = float4(input[0].position.x,input[0].position.y,
input[0].position.z,1.0f);
// lower-right vertex
output[1].position = float4(input[1].position.x,input[0].position.y,
input[0].position.z,1.0f);
// upper-left vertex
output[2].position = float4(input[0].position.x,input[1].position.y,
input[0].position.z,1.0f);
// upper-right vertex
output[3].position = float4(input[1].position.x,input[1].position.y,
input[0].position.z,1.0f);
// By using hardware instancing, the geometry shader will be invoked 32
// times with the corresponding instance ID. For each invocation the
// instance ID is used to determine into which slice of a 2D texture
// array the current quad should be rasterized.
[unroll]
for ( int i=0;i<4;i++)
{
output[i].rtIndex = input[0].instanceID;
outputStream.Append(output[i]);
}
outputStream.RestartStrip();
}
// pixel shader
StructuredBuffer <VOXEL> gridBuffer: register (t0);
struct FS_OUTPUT
{
float4 fragColor0: SV_TARGET0; // red SH-coefficients
float4 fragColor1: SV_TARGET1; // blue SH-coefficients
float4 fragColor2: SV_TARGET2; // green SH-coefficients
};
// Calculate second-order SH-coefficients for clamped cosine lobe function.
float4 ClampedCosineSHCoeffs(in float3 dir)
{
float4 coeffs;
coeffs.x = PI/(2.0f*sqrt(PI));
coeffs.y = -((2.0f*PI)/3.0f)*sqrt(3.0f/(4.0f*PI));
coeffs.z = ((2.0f*PI)/3.0f)*sqrt(3.0f/(4.0f*PI));
coeffs.w = -((2.0f*PI)/3.0f)*sqrt(3.0f/(4.0f*PI));
coeffs.wyz *= dir;
return coeffs;
}
// Determine which of the four specified normals is closest to the
// specified direction. The function returns the closest normal and as
// output parameter the corresponding dot product.
float3 GetClosestNormal(in uint4 normalMasks ,in float3 direction,out float
dotProduct)
{
float4x3 normalMatrix;
normalMatrix[0] = DecodeNormal(normalMasks.x);
normalMatrix[1] = DecodeNormal(normalMasks.y);
normalMatrix[2] = DecodeNormal(normalMasks.z);
normalMatrix[3] = DecodeNormal(normalMasks.w);
float4 dotProducts = mul(normalMatrix ,direction);
float maximum = max (max(dotProducts.x,dotProducts.y),
max(dotProducts.z,dotProducts.w));
 
Search Nedrilad ::




Custom Search