Effects and Effect Bindings |
DigitalRune Graphics uses DirectX Effects for managing render pipeline states. At runtime effects are managed using so called "effect bindings".
This topic contains the following sections:
A DirectX effect (see XNA class Effect) describes the render pipeline states that are required to produce certain render conditions. These render pipeline states include:
An effect usually requires several effect parameters, such as
Some of these effect parameters can be set directly by the user, some need to be resolved automatically by the graphics engine.
In addition, an effect may define multiple versions of shaders (called effect techniques) to support different hardware. At runtime the graphics engine needs to select the technique which is appropriate for the current hardware.
Effects are defined using effect files (.FX). See Writing an Effect (Direct3D 9) for more information.
DigitalRune Graphics introduces the concept of effect bindings (see class EffectBinding). An effect binding implements the logic that is required for using an effect at runtime. The effect binding includes
Effect bindings are usually created automatically when loading a model or a material. The mechanism for initializing effect bindings is described below (see "Initialization").
An effect may define several effect techniques for rendering objects. The EffectTechniqueBinding provides the logic to select the appropriate technique when rendering a specific object. For example, when the MeshRenderer renders a mesh it calls the effect technique binding to select the appropriate technique.
Effect technique bindings are created automatically when an effect is loaded. Effect technique bindings cannot be replaced at runtime. By default, if no special effect technique binding is created, a ByNameTechniqueBinding is set.
Once an effect technique is selected EffectTechniqueBindingGetPassBinding needs to be called to get the EffectPassBinding. The effect pass binding provides an enumerator that iterates over all effect passes that need to be applied for rendering the current object.
An EffectParameterBinding binds an effect parameter to a certain value. When an effect is selected for rendering, the effect parameter bindings are evaluated and the resulting values are set in the shader.
DigitalRune Graphics provides several types of parameter bindings:
Effect parameter bindings are created automatically when an effect is loaded. Parameter bindings can be replaced at runtime.
Effect bindings can be created manually in code, but in most cases effect bindings are set up automatically when models and materials are loaded. The effect technique and parameters bindings are initialized in two steps:
The effect binding system is extensible: The effect interpreters and binders are stored in the graphics service (see properties EffectInterpreters and EffectBinders). New effect interpreters and binders can be added to support new types of effects or add new binding mechanisms. See How To: Add Support for New Effect Parameters
The XNA stock effects
are automatically wrapped using special effect bindings: