To provide you own rendering logic you can use CustomRenderableNode object - it is a special SceneNode object that is created with a callback action that is called when the SceneNode needs to be rendered. The Action is called with RenderingContext and other parameters and there you can set your own DirectX states and call Draw calls.
When setting states, constant buffers and shaders please use the renderingContext.ContextStatesManager object - this way your custom code will work fine with other DXEngine SceneNodes.
To see a sample CustomRenderableNode check the Customizations\CustomRenderingStep4.xaml.cs source in the DXEngine samples project (there are also some additional comments).
You can also provide your rendering logic by specifying your own CustomActionRenderingStep - rendering steps are defined in the DXScene.RenderingSteps collection and define the steps that are executed to render one frame.
By default the rendering steps are:
- InitializeRenderingStep - InitializeRendering is the first rendering step. It sets up the RenderingContext with current RenderTargets, resets statistics, etc.
- PrepareRenderTargetsRenderingStep - PrepareRenderTargets sets rendering targets and clears them and sets Viewport.
- RenderObjectsRenderingStep - Default RenderObjects renders the objects with their default effect and material.
- ResolveMultisampledBackBufferRenderingStep - Resolve multisampled back buffer (MSAABackBuffer) into the back buffer.
- PreparePostProcessingRenderingStep - prepares the buffers for post-processing. When no post-processing effects are used, this and the next steps are not present in the RenderingSteps collection.
- RenderPostProcessingRenderingStep - renders the post processing effects.
- CompleteRenderingStep - CompleteRendering is the last rendering step. It Presents SwapChain (if used) or prepares the output buffer that can be sent to WPF or CPU memory.
You can add your own rendering step between already defined rendering steps.
This can be done with the following steps:
- Define your own rendering step.
This can be done with derived a class from Ab3d.DirectX.RenderingStepBase and implement OnRun method. Another simpler option is to create a new instance of Ab3d.DirectX.CustomActionRenderingStep class and set its CustomAction delegate to your method that will execute your code (this is also used in this sample).
- Insert your rendering step into the existing rendering steps.
This is done by calling AddAfter or AddBefore methods. Both these methods take an existing rendering step as the first parameter. To get existing rendering steps, you can use the properties defined in DXScene - the names of properties start with Default and then the name of rendering step class - for example:
dxScene.RenderingSteps.AddAfter(dxScene.DefaultPrepareRenderTargetsRenderingStep, newRenderingStep);
- Execute your code based on the RenderingContext. OnRun or CustomAction are called with RenderingContext that provide various properties about current rendering process - for example:
Current DirectX device, device context, render target, back buffer, viewport, frame number, etc.
Many other scene related properties can be get from the DXScene - for example, the current camera and lights.
More information about this process and sample code can be seen in samples from Customizations\CustomRenderingStep1 to Customizations\CustomRenderingStep3. It is recommended to check also other samples in the Customizations folder.