Game Development Reference
In-Depth Information
// Increase size of triangle in normalized device coordinates by the
// texel size of the currently bound render-target.
float2 side0N = normalize(output[1].position.xy-output[0].position.xy);
float2 side1N = normalize(output[2].position.xy-output[1].position.xy);
float2 side2N = normalize(output[0].position.xy-output[2].position.xy);
float texelSize = 1.0f/64.0f;
output[0].position.xy += normalize(-side0N+side2N)*texelSize;
output[1].position.xy += normalize(side0N-side1N)*texelSize;
output[2].position.xy += normalize(side1N-side2N)*texelSize;
[unroll]
for ( int j=0;j<3;j++)
outputStream.Append(output[j]);
outputStream.RestartStrip();
}
// pixel shader
struct VOXEL
{
uint colorMask; // encoded color
uint4 normalMasks; // encoded normals
uint occlusion; // voxel only contains geometry info if occlusion > 0
};
RWStructuredBuffer<VOXEL> gridBuffer: register (u1);
// normalized directions of four faces of a tetrahedron
static float3 faceVectors[4] =
{
float3(0.0f,-0.57735026f,0.81649661f),
float3(0.0f,-0.57735026f,-0.81649661f),
float3(-0.81649661f,0.57735026f,0.0f),
float3(0.81649661f,0.57735026f,0.0f)
};
int GetNormalIndex(in float3 normal,out float dotProduct)
{
float4x3 faceMatrix;
faceMatrix[0] = faceVectors[0];
faceMatrix[1] = faceVectors[1];
faceMatrix[2] = faceVectors[2];
faceMatrix[3] = faceVectors[3];
float4 dotProducts = mul(faceMatrix,normal);
float maximum = max (max(dotProducts.x,dotProducts.y),
max(dotProducts.z,dotProducts.w));
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 index;
}
void main(GS_OUTPUT input)
{
float3 base = colorMap.Sample(colorMapSampler ,input.texCoords).rgb;
 
Search Nedrilad ::




Custom Search