Using different LightnigEffects with the same Model

rated by 0 users
This post has 2 Replies | 2 Followers

Top 75 Contributor
Posts 41
SunBurn_Community_Licensee
SunBurn_Pro_Licensee
khayman218 Posted: 09-05-2010 12:21 AM

Is it possible to use different effects with the same model using the built-in renderer?

I have a switch model that I want to render in different color textures based on its state.

 

Thanks.

Top 10 Contributor
Posts 337
SunBurn_Community_Licensee
SunBurn_Pro_Licensee

this would a simple process using custom effects (.FX)

Top 10 Contributor
Posts 4,546
Employee
SunBurn_Studio_Licensee

Hi khayman,

To make these SceneObject effects unique you can loop through and clone them.  As an example:


SceneObject obj = new SceneObject(model);

foreach(RenderableMesh mesh in obj.RenderableMeshes)
{
    mesh.Effect = mesh.Effect.Clone();
    // you can do something to the unique effect here or later in code, and it will no longer affect any other object...
    // for instance change a player's diffuse texture to the team color texture (red, blue, ...)...
}


Please note this affects batching.  The effect(s) are no longer shared, so the object will not be batched with other objects, which can reduce performance if there are many objects with unique effects.

If you are creating groups of effects that are the same, for instance team materials (red, blue, ...), it's best to create one effect per group and assigned it to all objects in the group.  This will batch all objects in the group and help optimize performance.

Let me know if this helps!

Follow me on Twitter – development and personal tweets
Awesome XNA Videos – Lighting, Rendering, and game videos

Page 1 of 1 (3 items) | RSS