Graphics Reference
In-Depth Information
if (isFullScreen || (cameraParams.ZNear > viewSpacePos.Z -
light.Range && cameraParams.ZFar < viewSpacePos.Z + light.
Range))
{
// Use SAQuad to process entire G-Buffer
context.OutputMerger.DepthStencilState = depthDisabled;
saQuad.ShaderResources = null;
saQuad.Shader = shader; // Set appropriate light shader
saQuad.Render();
}
else // Render volume (point light)
{
... see next step
}
22. In the case above, when the camera is not fully enclosed by the point light's volume,
we need to scale and position the volume mesh for the light (for example, a sphere).
Prior to rendering the mesh, we determine whether to cull front or back faces,
and whether to perform a greater-than/lesser-than depth test.
// Set appropriate shader
context.PixelShader.Set(shader);
context.VertexShader.Set(vertexShader);
MeshRenderer volume = pointLightVolume;
// Prepare world matrix
Matrix world = Matrix.Identity;
world.ScaleVector = Vector3.One * light.Range;
world.TranslationVector = Lights[i].Position;
volume.World = world;
var transposed = PerObject; // Transpose PerObject matrices
transposed.World = volume.World;
transposed.WorldViewProjection = volume.World *
PerObject.ViewProjection;
transposed.Transpose();
context.UpdateSubresource(ref transposed, PerObjectBuffer);
if (cameraParams.ZFar < viewSpacePos.Z + light.Range)
{
// Cull the back face and only render where there is
// something behind the front face.
context.Rasterizer.State = rsCullBack;
context.OutputMerger.DepthStencilState = depthLessThan;
}
else
 
Search WWH ::




Custom Search