Class MaterialGenerator
Common base class for implementations of IMaterialGenerator
Implements
Inherited Members
Namespace: GLTFast.Materials
Assembly: glTFast.dll
Syntax
public abstract class MaterialGenerator : IMaterialGenerator
Fields
AlphaCutoffProperty
Shader property ID for property alphaCutoff
Declaration
[Obsolete("Use MaterialProperty.AlphaCutoff instead.")]
public static readonly int AlphaCutoffProperty
Field Value
Type | Description |
---|---|
int |
AlphaTestOnKeyword
Shader keyword _ALPHATEST_ON
Declaration
public const string AlphaTestOnKeyword = "_ALPHATEST_ON"
Field Value
Type | Description |
---|---|
string |
BaseColorProperty
Shader property ID for property baseColorTexture
Declaration
[Obsolete("Use MaterialProperty.BaseColor instead.")]
public static readonly int BaseColorProperty
Field Value
Type | Description |
---|---|
int |
BaseColorTextureProperty
Shader property ID for property baseColorTexture
Declaration
[Obsolete("Use MaterialProperty.BaseColorTexture instead.")]
public static readonly int BaseColorTextureProperty
Field Value
Type | Description |
---|---|
int |
BaseColorTextureRotationProperty
Shader property ID for property baseColorTexture_Rotation
Declaration
[Obsolete("Use MaterialProperty.BaseColorTextureRotation instead.")]
public static readonly int BaseColorTextureRotationProperty
Field Value
Type | Description |
---|---|
int |
BaseColorTextureScaleTransformProperty
Shader property ID for property baseColorTexture_ST
Declaration
[Obsolete("Use MaterialProperty.BaseColorTextureScaleTransform instead.")]
public static readonly int BaseColorTextureScaleTransformProperty
Field Value
Type | Description |
---|---|
int |
BaseColorTextureTexCoordProperty
Shader property ID for property baseColorTexture_texCoord
Declaration
[Obsolete("Use MaterialProperty.BaseColorTextureTexCoord instead.")]
public static readonly int BaseColorTextureTexCoordProperty
Field Value
Type | Description |
---|---|
int |
CullModeProperty
Shader property ID for property _CullMode
Declaration
[Obsolete("Use MaterialProperty.CullMode instead.")]
public static readonly int CullModeProperty
Field Value
Type | Description |
---|---|
int |
CullProperty
Shader property ID for property _Cull
Declaration
[Obsolete("Use MaterialProperty.Cull instead.")]
public static readonly int CullProperty
Field Value
Type | Description |
---|---|
int |
DefaultMaterialName
When a glTF mesh(primitive) has no material assigned, a default material, has to get created and assigned. This default material should get named after this field's value to ensure future round-trip workflows are functioning.
Declaration
public const string DefaultMaterialName = "glTF-Default-Material"
Field Value
Type | Description |
---|---|
string |
DiffuseFactorProperty
Shader property ID for property diffuseFactor
Declaration
[Obsolete("Use MaterialProperty.DiffuseFactor instead.")]
public static readonly int DiffuseFactorProperty
Field Value
Type | Description |
---|---|
int |
DiffuseTextureProperty
Shader property ID for property diffuseTexture
Declaration
[Obsolete("Use MaterialProperty.DiffuseTexture instead.")]
public static readonly int DiffuseTextureProperty
Field Value
Type | Description |
---|---|
int |
DiffuseTextureRotationProperty
Shader property ID for property diffuseTexture_Rotation
Declaration
[Obsolete("Use MaterialProperty.DiffuseTextureRotation instead.")]
public static readonly int DiffuseTextureRotationProperty
Field Value
Type | Description |
---|---|
int |
DiffuseTextureScaleTransformProperty
Shader property ID for property diffuseTexture_ST
Declaration
[Obsolete("Use MaterialProperty.DiffuseTextureScaleTransform instead.")]
public static readonly int DiffuseTextureScaleTransformProperty
Field Value
Type | Description |
---|---|
int |
DiffuseTextureTexCoordProperty
Shader property ID for property diffuseTexture_texCoord
Declaration
[Obsolete("Use MaterialProperty.DiffuseTextureTexCoord instead.")]
public static readonly int DiffuseTextureTexCoordProperty
Field Value
Type | Description |
---|---|
int |
DstBlendProperty
Shader property ID for property _DstBlend
Declaration
[Obsolete("Use MaterialProperty.DstBlend instead.")]
public static readonly int DstBlendProperty
Field Value
Type | Description |
---|---|
int |
EmissiveFactorProperty
Shader property ID for property emissiveFactor
Declaration
[Obsolete("Use MaterialProperty.EmissiveFactor instead.")]
public static readonly int EmissiveFactorProperty
Field Value
Type | Description |
---|---|
int |
EmissiveTextureProperty
Shader property ID for property emissiveTexture
Declaration
[Obsolete("Use MaterialProperty.EmissiveTexture instead.")]
public static readonly int EmissiveTextureProperty
Field Value
Type | Description |
---|---|
int |
EmissiveTextureRotationProperty
Shader property ID for property emissiveTexture_Rotation
Declaration
[Obsolete("Use MaterialProperty.EmissiveTextureRotation instead.")]
public static readonly int EmissiveTextureRotationProperty
Field Value
Type | Description |
---|---|
int |
EmissiveTextureScaleTransformProperty
Shader property ID for property emissiveTexture_ST
Declaration
[Obsolete("Use MaterialProperty.EmissiveTextureScaleTransform instead.")]
public static readonly int EmissiveTextureScaleTransformProperty
Field Value
Type | Description |
---|---|
int |
EmissiveTextureTexCoordProperty
Shader property ID for property emissiveTexture_texCoord
Declaration
[Obsolete("Use MaterialProperty.EmissiveTextureTexCoord instead.")]
public static readonly int EmissiveTextureTexCoordProperty
Field Value
Type | Description |
---|---|
int |
FadeRenderType
Render type Fade value
Declaration
public const string FadeRenderType = "Fade"
Field Value
Type | Description |
---|---|
string |
GlossinessFactorProperty
Shader property ID for property glossinessFactor
Declaration
[Obsolete("Use MaterialProperty.GlossinessFactor instead.")]
public static readonly int GlossinessFactorProperty
Field Value
Type | Description |
---|---|
int |
MetallicProperty
Shader property ID for property metallicFactor
Declaration
[Obsolete("Use MaterialProperty.Metallic instead.")]
public static readonly int MetallicProperty
Field Value
Type | Description |
---|---|
int |
MetallicRoughnessMapProperty
Shader property ID for property metallicRoughnessTexture
Declaration
[Obsolete("Use MaterialProperty.MetallicRoughnessMap instead.")]
public static readonly int MetallicRoughnessMapProperty
Field Value
Type | Description |
---|---|
int |
MetallicRoughnessMapRotationProperty
Shader property ID for property metallicRoughnessTexture_Rotation
Declaration
[Obsolete("Use MaterialProperty.MetallicRoughnessMapRotation instead.")]
public static readonly int MetallicRoughnessMapRotationProperty
Field Value
Type | Description |
---|---|
int |
MetallicRoughnessMapScaleTransformProperty
Shader property ID for property metallicRoughnessTexture_ST
Declaration
[Obsolete("Use MaterialProperty.MetallicRoughnessMapScaleTransform instead.")]
public static readonly int MetallicRoughnessMapScaleTransformProperty
Field Value
Type | Description |
---|---|
int |
MetallicRoughnessMapUVChannelProperty
Shader property ID for property metallicRoughnessTexture_texCoord
Declaration
[Obsolete("Use MaterialProperty.MetallicRoughnessMapTexCoord instead.")]
public static readonly int MetallicRoughnessMapUVChannelProperty
Field Value
Type | Description |
---|---|
int |
NormalTextureProperty
Shader property ID for property normalTexture
Declaration
[Obsolete("Use MaterialProperty.NormalTexture instead.")]
public static readonly int NormalTextureProperty
Field Value
Type | Description |
---|---|
int |
NormalTextureRotationProperty
Shader property ID for property normalTexture_Rotation
Declaration
[Obsolete("Use MaterialProperty.NormalTextureRotation instead.")]
public static readonly int NormalTextureRotationProperty
Field Value
Type | Description |
---|---|
int |
NormalTextureScaleProperty
Shader property ID for property normalTexture_scale
Declaration
[Obsolete("Use MaterialProperty.NormalTextureScale instead.")]
public static readonly int NormalTextureScaleProperty
Field Value
Type | Description |
---|---|
int |
NormalTextureScaleTransformProperty
Shader property ID for property normalTexture_ST
Declaration
[Obsolete("Use MaterialProperty.NormalTextureScaleTransform instead.")]
public static readonly int NormalTextureScaleTransformProperty
Field Value
Type | Description |
---|---|
int |
NormalTextureTexCoordProperty
Shader property ID for property normalTexture_texCoord
Declaration
[Obsolete("Use MaterialProperty.NormalTextureTexCoord instead.")]
public static readonly int NormalTextureTexCoordProperty
Field Value
Type | Description |
---|---|
int |
OcclusionTextureProperty
Shader property ID for property occlusionTexture
Declaration
[Obsolete("Use MaterialProperty.OcclusionTexture instead.")]
public static readonly int OcclusionTextureProperty
Field Value
Type | Description |
---|---|
int |
OcclusionTextureRotationProperty
Shader property ID for property occlusionTexture_Rotation
Declaration
[Obsolete("Use MaterialProperty.OcclusionTextureRotation instead.")]
public static readonly int OcclusionTextureRotationProperty
Field Value
Type | Description |
---|---|
int |
OcclusionTextureScaleTransformProperty
Shader property ID for property occlusionTexture_ST
Declaration
[Obsolete("Use MaterialProperty.OcclusionTextureScaleTransform instead.")]
public static readonly int OcclusionTextureScaleTransformProperty
Field Value
Type | Description |
---|---|
int |
OcclusionTextureStrengthProperty
Shader property ID for property occlusionTexture_strength
Declaration
[Obsolete("Use MaterialProperty.OcclusionTextureStrength instead.")]
public static readonly int OcclusionTextureStrengthProperty
Field Value
Type | Description |
---|---|
int |
OcclusionTextureTexCoordProperty
Shader property ID for property occlusionTexture_texCoord
Declaration
[Obsolete("Use MaterialProperty.OcclusionTextureTexCoord instead.")]
public static readonly int OcclusionTextureTexCoordProperty
Field Value
Type | Description |
---|---|
int |
OpaqueRenderType
Render type Opaque value
Declaration
public const string OpaqueRenderType = "Opaque"
Field Value
Type | Description |
---|---|
string |
RenderTypeTag
Render type key
Declaration
public const string RenderTypeTag = "RenderType"
Field Value
Type | Description |
---|---|
string |
RoughnessFactorProperty
Shader property ID for property roughnessFactor
Declaration
[Obsolete("Use MaterialProperty.RoughnessFactor instead.")]
public static readonly int RoughnessFactorProperty
Field Value
Type | Description |
---|---|
int |
SpecularFactorProperty
Shader property ID for property specularFactor
Declaration
[Obsolete("Use MaterialProperty.SpecularFactor instead.")]
public static readonly int SpecularFactorProperty
Field Value
Type | Description |
---|---|
int |
SpecularGlossinessTextureProperty
Shader property ID for property specularGlossinessTexture
Declaration
[Obsolete("Use MaterialProperty.SpecularGlossinessTexture instead.")]
public static readonly int SpecularGlossinessTextureProperty
Field Value
Type | Description |
---|---|
int |
SpecularGlossinessTextureRotationProperty
Shader property ID for property specularGlossinessTexture_Rotation
Declaration
[Obsolete("Use MaterialProperty.SpecularGlossinessTextureRotation instead.")]
public static readonly int SpecularGlossinessTextureRotationProperty
Field Value
Type | Description |
---|---|
int |
SpecularGlossinessTextureScaleTransformProperty
Shader property ID for property specularGlossinessTexture_ST
Declaration
[Obsolete("Use MaterialProperty.SpecularGlossinessTextureScaleTransform instead.")]
public static readonly int SpecularGlossinessTextureScaleTransformProperty
Field Value
Type | Description |
---|---|
int |
SpecularGlossinessTextureTexCoordProperty
Shader property ID for property specularGlossinessTexture_texCoord
Declaration
[Obsolete("Use MaterialProperty.SpecularGlossinessTextureTexCoord instead.")]
public static readonly int SpecularGlossinessTextureTexCoordProperty
Field Value
Type | Description |
---|---|
int |
SrcBlendProperty
Shader property ID for property _SrcBlend
Declaration
[Obsolete("Use MaterialProperty.SrcBlend instead.")]
public static readonly int SrcBlendProperty
Field Value
Type | Description |
---|---|
int |
TextureTransformKeyword
Shader keyword _TEXTURE_TRANSFORM
Declaration
public const string TextureTransformKeyword = "_TEXTURE_TRANSFORM"
Field Value
Type | Description |
---|---|
string |
TransparentCutoutRenderType
Render type TransparentCutout value
Declaration
public const string TransparentCutoutRenderType = "TransparentCutout"
Field Value
Type | Description |
---|---|
string |
TransparentRenderType
Render type Transparent value
Declaration
public const string TransparentRenderType = "Transparent"
Field Value
Type | Description |
---|---|
string |
UVChannelSelectKeyword
Shader keyword _UV_CHANNEL_SELECT
Declaration
public const string UVChannelSelectKeyword = "_UV_CHANNEL_SELECT"
Field Value
Type | Description |
---|---|
string |
ZWriteProperty
Shader property ID for property _ZWrite
Declaration
[Obsolete("Use MaterialProperty.ZWrite instead.")]
public static readonly int ZWriteProperty
Field Value
Type | Description |
---|---|
int |
Properties
Logger
Logger to be used for messaging. Can be null!
Declaration
protected ICodeLogger Logger { get; }
Property Value
Type | Description |
---|---|
ICodeLogger |
Methods
FindShader(string, ICodeLogger)
Tries to load a shader and covers error handling.
Declaration
protected static Shader FindShader(string shaderName, ICodeLogger logger)
Parameters
Type | Name | Description |
---|---|---|
string | shaderName | The requested shader's name. |
ICodeLogger | logger | Logger used for reporting errors. |
Returns
Type | Description |
---|---|
Shader | Requested shader or null if it couldn't be loaded. |
GenerateDefaultMaterial(bool)
Creates a fallback material to be assigned to nodes without a material.
Declaration
protected abstract Material GenerateDefaultMaterial(bool pointsSupport = false)
Parameters
Type | Name | Description |
---|---|---|
bool | pointsSupport | If true, material has to support meshes with points topology |
Returns
Type | Description |
---|---|
Material | fallback material |
GenerateMaterial(MaterialBase, IGltfReadable, bool)
Converts a glTF material into a Unity Material. gltfMaterial might reference textures, which can be queried from gltf.
Declaration
public abstract Material GenerateMaterial(MaterialBase gltfMaterial, IGltfReadable gltf, bool pointsSupport = false)
Parameters
Type | Name | Description |
---|---|---|
MaterialBase | gltfMaterial | Source glTF material |
IGltfReadable | gltf | Interface to a loaded glTF's resources (e.g. textures) |
bool | pointsSupport | If true, material has to support meshes with points topology. |
Returns
Type | Description |
---|---|
Material | Generated Unity Material |
GetDefaultMaterial(bool)
Get fallback material that is assigned to nodes without a material.
Declaration
public Material GetDefaultMaterial(bool pointsSupport = false)
Parameters
Type | Name | Description |
---|---|---|
bool | pointsSupport | If true, material has to support meshes with points topology. |
Returns
Type | Description |
---|---|
Material | fallback material |
GetDefaultMaterialGenerator()
Provides the default material generator that's being used if no custom material generator was provided. The result depends on the currently used render pipeline.
Declaration
public static IMaterialGenerator GetDefaultMaterialGenerator()
Returns
Type | Description |
---|---|
IMaterialGenerator | The default material generator |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Is thrown when the default material generator couldn't be determined based on the current render pipeline. |
SetLogger(ICodeLogger)
Has to be called prior to GenerateMaterial(MaterialBase, IGltfReadable, bool). The logger can be used to inform users about incidents of arbitrary severity (error,warning or info) during material generation.
Declaration
public void SetLogger(ICodeLogger logger)
Parameters
Type | Name | Description |
---|---|---|
ICodeLogger | logger | Logger to be used. |
TransmissionWorkaroundShaderMode(Transmission, ref Color)
Approximates Transmission material effect for Render Pipelines / Shaders where filtering the backbuffer is not possible.
Declaration
protected static bool TransmissionWorkaroundShaderMode(Transmission transmission, ref Color baseColorLinear)
Parameters
Type | Name | Description |
---|---|---|
Transmission | transmission | glTF transmission extension data |
Color | baseColorLinear | BaseColor reference. Alpha will be altered according to transmission |
Returns
Type | Description |
---|---|
bool | True when the transmission can be approximated with Premultiply mode. False if blending is better |
TrySetTexture(TextureInfoBase, Material, IGltfReadable, int, int, int, int)
Attempts assigning a glTF texture to a Unity material.
Declaration
protected bool TrySetTexture(TextureInfoBase textureInfo, Material material, IGltfReadable gltf, int texturePropertyId, int scaleTransformPropertyId = -1, int rotationPropertyId = -1, int uvChannelPropertyId = -1)
Parameters
Type | Name | Description |
---|---|---|
TextureInfoBase | textureInfo | glTF source texture |
Material | material | target material |
IGltfReadable | gltf | Context glTF |
int | texturePropertyId | Target texture property |
int | scaleTransformPropertyId | Scale/transform (_ST) property |
int | rotationPropertyId | Rotation property |
int | uvChannelPropertyId | UV channel selection property |
Returns
Type | Description |
---|---|
bool | True if texture assignment was successful, false otherwise. |