Click or drag to resize
DigitalRuneMaterialInstance Class
Represents an instance of a specific material.
Inheritance Hierarchy
SystemObject
  DigitalRune.Graphics.SceneGraphMaterialInstance

Namespace: DigitalRune.Graphics.SceneGraph
Assembly: DigitalRune.Graphics (in DigitalRune.Graphics.dll) Version: 1.2.0.0 (1.2.1.14562)
Syntax
public class MaterialInstance : IDictionary<string, EffectBinding>, 
	ICollection<KeyValuePair<string, EffectBinding>>, IEnumerable<KeyValuePair<string, EffectBinding>>, 
	IEnumerable

The MaterialInstance type exposes the following members.

Constructors
  NameDescription
Protected methodMaterialInstance
Initializes a new instance of the MaterialInstance class. (This constructor creates an uninitialized instance. Use this constructor only for cloning or other special cases!)
Public methodMaterialInstance(Material)
Initializes a new instance of the MaterialInstance class.
Top
Methods
  NameDescription
Public methodClone
Creates a new MaterialInstance that is a clone of the current instance.
Protected methodCloneCore
Makes the instance a clone (deep copy) of the specified MaterialInstance.
Public methodContains
Determines whether the material instance contains effect parameter bindings for the specified render pass.
Protected methodCreateInstanceCore
When implemented in a derived class, creates a new instance of the MaterialInstance derived class.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetEnumerator
Returns an enumerator that iterates through a collection.
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodTryGet
Gets the effect parameter bindings for the specified render pass.
Top
Extension Methods
  NameDescription
Public Extension MethodAddRangeKeyValuePairString, EffectBinding (Defined by CollectionHelper.)
Public Extension MethodDoKeyValuePairString, EffectBinding(ActionKeyValuePairString, EffectBinding)Overloaded.
Performs the given action on each element in a sequence when it is enumerated.
(Defined by LinqHelper.)
Public Extension MethodDoKeyValuePairString, EffectBinding(ActionKeyValuePairString, EffectBinding, Int32)Overloaded.
Performs the given action on each element (incorporating its index) in a sequence when it is enumerated.
(Defined by LinqHelper.)
Public Extension MethodForEachKeyValuePairString, EffectBinding(ActionKeyValuePairString, EffectBinding)Overloaded.
Immediately performs the given action on each element in a sequence.
(Defined by LinqHelper.)
Public Extension MethodForEachKeyValuePairString, EffectBinding(ActionKeyValuePairString, EffectBinding, Int32)Overloaded.
Immediately performs the given action on each element (incorporating its index) in a sequence.
(Defined by LinqHelper.)
Public Extension MethodIndexOfKeyValuePairString, EffectBinding
Returns the index of the first element in a sequence that satisfies the specified condition.
(Defined by LinqHelper.)
Top
Properties
  NameDescription
Public propertyCount
Gets the number of render passes supported by this material instance.
Public propertyEffectBindings
Gets a read-only collection of effect bindings used by this material instance.
Public propertyItem
Gets or sets the effect parameter bindings for the specified render pass.
Public propertyMaterial
Gets the material.
Public propertyPasses
Gets a read-only collection of all the render passes supported by this material instance.
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implementationPrivate methodICollectionKeyValuePairString, EffectBindingAdd
Explicit interface implementationPrivate methodIDictionaryString, EffectBindingAdd
Explicit interface implementationPrivate methodICollectionKeyValuePairString, EffectBindingClear
Explicit interface implementationPrivate methodICollectionKeyValuePairString, EffectBindingContains
Explicit interface implementationPrivate methodIDictionaryString, EffectBindingContainsKey
Explicit interface implementationPrivate methodICollectionKeyValuePairString, EffectBindingCopyTo
Explicit interface implementationPrivate methodIEnumerableKeyValuePairString, EffectBindingGetEnumerator
Returns an enumerator that iterates through the collection.
Explicit interface implementationPrivate methodIEnumerableGetEnumerator
Returns an enumerator that iterates through a collection.
Explicit interface implementationPrivate propertyICollectionKeyValuePairString, EffectBindingIsReadOnly
Explicit interface implementationPrivate propertyIDictionaryString, EffectBindingKeys
Explicit interface implementationPrivate methodICollectionKeyValuePairString, EffectBindingRemove
Explicit interface implementationPrivate methodIDictionaryString, EffectBindingRemove
Explicit interface implementationPrivate methodIDictionaryString, EffectBindingTryGetValue
Gets the value associated with the specified key.
Explicit interface implementationPrivate propertyIDictionaryString, EffectBindingValues
Top
Remarks

Each mesh has a set of materials (see class Material). A material defines the effect bindings (see class EffectBinding) for all required render passes.

The effect parameters basically fall into two categories:

  • Non-shared parameters, which are unique for each mesh node. Examples are world matrices, light properties, etc. These effect parameters depend on the actual mesh instance that is rendered.
  • Shared parameters, which are shared by mesh nodes with the same base mesh. Examples are view/projection matrices, most material properties, etc.

When a new mesh node (see class MeshNode) is created for a mesh (see class Mesh), all materials are instanced. That means, a new object of type MaterialInstance is created for each material. A material instance references the base material from which it was created (see property Material).

Both, the base material and the material instance are dictionaries of effect bindings: They contain one effect binding for each render pass that is required to render the mesh. The base material contains the bindings for all shared parameters. The material instance contains the bindings for non-shared parameters. Materials can be shared between different meshes - they are not bound to a specific mesh, but material instances belong to a certain mesh node!

Cloning:
MaterialInstances can be cloned. When Clone is called all EffectBindings are duplicated (deep copy). The base Material is copied by reference (shallow copy).

See Also