Click or drag to resize
DigitalRuneEffects 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:

Effects

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:

  • Shader states: vertex shader, pixel shader, shader constants
  • Sampler states
  • Other pipeline states: blend states, cull mode, fill mode, stencil mode, depth mode

An effect usually requires several effect parameters, such as

  • Shader constants: transformation matrices, material settings, light properties, etc.
  • Textures: material textures, environment textures, shadow maps, lookup textures, etc.

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.

Caution note Caution

DigitalRune Graphics internally uses the Tag property of the Effect class. This property must not be modified by the game.

Effect bindings

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").

Effect Bindings
Class Diagram: Effect Bindings

Effect technique bindings

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.

Effect pass bindings

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.

Effect parameter bindings

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.

Initialization

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:

  1. Interpretation - The effect is interpreted by IEffectInterpreters. The interpreters create EffectTechniqueDescriptions and EffectParameterDescriptions.
    (The descriptions are stored by the graphics service and can be accessed using the methods EffectHelperGetTechniqueDescriptions and EffectHelperGetParameterDescriptions.)
  2. Binding - IEffectBinders read the descriptions and create EffectTechniqueBindings and EffectParameterBindings.

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

XNA stock effects
See Also