Class MaterialGenerator
Common base class for implementations of IMaterialGenerator
Inherited Members
Namespace: GLTFast.Materials
Syntax
public abstract class MaterialGenerator : IMaterialGenerator
Fields
AlphaCutoffProperty
Shader property ID for property alphaCutoff
Declaration
public static readonly int AlphaCutoffProperty
Field Value
Type | Description |
---|---|
Int32 |
AlphaTestOnKeyword
Shader keyword _ALPHATEST_ON
Declaration
public const string AlphaTestOnKeyword = "_ALPHATEST_ON"
Field Value
Type | Description |
---|---|
String |
BaseColorProperty
Shader property ID for property baseColorFactor
Declaration
public static readonly int BaseColorProperty
Field Value
Type | Description |
---|---|
Int32 |
BaseColorTextureProperty
Shader property ID for property baseColorTexture
Declaration
public static readonly int BaseColorTextureProperty
Field Value
Type | Description |
---|---|
Int32 |
BaseColorTextureRotationProperty
Shader property ID for property baseColorTexture_Rotation
Declaration
public static readonly int BaseColorTextureRotationProperty
Field Value
Type | Description |
---|---|
Int32 |
BaseColorTextureScaleTransformProperty
Shader property ID for property baseColorTexture_ST
Declaration
public static readonly int BaseColorTextureScaleTransformProperty
Field Value
Type | Description |
---|---|
Int32 |
BaseColorTextureTexCoordProperty
Shader property ID for property baseColorTexture_texCoord
Declaration
public static readonly int BaseColorTextureTexCoordProperty
Field Value
Type | Description |
---|---|
Int32 |
CullModeProperty
Shader property ID for property _CullMode
Declaration
public static readonly int CullModeProperty
Field Value
Type | Description |
---|---|
Int32 |
CullProperty
Shader property ID for property _Cull
Declaration
public static readonly int CullProperty
Field Value
Type | Description |
---|---|
Int32 |
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
public static readonly int DiffuseFactorProperty
Field Value
Type | Description |
---|---|
Int32 |
DiffuseTextureProperty
Shader property ID for property diffuseTexture
Declaration
public static readonly int DiffuseTextureProperty
Field Value
Type | Description |
---|---|
Int32 |
DiffuseTextureRotationProperty
Shader property ID for property diffuseTexture_Rotation
Declaration
public static readonly int DiffuseTextureRotationProperty
Field Value
Type | Description |
---|---|
Int32 |
DiffuseTextureScaleTransformProperty
Shader property ID for property diffuseTexture_ST
Declaration
public static readonly int DiffuseTextureScaleTransformProperty
Field Value
Type | Description |
---|---|
Int32 |
DiffuseTextureTexCoordProperty
Shader property ID for property diffuseTexture_texCoord
Declaration
public static readonly int DiffuseTextureTexCoordProperty
Field Value
Type | Description |
---|---|
Int32 |
DstBlendProperty
Shader property ID for property _DstBlend
Declaration
public static readonly int DstBlendProperty
Field Value
Type | Description |
---|---|
Int32 |
EmissiveFactorProperty
Shader property ID for property emissiveFactor
Declaration
public static readonly int EmissiveFactorProperty
Field Value
Type | Description |
---|---|
Int32 |
EmissiveTextureProperty
Shader property ID for property emissiveTexture
Declaration
public static readonly int EmissiveTextureProperty
Field Value
Type | Description |
---|---|
Int32 |
EmissiveTextureRotationProperty
Shader property ID for property emissiveTexture_Rotation
Declaration
public static readonly int EmissiveTextureRotationProperty
Field Value
Type | Description |
---|---|
Int32 |
EmissiveTextureScaleTransformProperty
Shader property ID for property emissiveTexture_ST
Declaration
public static readonly int EmissiveTextureScaleTransformProperty
Field Value
Type | Description |
---|---|
Int32 |
EmissiveTextureTexCoordProperty
Shader property ID for property emissiveTexture_texCoord
Declaration
public static readonly int EmissiveTextureTexCoordProperty
Field Value
Type | Description |
---|---|
Int32 |
FadeRenderType
Render type Fade value
Declaration
public const string FadeRenderType = "Fade"
Field Value
Type | Description |
---|---|
String |
GlossinessFactorProperty
Shader property ID for property glossinessFactor
Declaration
public static readonly int GlossinessFactorProperty
Field Value
Type | Description |
---|---|
Int32 |
MetallicProperty
Shader property ID for property metallicFactor
Declaration
public static readonly int MetallicProperty
Field Value
Type | Description |
---|---|
Int32 |
MetallicRoughnessMapProperty
Shader property ID for property metallicRoughnessTexture
Declaration
public static readonly int MetallicRoughnessMapProperty
Field Value
Type | Description |
---|---|
Int32 |
MetallicRoughnessMapRotationProperty
Shader property ID for property metallicRoughnessTexture_Rotation
Declaration
public static readonly int MetallicRoughnessMapRotationProperty
Field Value
Type | Description |
---|---|
Int32 |
MetallicRoughnessMapScaleTransformProperty
Shader property ID for property metallicRoughnessTexture_ST
Declaration
public static readonly int MetallicRoughnessMapScaleTransformProperty
Field Value
Type | Description |
---|---|
Int32 |
MetallicRoughnessMapUVChannelProperty
Shader property ID for property metallicRoughnessTexture_texCoord
Declaration
public static readonly int MetallicRoughnessMapUVChannelProperty
Field Value
Type | Description |
---|---|
Int32 |
NormalTextureProperty
Shader property ID for property normalTexture
Declaration
public static readonly int NormalTextureProperty
Field Value
Type | Description |
---|---|
Int32 |
NormalTextureRotationProperty
Shader property ID for property normalTexture_Rotation
Declaration
public static readonly int NormalTextureRotationProperty
Field Value
Type | Description |
---|---|
Int32 |
NormalTextureScaleProperty
Shader property ID for property normalTexture_scale
Declaration
public static readonly int NormalTextureScaleProperty
Field Value
Type | Description |
---|---|
Int32 |
NormalTextureScaleTransformProperty
Shader property ID for property normalTexture_ST
Declaration
public static readonly int NormalTextureScaleTransformProperty
Field Value
Type | Description |
---|---|
Int32 |
NormalTextureTexCoordProperty
Shader property ID for property normalTexture_texCoord
Declaration
public static readonly int NormalTextureTexCoordProperty
Field Value
Type | Description |
---|---|
Int32 |
OcclusionTextureProperty
Shader property ID for property occlusionTexture
Declaration
public static readonly int OcclusionTextureProperty
Field Value
Type | Description |
---|---|
Int32 |
OcclusionTextureRotationProperty
Shader property ID for property occlusionTexture_Rotation
Declaration
public static readonly int OcclusionTextureRotationProperty
Field Value
Type | Description |
---|---|
Int32 |
OcclusionTextureScaleTransformProperty
Shader property ID for property occlusionTexture_ST
Declaration
public static readonly int OcclusionTextureScaleTransformProperty
Field Value
Type | Description |
---|---|
Int32 |
OcclusionTextureStrengthProperty
Shader property ID for property occlusionTexture_strength
Declaration
public static readonly int OcclusionTextureStrengthProperty
Field Value
Type | Description |
---|---|
Int32 |
OcclusionTextureTexCoordProperty
Shader property ID for property occlusionTexture_texCoord
Declaration
public static readonly int OcclusionTextureTexCoordProperty
Field Value
Type | Description |
---|---|
Int32 |
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
public static readonly int RoughnessFactorProperty
Field Value
Type | Description |
---|---|
Int32 |
SpecularFactorProperty
Shader property ID for property specularFactor
Declaration
public static readonly int SpecularFactorProperty
Field Value
Type | Description |
---|---|
Int32 |
SpecularGlossinessTextureProperty
Shader property ID for property specularGlossinessTexture
Declaration
public static readonly int SpecularGlossinessTextureProperty
Field Value
Type | Description |
---|---|
Int32 |
SpecularGlossinessTextureRotationProperty
Shader property ID for property specularGlossinessTexture_Rotation
Declaration
public static readonly int SpecularGlossinessTextureRotationProperty
Field Value
Type | Description |
---|---|
Int32 |
SpecularGlossinessTextureScaleTransformProperty
Shader property ID for property specularGlossinessTexture_ST
Declaration
public static readonly int SpecularGlossinessTextureScaleTransformProperty
Field Value
Type | Description |
---|---|
Int32 |
SpecularGlossinessTextureTexCoordProperty
Shader property ID for property specularGlossinessTexture_texCoord
Declaration
public static readonly int SpecularGlossinessTextureTexCoordProperty
Field Value
Type | Description |
---|---|
Int32 |
SrcBlendProperty
Shader property ID for property _SrcBlend
Declaration
public static readonly int SrcBlendProperty
Field Value
Type | Description |
---|---|
Int32 |
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
public static readonly int ZWriteProperty
Field Value
Type | Description |
---|---|
Int32 |
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(Boolean)
Creates a fallback material to be assigned to nodes without a material.
Declaration
protected abstract Material GenerateDefaultMaterial(bool pointsSupport = false)
Parameters
Type | Name | Description |
---|---|---|
Boolean | pointsSupport | If true, material has to support meshes with points topology Points |
Returns
Type | Description |
---|---|
Material | fallback material |
GenerateMaterial(Material, IGltfReadable, Boolean)
Converts a glTF material into a Unity Material.
Declaration
public abstract Material GenerateMaterial(Material gltfMaterial, IGltfReadable gltf, bool pointsSupport = false)
Parameters
Type | Name | Description |
---|---|---|
Material | gltfMaterial | Source glTF material |
IGltfReadable | gltf | Interface to a loaded glTF's resources (e.g. textures) |
Boolean | pointsSupport | If true, material has to support meshes with points topology Points |
Returns
Type | Description |
---|---|
Material | Generated Unity Material |
Implements
GetDefaultMaterial(Boolean)
Get fallback material that is assigned to nodes without a material.
Declaration
public Material GetDefaultMaterial(bool pointsSupport = false)
Parameters
Type | Name | Description |
---|---|---|
Boolean | pointsSupport | If true, material has to support meshes with points topology Points |
Returns
Type | Description |
---|---|
Material | fallback material |
Implements
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 |
---|---|
Exception |
SetLogger(ICodeLogger)
Is called prior to GenerateMaterial(Material, IGltfReadable, Boolean). The logger should 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 |
Implements
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 |
---|---|
Boolean | True when the transmission can be approximated with Premultiply mode. False if blending is better |
TrySetTexture(TextureInfo, Material, IGltfReadable, Int32, Int32, Int32, Int32)
Attempts assigning a glTF texture to a Unity material.
Declaration
protected bool TrySetTexture(TextureInfo textureInfo, Material material, IGltfReadable gltf, int texturePropertyId, int scaleTransformPropertyId = -1, int rotationPropertyId = -1, int uvChannelPropertyId = -1)
Parameters
Type | Name | Description |
---|---|---|
TextureInfo | textureInfo | glTF source texture |
Material | material | target material |
IGltfReadable | gltf | Context glTF |
Int32 | texturePropertyId | Target texture property |
Int32 | scaleTransformPropertyId | Scale/transform (_ST) property |
Int32 | rotationPropertyId | Rotation property |
Int32 | uvChannelPropertyId | UV channel selection property |
Returns
Type | Description |
---|---|
Boolean | True if texture assignment was successful, false otherwise. |