Click or drag to resize
DigitalRuneMaterials and Material Instances

A material defines how a submesh is rendered: Which render passes are supported? Which effects are used? Which effect parameters (e.g. colors and textures) are used?

This topic contains the following sections:

Materials

A material defines how a submesh is rendered. Depending on the render pipeline drawing a submesh may involve several render passes.

For example, a typical light pre-pass renderer requires the following render passes:

  1. In the "ShadowMap" pass the mesh is rendered into the shadow map, which is used later on.
  2. In the "GBuffer" pass the depth, the normals, and other mesh properties are rendered into multiple render targets.
  3. Next the renderer computes the lighting information.
  4. Then in the "Material" pass, the mesh is rendered again - the lighting information is combined with the material settings.

Each render pass usually requires its own effect binding.

A material (see class Material) is a dictionary that contains the effect bindings for all render passes. The dictionary key is the name of the render pass (string) and the value is the EffectBinding to be used for the render pass.

Simple renderers may only require a single render pass ("Default"). Complex renderers may require several render passes ("ShadowMap", "GBuffer", "Material", etc.).

Materials can (and should be!) reused by different meshes. The graphics engine automatically sorts meshes by materials to reduce the number of required render state changes in order to improve performance.

Materials can be defined created in code, but materials for model assets are usually defined in XML files, see Materials (*.drmat). Here is an example DRMAT file:

<?xml version="1.0" encoding="utf-8"?>

<Material Name="CustomMaterial">
  <Pass Name="Default" Effect="BasicEffect" Profile="Any">
    <Parameter Name="DiffuseColor" Value="1,1,1" />
    <Parameter Name="SpecularColor" Value="1,1,1" />
    <Parameter Name="SpecularPower" Value="100" />
    <Texture Name="Texture" File="albedo.tga" />
  </Pass>
  <Pass Name="ShadowMap" Effect="DigitalRune/Materials/ShadowMap" Profile="HiDef" />
  <Pass Name="GBuffer" Effect="DigitalRune/Materials/GBufferNormal" Profile="HiDef">
    <Parameter Name="SpecularPower" Value="100" />
    <Texture Name="NormalTexture" Format="Normal" File="normal.tga" />
  </Pass>
  <Pass Name="Material" Effect="CustomMaterial.fx" Profile="HiDef">
    <Parameter Name="DiffuseColor" Value="1,1,1" />
    <Parameter Name="SpecularColor" Value="1,1,1" />
    <Parameter Name="CustomParameter" Value="0.95" />
    <Texture Name="DiffuseTexture" File="albedo.tga" />
    <Texture Name="SpecularTexture" File="specular.tga" />
  </Pass>
</Material>
MaterialInstances

When a MeshNode is created for a Mesh, the materials are "instanced". That means a MaterialInstance is created for each Material.

A Material contains the effect parameter bindings that are shared by all mesh instances. The MaterialInstance contains the effect technique binding and all effect parameter bindings that are specific to the mesh instance.

Class diagram
Meshes and Materials
Class Diagram: Meshes and Materials