class TMaterial

template<bool IsRenderProxy>
Inherits: MaterialBase

Material that controls how objects are rendered.

It is represented by a shader and parameters used to set up that shader. It provides a simple interface for manipulating the parameters.

Public

Constructors

TMaterial<IsRenderProxy>

TMaterial<IsRenderProxy>() = default

Methods

~TMaterial<IsRenderProxy>

virtual ~TMaterial<IsRenderProxy>() = default

GetShader

ShaderType GetShader() const

Returns the currently active shader.

GetVariationParameters

const ShaderVariationParameters &GetVariationParameters() const

Set of parameters that determine which subset of variations in the assigned shader should be used.

Only the variations that have the provided parameters with the provided values will match. This will control which variation is considered the default variation and which subset of variations are searched during a call to FindVariation().

GetVariationCount

u32 GetVariationCount() const

Returns the total number of variations supported by this material.

GetVariation

const SPtr<VariationType> &GetVariation(u32 index) const

Returns the variation at the specified index.

FindVariation

u32 FindVariation(const FindVariationInformation &information) const

Attempts to find a variation matching the specified variation and tags among the supported variations.

information
Object containing an optional set of tags and a set of variation parameters to look for.

Returns: First variation that matches the variation parameters specified in .

GetDefaultVariation

u32 GetDefaultVariation() const

Finds the index of the default (primary) variation to use.

This will be the first variation that matches the currently set variation parameters (if any).

GetPassCount

u32 GetPassCount(u32 variationIndex = 0) const

Returns the number of passes that are used by the variation at the specified index.

variationIndex
Index of the variation to retrieve the number of passes for. 0 is always guaranteed to be the default variation.

Returns: Number of passes used by the variation.

GetPass

SPtr<PassType> GetPass(u32 passIndex = 0, u32 variationIndex = 0) const

Retrieves a specific shader pass from the provided variation.

passIndex
Sequential index of the pass to retrieve.
variationIndex
Index of the variation to retrieve the pass for. 0 is always guaranteed to be the default variation.

Returns: Pass if found, null otherwise.

CreateParameterAdapter

SPtr<MaterialParameterAdapterType> CreateParameterAdapter(u32 variationIndex = 0)

Creates an adapter that can be used for transferring parameters from the material to GpuParameterSet objects.

The adapter will take care of tracking when material parameters change and can be used to update the underlying GpuParameterSet objects. Adapter is only valid for a particular material variation, you will need to create a different adapter for each variation.

SetFloat

void SetFloat(const String &name, float value, u32 arrayIdx = 0)

Assigns a float value to the shader parameter with the specified name.

Optionally if the parameter is an array you may provide an array index to assign the value to.

SetFloatCurve

void SetFloatCurve(const String &name, TAnimationCurve<float> value, u32 arrayIdx = 0)

SetColor

void SetColor(const String &name, const Color &value, u32 arrayIdx = 0)

Assigns a color to the shader parameter with the specified name.

Optionally if the parameter is an array you may provide an array index to assign the value to.

SetColorGradient

void SetColorGradient(const String &name, const ColorGradientHDR &value, u32 arrayIdx = 0)

Assigns a color gradient to the shader parameter with the specified name.

The system will automatically evaluate the gradient with the passage of time and apply the evaluated value to the parameter.

Optionally if the parameter is an array you may provide an array index to assign the value to.

SetVec2

void SetVec2(const String &name, const Vector2 &value, u32 arrayIdx = 0)

Assigns a 2D vector to the shader parameter with the specified name.

Optionally if the parameter is an array you may provide an array index to assign the value to.

SetVec3

void SetVec3(const String &name, const Vector3 &value, u32 arrayIdx = 0)

Assigns a 3D vector to the shader parameter with the specified name.

Optionally if the parameter is an array you may provide an array index to assign the value to.

SetVec4

void SetVec4(const String &name, const Vector4 &value, u32 arrayIdx = 0)

Assigns a 4D vector to the shader parameter with the specified name.

Optionally if the parameter is an array you may provide an array index to assign the value to.

SetMat3

void SetMat3(const String &name, const Matrix3 &value, u32 arrayIdx = 0)

Assigns a 3x3 matrix to the shader parameter with the specified name.

Optionally if the parameter is an array you may provide an array index to assign the value to.

SetMat4

void SetMat4(const String &name, const Matrix4 &value, u32 arrayIdx = 0)

Assigns a 4x4 matrix to the shader parameter with the specified name.

Optionally if the parameter is an array you may provide an array index to assign the value to.

SetStructData

void SetStructData(const String &name, void *value, u32 size, u32 arrayIdx = 0)

Assigns a structure to the shader parameter with the specified name.

Structure is provided as a raw buffer and caller must ensure structure in buffer matches what the shader expects.

Optionally if the parameter is an array you may provide an array index to assign the value to.

SetTexture

void SetTexture(const String &name, const TextureType &value, const TextureSurface &surface = TextureSurface::kComplete)

Assigns a texture to the shader parameter with the specified name.

SetSpriteImage

void SetSpriteImage(const String &name, const SpriteImageType &value)

Assigns a sprite image to the shader parameter with the specified name.

If the sprite image contains animation it will be automatically evaluated every frame.

SetLoadStoreTexture

void SetLoadStoreTexture(const String &name, const TextureType &value, const TextureSurface &surface)

Assigns a texture to be used for random load/store operations to the shader parameter with the specified name.

SetBuffer

void SetBuffer(const String &name, const BufferType &value)

Assigns a buffer to the shader parameter with the specified name.

SetSamplerState

void SetSamplerState(const String &name, const SPtr<SamplerState> &value)

Assigns a sampler state to the shader parameter with the specified name.

GetFloat

float GetFloat(const String &name, u32 arrayIdx = 0) const

Returns a float value assigned with the parameter with the specified name.

If a curve is assigned to this parameter, returns the curve value evaluated at time 0. Use getBoundParamType() to determine the type of the parameter.

Optionally if the parameter is an array you may provide an array index you which to retrieve.

GetFloatCurve

const TAnimationCurve<float> &GetFloatCurve(const String &name, u32 arrayIdx = 0) const

Returns a curve value assigned to the parameter with the specified name.

If the parameter has a constant value bound instead of a curve then this method returns an empty curve. Use getBoundParamType() to determine the type of the parameter.

Optionally if the parameter is an array you may provide an array index you which to retrieve.

GetColor

Color GetColor(const String &name, u32 arrayIdx = 0) const

Returns a color assigned with the parameter with the specified name.

If a color gradient is assigned to this parameter, returns the gradient color evaluated at time 0. Use getBoundParamType() to determine the type of the parameter.

Optionally if the parameter is an array you may provide an array index you which to retrieve.

GetColorGradient

const ColorGradientHDR &GetColorGradient(const String &name, u32 arrayIdx = 0) const

Returns a color gradient assigned with the parameter with the specified name.

If the parameter has a constant value bound instead of a gradient then this method returns an empty gradient. Use getBoundParamType() to determine the type of the parameter.

Optionally if the parameter is an array you may provide an array index you which to retrieve.

GetVec2

Vector2 GetVec2(const String &name, u32 arrayIdx = 0) const

Returns a 2D vector assigned with the parameter with the specified name.

Optionally if the parameter is an array you may provide an array index you which to retrieve.

GetVec3

Vector3 GetVec3(const String &name, u32 arrayIdx = 0) const

Returns a 3D vector assigned with the parameter with the specified name.

Optionally if the parameter is an array you may provide an array index you which to retrieve.

GetVec4

Vector4 GetVec4(const String &name, u32 arrayIdx = 0) const

Returns a 4D vector assigned with the parameter with the specified name.

Optionally if the parameter is an array you may provide an array index you which to retrieve.

GetMat3

Matrix3 GetMat3(const String &name, u32 arrayIdx = 0) const

Returns a 3x3 matrix assigned with the parameter with the specified name.

Optionally if the parameter is an array you may provide an array index you which to retrieve.

GetMat4

Matrix4 GetMat4(const String &name, u32 arrayIdx = 0) const

Returns a 4x4 matrix assigned with the parameter with the specified name.

Optionally if the parameter is an array you may provide an array index you which to retrieve.

IsAnimated

bool IsAnimated(const String &name, u32 arrayIdx = 0)

Checks does the data parameter with the specified name currently contains animated data.

This could be an animation curve or a color gradient.

GetTexture

TextureType GetTexture(const String &name) const

Returns a texture assigned with the parameter with the specified name.

GetSpriteImage

SpriteImageType GetSpriteImage(const String &name) const

Returns a sprite image assigned to the parameter with the specified name.

If the parameter has a regular texture attached instead of a sprite image, null will be returned. Use getBoundParamType() to determine the type of the parameter.

GetSamplerState

SPtr<SamplerState> GetSamplerState(const String &name) const

Returns a sampler state assigned with the parameter with the specified name.

GetStructData

MaterialBase::StructData GetStructData(const String &name, u32 arrayIdx = 0) const

Returns a buffer representing a structure assigned to the parameter with the specified name.

Optionally if the parameter is an array you may provide an array index you which to retrieve.

GetParamFloat

TMaterialParameterPrimitive<float, IsRenderProxy> GetParamFloat(const String &name) const

Returns a handle that allows you to assign a constant value to a floating point parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamFloatCurve

TMaterialParameterCurve<float, IsRenderProxy> GetParamFloatCurve(const String &name) const

Returns a handle that allows you to assign a time-varying curve to a floating point parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamColor

TMaterialParameterPrimitive<Color, IsRenderProxy> GetParamColor(const String &name) const

Returns a handle that allows you to assign a constant value to a color parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamColorGradient

TMaterialParameterColorGradient<IsRenderProxy> GetParamColorGradient(const String &name) const

Returns a handle that allows you to assign a time-varying gradient to a color parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamVec2

TMaterialParameterPrimitive<Vector2, IsRenderProxy> GetParamVec2(const String &name) const

Returns a handle that allows you to assign a constant value to a 2D vector parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamVec3

TMaterialParameterPrimitive<Vector3, IsRenderProxy> GetParamVec3(const String &name) const

Returns a handle that allows you to assign a constant value to a 3D vector parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamVec4

TMaterialParameterPrimitive<Vector4, IsRenderProxy> GetParamVec4(const String &name) const

Returns a handle that allows you to assign a constant value to a 4D vector parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamMat3

TMaterialParameterPrimitive<Matrix3, IsRenderProxy> GetParamMat3(const String &name) const

Returns a handle that allows you to assign a constant value to a 3x3 matrix parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamMat4

TMaterialParameterPrimitive<Matrix4, IsRenderProxy> GetParamMat4(const String &name) const

Returns a handle that allows you to assign a constant value to a 4x4 matrix parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamStruct

TMaterialParameterStruct<IsRenderProxy> GetParamStruct(const String &name) const

Returns a handle that allows you to assign a structure GPU parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamTexture

TMaterialParameterSampledTexture<IsRenderProxy> GetParamTexture(const String &name) const

Returns a handle that allows you to assign a texture GPU parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamSpriteImage

TMaterialParamSpriteImage<IsRenderProxy> GetParamSpriteImage(const String &name) const

Returns a handle that allows you to assign a sprite texture GPU parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamLoadStoreTexture

TMaterialParameterStorageTexture<IsRenderProxy> GetParamLoadStoreTexture(const String &name) const

Returns a handle that allows you to assign a load-store texture GPU parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamBuffer

TMaterialParameterBuffer<IsRenderProxy> GetParamBuffer(const String &name) const

Returns a handle that allows you to assign a buffer GPU parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

GetParamSamplerState

TMaterialParameterSampler<IsRenderProxy> GetParamSamplerState(const String &name) const

Returns a handle that allows you to assign a sampler state GPU parameter.

This handle may be used for more efficiently getting/setting GPU parameter values than calling Material::Get* / Material::Set* methods.

Internal

Methods

GetMaterialParameters

SPtr<MaterialParametersType> GetMaterialParameters() const

Returns an object containg all of material's parameters.

Allows the caller to manipulate the parameters more directly.

Protected

Methods

InitializeVariations

void InitializeVariations()

Initializes the material by using the compatible variations from the currently set shader.

Shader must contain the variations that matches the current renderer and GPU backend.

InitializeDefaultParameters

void InitializeDefaultParameters()

Assigns all the default parameters specified in the shader to the material.

ReportIfNotInitialized

void ReportIfNotInitialized() const

Reports an error if no shader is set, or no acceptable variation was found.

Fields

mShader

ShaderType mShader

mParameters

SPtr<MaterialParametersType> mParameters

mVariations

Vector<SPtr<VariationType>> mVariations

mVariationParameters

ShaderVariationParameters mVariationParameters