Table of Contents

Class MaterialProcessor

Namespace
Microsoft.Xna.Framework.Content.Pipeline.Processors
Assembly
MonoGame.Framework.Content.Pipeline.dll

Provides methods and properties for maintaining a collection of named texture references.

[ContentProcessor(DisplayName = "Material - MonoGame")]
public class MaterialProcessor : ContentProcessor<MaterialContent, MaterialContent>, IContentProcessor
Inheritance
MaterialProcessor
Implements
Inherited Members

Remarks

In addition to texture references, opaque data values are stored in the OpaqueData property of the base class.

Constructors

MaterialProcessor()

Initializes a new instance of the MaterialProcessor class.

public MaterialProcessor()

Properties

ColorKeyColor

Gets or sets the color value to replace with transparent black.

public virtual Color ColorKeyColor { get; set; }

Property Value

Color

Color value of the material to replace with transparent black.

ColorKeyEnabled

Specifies whether color keying of a texture is enabled.

public virtual bool ColorKeyEnabled { get; set; }

Property Value

bool

true if color keying is enabled; false otherwise.

DefaultEffect

The default effect type for this instance of MaterialProcessor.

public virtual MaterialProcessorDefaultEffect DefaultEffect { get; set; }

Property Value

MaterialProcessorDefaultEffect

The default effect type.

Remarks

When MaterialProcessor is instantiated, DefaultEffect is set to default to BasicEffect Class.

GenerateMipmaps

Specifies if a full chain of mipmaps are generated from the source material. Existing mipmaps of the material are not replaced.

public virtual bool GenerateMipmaps { get; set; }

Property Value

bool

true if mipmap generation is enabled; false otherwise.

PremultiplyTextureAlpha

Specifies whether alpha premultiply of textures is enabled.

public virtual bool PremultiplyTextureAlpha { get; set; }

Property Value

bool

true if alpha premultiply is enabled; false otherwise.

ResizeTexturesToPowerOfTwo

Specifies whether resizing of a material is enabled. Typically used to maximize compatability with a graphics card because many graphics cards do not support a material size that is not a power of two. If ResizeTexturesToPowerOfTwo is enabled, the material is resized to the next largest power of two.

public virtual bool ResizeTexturesToPowerOfTwo { get; set; }

Property Value

bool

true if resizing is enabled; false otherwise.

TextureFormat

Specifies the texture format of output materials. Materials can either be left unchanged from the source asset, converted to a corresponding Color, or compressed using the appropriate DxtCompressed format.

public virtual TextureProcessorOutputFormat TextureFormat { get; set; }

Property Value

TextureProcessorOutputFormat

The texture format of the output.

Methods

BuildEffect(ExternalReference<EffectContent>, ContentProcessorContext)

Builds effect content.

protected virtual ExternalReference<CompiledEffectContent> BuildEffect(ExternalReference<EffectContent> effect, ContentProcessorContext context)

Parameters

effect ExternalReference<EffectContent>

An external reference to the effect content.

context ContentProcessorContext

Context for the specified processor.

Returns

ExternalReference<CompiledEffectContent>

A platform-specific compiled binary effect.

Remarks

If the input to process is of type EffectMaterialContent, this function will be called to request that the EffectContent be built. The EffectProcessor is used to process the EffectContent. Subclasses of MaterialProcessor can override this function to modify the parameters used to build EffectContent. For example, a different version of this function could request a different processor for the EffectContent.

BuildTexture(string, ExternalReference<TextureContent>, ContentProcessorContext)

Builds texture content.

protected virtual ExternalReference<TextureContent> BuildTexture(string textureName, ExternalReference<TextureContent> texture, ContentProcessorContext context)

Parameters

textureName string

The name of the texture. This should correspond to the key used to store the texture in Textures.

texture ExternalReference<TextureContent>

The asset to build. This should be a member of Textures.

context ContentProcessorContext

Context for the specified processor.

Returns

ExternalReference<TextureContent>

The built texture content.

Remarks

textureName can be used to determine which processor to use. For example, if a texture is being used as a normal map, the user may not want to use the ModelTextureProcessor on it, which compresses textures.

CreateDefaultMaterial(MaterialProcessorDefaultEffect)

Helper method which returns the material for a default effect.

public static MaterialContent CreateDefaultMaterial(MaterialProcessorDefaultEffect effect)

Parameters

effect MaterialProcessorDefaultEffect

Returns

MaterialContent

A material.

GetDefaultEffect(MaterialContent)

Helper method which returns the default effect for a material.

public static MaterialProcessorDefaultEffect GetDefaultEffect(MaterialContent content)

Parameters

content MaterialContent

Returns

MaterialProcessorDefaultEffect

The default effect.

Process(MaterialContent, ContentProcessorContext)

Builds the texture and effect content for the material.

public override MaterialContent Process(MaterialContent input, ContentProcessorContext context)

Parameters

input MaterialContent

The material content to build.

context ContentProcessorContext

Context for the specified processor.

Returns

MaterialContent

The built material.

Remarks

If the MaterialContent is of type EffectMaterialContent, a build is requested for Effect, and validation will be performed on the OpaqueData to ensure that all parameters are valid input to SetValue or SetValueTranspose. If the MaterialContent is a BasicMaterialContent, no validation will be performed on OpaqueData. Process requests builds for all textures in Textures, unless the MaterialContent is of type BasicMaterialContent, in which case a build will only be requested for DiffuseColor. The textures in Textures will be ignored.