Graphics Reference
In-Depth Information
27. And then, for each mesh that supports reflections, create a new DynamicCubeMap
instance and initialize.
// If MeshRenderer instance is reflective:
var mesh = ...some reflective MeshRenderer instance
var envMap = ToDispose( new DynamicCubeMap(256) );
envMap.Reflector = mesh;
envMap.Initialize(this);
m.EnvironmentMap = envMap;
// Add to list of cube maps
envMaps.Add(envMap);
28. The bulk of our rendering loop will now be moved into a local anonymous method.
In our simple example, this should be located before the start of the rendering loop
as shown in the following code snippet:
// Action for rendering the entire scene
Action<DeviceContext, Matrix, Matrix, RenderTargetView,
DepthStencilView, DynamicCubeMap> renderScene =
(context, view, projection, rtv, dsv, envMap) =>
{
// We must initialize the context every time we render
// the scene as we are changing the state depending on
// whether we are rendering a cube map or final scene
InitializeContext(context, false);
// We always need the immediate context
var immediateContext = this.DeviceManager.Direct3DDevice
.ImmediateContext;
// Clear depth stencil view
context.ClearDepthStencilView( dsv ,
DepthStencilClearFlags.Depth |
DepthStencilClearFlags.Stencil, 1.0f, 0);
// Clear render target view
context.ClearRenderTargetView( rtv , background);
// Create viewProjection matrix
var viewProjection = Matrix.Multiply( view, projection );
// Extract camera position from view
var camPosition = Matrix.Transpose( Matrix.Invert(view) )
.Column4;
cameraPosition = new Vector3(camPosition.X,
camPosition.Y, camPosition.Z);
...SNIP perform all rendering actions and multithreading
}
 
Search WWH ::




Custom Search