Uh, sorry when I was writing an answer, I did not have time to check if this would work.
I have checked things again and now I see that multipass rendering works only for standard effect – an effect that is registered as standard effect and rendered objects with standard materials (object, that do not have any specific effect specified). In DXEngine this is used to render many lights – one StandardEffect can render 26 lights in one pass so in cases where there is more than 16 lights in the scene, multiple passes are used to render all the lights.
You can easily register an effect as standard effect with the call to SetStandardEffect on EffectManager (for example for CustomShaderMaterialSample you can use the following line of code – put that into line 93):
dxScene.DXDevice.EffectsManager.SetStandardEffect(_wpfMaterialEffect);
After that the GetRequiredRenderingPassesCount method will be called. If you return 2, then ApplyRenderingPass method is called before rendering the second pass.
Note that to render transparent objects correctly, DXEngine first renders all passes for the the non-transparent objects and then it renders all the passes for the transparent objects.
For example for 2-pass shader the following methods are called on each frame:
GetRequiredRenderingPassesCount
// Render non-transparent objects
OnApplyPerFrameSettings
// The following two methdos are called for each object with stadard material
ApplyMaterial // apply settings before rendering 1st pass
ApplyRenderingPass // apply settings before rendering 2nd pass
// Render transparent objects
OnApplyPerFrameSettings
// The following two methdos are called for each object with stadard material
ApplyMaterial // apply settings before rendering 1st pass
ApplyRenderingPass // apply settings before rendering 2nd pass
Another way to render 2-passes is to customize the rendering steps (steps that are executed for each frame).
Usually objects are rendered in RenderObjectsRenderingStep class (an instance can be get from MainDXViewportView.DXScene.DefaultRenderObjectsRenderingStep). RenderObjectsRenderingStep allows you to provide a filter function to render only selected objects. You can also specify the OverrideEffect – effect that will be used to render all the objects.
This allows you to change the default RenderObjectsRenderingStep and set the OverideEffect to an effect that renders the first pass. Then you add another RenderObjectsRenderingStep instance and set its OverideEffect to an effect to render second pass.
For example:
Code:
var secondPassRenderObjects = new RenderObjectsRenderingStep("SecondPassRenderObjects")
{
OverrideEffect = ...
FilterObjectsFunction = ...
};
MainDXViewportView.DXScene.RenderingSteps.AddBefore(MainDXViewportView.DXScene.DefaultRenderObjectsRenderingStep, secondPassRenderObjects);
You can also add additional RenderObjectsRenderingStep and set FilterObjectsFunction so they will render only specified objects.
As you see it is possible to render multi-pass effects, but this not yet an easy task. In the future I will improve support for that and also write an sample that will demonstrate how to do that.