Graphics Reference
In-Depth Information
4.
The output from the geometry shader (and therefore, input to our new pixel shader)
is exactly the same as the PixelShaderInput structure within Shaders\Common.
hlsl , except that we have added one new property to control the render target
(that is, the face of the cube map) used.
// Pixel Shader input structure (from Geometry Shader)
struct GS_CubeMapOutput
{ float4 Position : SV_Position;
...SNIP (existing PixelShaderInput structure properties)
// Allows writing to multiple render targets
uint RTIndex : SV_RenderTargetArrayIndex;
};
5.
The new vertex shader is almost the same as the existing one in Shaders\VS.hlsl ;
however, we need to apply the World matrix transform on the Position property.
// Vertex shader cubemap function
GeometryShaderInput VS_CubeMap (VertexShaderInput vertex)
{ GeometryShaderInput result = (GeometryShaderInput)0;
...SNIP
// Only apply world transform (not WorldViewProjection)
result.Position = mul(vertex.Position, World);
...SNIP
}
6.
The new geometry shader is where we use the geometry shader instance
attribute of Shader Model 5 to execute the shader six times per input primitive
(that is, six times per triangle).
[maxvertexcount(3)] // Outgoing vertex count (1 triangle)
[instance(6)] // Number of times to execute for each input
void GS_CubeMap(triangle GeometryShaderInput input[3],
uint instanceId: SV_GSInstanceID ,
inout TriangleStream<GS_CubeMapOutput> stream)
{
// Output the input triangle using the View/Projection
// of the cube face identified by instanceId
float4x4 viewProj = CubeFaceViewProj[instanceId];
GS_CubeMapOutput output;
// Assign the render target instance
// i.e. 0 = +X-face, 1 = -X-face and so on
output.RTIndex = instanceId;
// In order to render correctly into a TextureCube we
// must either:
 
Search WWH ::




Custom Search