Ejemplo n.º 1
0
        public override Material GenerateMaterial(
            Schema.Material gltfMaterial,
            ref Schema.Texture[] textures,
            ref Schema.Image[] schemaImages,
            ref Dictionary <int, Texture2D>[] imageVariants
            )
        {
            Material material;

            MaterialType?materialType = null;
            ShaderMode   shaderMode   = ShaderMode.Opaque;

            if (gltfMaterial.extensions?.KHR_materials_unlit != null)
            {
                material     = GetUnlitMaterial(gltfMaterial);
                materialType = MaterialType.Unlit;
                shaderMode   = gltfMaterial.alphaModeEnum != AlphaMode.OPAQUE ? ShaderMode.Blend : ShaderMode.Opaque;
            }
            else
            {
                bool isMetallicRoughness = gltfMaterial.extensions?.KHR_materials_pbrSpecularGlossiness == null;
                if (isMetallicRoughness)
                {
                    materialType = MaterialType.MetallicRoughness;
                    var metallicShaderFeatures = GetMetallicShaderFeatures(gltfMaterial);
                    material   = GetMetallicMaterial(metallicShaderFeatures);
                    shaderMode = (ShaderMode)(metallicShaderFeatures & MetallicShaderFeatures.ModeMask);
                }
                else
                {
                    materialType = MaterialType.SpecularGlossiness;
                    var specularShaderFeatures = GetSpecularShaderFeatures(gltfMaterial);
                    material = GetSpecularMaterial(specularShaderFeatures);
                    if ((specularShaderFeatures & SpecularShaderFeatures.AlphaBlend) != 0)
                    {
                        shaderMode = ShaderMode.Blend;
                    }
                }
            }

            if (material == null)
            {
                return(null);
            }

            material.name = gltfMaterial.name;

            Color       baseColorLinear = Color.white;
            RenderQueue?renderQueue     = null;

            //added support for KHR_materials_pbrSpecularGlossiness
            if (gltfMaterial.extensions != null)
            {
                Schema.PbrSpecularGlossiness specGloss = gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness;
                if (specGloss != null)
                {
                    baseColorLinear = specGloss.diffuseColor;
                    material.SetVector(specColorPropId, specGloss.specularColor);
                    material.SetFloat(smoothnessPropId, specGloss.glossinessFactor);

                    TrySetTexture(specGloss.diffuseTexture, material, baseMapPropId, ref textures, ref schemaImages, ref imageVariants);

                    if (TrySetTexture(specGloss.specularGlossinessTexture, material, specGlossMapPropId, ref textures, ref schemaImages, ref imageVariants))
                    {
                        // material.EnableKeyword();
                    }
                }
            }

            if (gltfMaterial.pbrMetallicRoughness != null)
            {
                baseColorLinear = gltfMaterial.pbrMetallicRoughness.baseColor;

                if (materialType != MaterialType.SpecularGlossiness)
                {
                    // baseColorTexture can be used by both MetallicRoughness AND Unlit materials
                    TrySetTexture(
                        gltfMaterial.pbrMetallicRoughness.baseColorTexture,
                        material,
                        baseMapPropId,
                        ref textures,
                        ref schemaImages,
                        ref imageVariants
                        );
                }

                if (materialType == MaterialType.MetallicRoughness)
                {
                    material.SetFloat(metallicPropId, gltfMaterial.pbrMetallicRoughness.metallicFactor);
                    material.SetFloat(smoothnessPropId, 1 - gltfMaterial.pbrMetallicRoughness.roughnessFactor);

                    if (TrySetTexture(gltfMaterial.pbrMetallicRoughness.metallicRoughnessTexture, material, metallicRoughnessTexturePropId, ref textures, ref schemaImages, ref imageVariants))
                    {
                        // material.EnableKeyword(KW_METALLIC_ROUGHNESS_MAP);
                    }

                    // TODO: When the occlusionTexture equals the metallicRoughnessTexture, we could sample just once instead of twice.
                    // if (!DifferentIndex(gltfMaterial.occlusionTexture,gltfMaterial.pbrMetallicRoughness.metallicRoughnessTexture)) {
                    //    ...
                    // }
                }
            }

            if (TrySetTexture(gltfMaterial.normalTexture, material, bumpMapPropId, ref textures, ref schemaImages, ref imageVariants))
            {
                // material.EnableKeyword(KW_NORMALMAP);
                material.SetFloat(bumpScalePropId, gltfMaterial.normalTexture.scale);
            }

            if (TrySetTexture(gltfMaterial.occlusionTexture, material, occlusionMapPropId, ref textures, ref schemaImages, ref imageVariants))
            {
                material.EnableKeyword(KW_OCCLUSION);
                material.SetFloat(occlusionStrengthPropId, gltfMaterial.occlusionTexture.strength);
            }

            if (TrySetTexture(gltfMaterial.emissiveTexture, material, emissionMapPropId, ref textures, ref schemaImages, ref imageVariants))
            {
                material.EnableKeyword(KW_EMISSION);
            }

            if (gltfMaterial.extensions != null)
            {
                // Transmission - Approximation
                var transmission = gltfMaterial.extensions.KHR_materials_transmission;
                if (transmission != null)
                {
                    renderQueue = ApplyTransmission(ref baseColorLinear, ref textures, ref schemaImages, ref imageVariants, transmission, material, renderQueue);
                }
            }

            if (gltfMaterial.alphaModeEnum == AlphaMode.MASK)
            {
                material.SetFloat(cutoffPropId, gltfMaterial.alphaCutoff);
            }
            else
            {
                material.SetFloat(cutoffPropId, 0);
                // double sided opaque would make errors in HDRP 7.3 otherwise
                material.SetOverrideTag("MotionVector", "User");
                material.SetShaderPassEnabled("MOTIONVECTORS", false);
            }
            if (!renderQueue.HasValue)
            {
                if (shaderMode == ShaderMode.Opaque)
                {
                    renderQueue = gltfMaterial.alphaModeEnum == AlphaMode.MASK
                        ? RenderQueue.AlphaTest
                        : RenderQueue.Geometry;
                }
                else
                {
                    renderQueue = RenderQueue.Transparent;
                }
            }

            material.renderQueue = (int)renderQueue.Value;

            material.SetVector(baseColorPropId, baseColorLinear);

            if (gltfMaterial.emissive != Color.black)
            {
                material.SetColor(emissionColorPropId, gltfMaterial.emissive);
                material.EnableKeyword(KW_EMISSION);
            }

            return(material);
        }
Ejemplo n.º 2
0
        public override Material GenerateMaterial(Schema.Material gltfMaterial, IGltfReadable gltf)
        {
            Material material;

            MaterialType?materialType = null;
            ShaderMode   shaderMode   = ShaderMode.Opaque;

            if (gltfMaterial.extensions?.KHR_materials_unlit != null)
            {
                material     = GetUnlitMaterial(gltfMaterial);
                materialType = MaterialType.Unlit;
                shaderMode   = gltfMaterial.alphaModeEnum == AlphaMode.BLEND ? ShaderMode.Blend : ShaderMode.Opaque;
            }
            else
            {
                bool isMetallicRoughness = gltfMaterial.extensions?.KHR_materials_pbrSpecularGlossiness == null;
                if (isMetallicRoughness)
                {
                    materialType = MaterialType.MetallicRoughness;
                    var metallicShaderFeatures = GetMetallicShaderFeatures(gltfMaterial);
                    material   = GetMetallicMaterial(metallicShaderFeatures);
                    shaderMode = (ShaderMode)(metallicShaderFeatures & MetallicShaderFeatures.ModeMask);
                }
                else
                {
                    materialType = MaterialType.SpecularGlossiness;
                    var specularShaderFeatures = GetSpecularShaderFeatures(gltfMaterial);
                    material = GetSpecularMaterial(specularShaderFeatures);
                    if ((specularShaderFeatures & SpecularShaderFeatures.AlphaBlend) != 0)
                    {
                        shaderMode = ShaderMode.Blend;
                    }
                }
            }

            if (material == null)
            {
                return(null);
            }

            material.name = gltfMaterial.name;

            Color       baseColorLinear = Color.white;
            RenderQueue?renderQueue     = null;

            //added support for KHR_materials_pbrSpecularGlossiness
            if (gltfMaterial.extensions != null)
            {
                Schema.PbrSpecularGlossiness specGloss = gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness;
                if (specGloss != null)
                {
                    baseColorLinear = specGloss.diffuseColor;
#if UNITY_SHADER_GRAPH_12_OR_NEWER
                    material.SetVector(specularFactorPropId, specGloss.specularColor);
#else
                    material.SetVector(specColorPropId, specGloss.specularColor);
#endif
                    material.SetFloat(smoothnessPropId, specGloss.glossinessFactor);

                    TrySetTexture(
                        specGloss.diffuseTexture,
                        material,
                        gltf,
                        baseMapPropId,
                        baseMapScaleTransformPropId,
                        baseMapRotationPropId,
                        baseMapUVChannelPropId
                        );

                    if (TrySetTexture(
                            specGloss.specularGlossinessTexture,
                            material,
                            gltf,
                            specGlossMapPropId,
                            specGlossScaleTransformMapPropId,
                            specGlossMapRotationPropId,
                            specGlossMapUVChannelPropId
                            ))
                    {
                        // material.EnableKeyword();
                    }
                }
            }

            if (gltfMaterial.pbrMetallicRoughness != null
                // If there's a specular-glossiness extension, ignore metallic-roughness
                // (according to extension specification)
                && gltfMaterial.extensions?.KHR_materials_pbrSpecularGlossiness == null)
            {
                baseColorLinear = gltfMaterial.pbrMetallicRoughness.baseColor;

                if (materialType != MaterialType.SpecularGlossiness)
                {
                    // baseColorTexture can be used by both MetallicRoughness AND Unlit materials
                    TrySetTexture(
                        gltfMaterial.pbrMetallicRoughness.baseColorTexture,
                        material,
                        gltf,
                        baseMapPropId,
                        baseMapScaleTransformPropId,
                        baseMapRotationPropId,
                        baseMapUVChannelPropId
                        );
                }

                if (materialType == MaterialType.MetallicRoughness)
                {
                    material.SetFloat(metallicPropId, gltfMaterial.pbrMetallicRoughness.metallicFactor);
                    material.SetFloat(smoothnessPropId, 1 - gltfMaterial.pbrMetallicRoughness.roughnessFactor);

                    if (TrySetTexture(
                            gltfMaterial.pbrMetallicRoughness.metallicRoughnessTexture,
                            material,
                            gltf,
                            metallicRoughnessMapPropId,
                            metallicRoughnessMapScaleTransformPropId,
                            metallicRoughnessMapRotationPropId,
                            metallicRoughnessMapUVChannelPropId
                            ))
                    {
                        // material.EnableKeyword(KW_METALLIC_ROUGHNESS_MAP);
                    }

                    // TODO: When the occlusionTexture equals the metallicRoughnessTexture, we could sample just once instead of twice.
                    // if (!DifferentIndex(gltfMaterial.occlusionTexture,gltfMaterial.pbrMetallicRoughness.metallicRoughnessTexture)) {
                    //    ...
                    // }
                }
            }

            if (TrySetTexture(
                    gltfMaterial.normalTexture,
                    material,
                    gltf,
                    bumpMapPropId,
                    bumpMapScaleTransformPropId,
                    bumpMapRotationPropId,
                    bumpMapUVChannelPropId
                    ))
            {
                // material.EnableKeyword(Constants.kwNormalMap);
                material.SetFloat(bumpScalePropId, gltfMaterial.normalTexture.scale);
            }

            if (TrySetTexture(
                    gltfMaterial.occlusionTexture,
                    material,
                    gltf,
                    occlusionMapPropId,
                    occlusionMapScaleTransformPropId,
                    occlusionMapRotationPropId,
                    occlusionMapUVChannelPropId
                    ))
            {
                material.EnableKeyword(KW_OCCLUSION);
                material.SetFloat(occlusionStrengthPropId, gltfMaterial.occlusionTexture.strength);
            }

            if (TrySetTexture(
                    gltfMaterial.emissiveTexture,
                    material,
                    gltf,
                    emissionMapPropId,
                    emissionMapScaleTransformPropId,
                    emissionMapRotationPropId,
                    emissionMapUVChannelPropId
                    ))
            {
                material.EnableKeyword(KW_EMISSION);
            }

            if (gltfMaterial.extensions != null)
            {
                // Transmission - Approximation
                var transmission = gltfMaterial.extensions.KHR_materials_transmission;
                if (transmission != null)
                {
                    renderQueue = ApplyTransmission(ref baseColorLinear, gltf, transmission, material, renderQueue);
                }
            }

            if (gltfMaterial.alphaModeEnum == AlphaMode.MASK)
            {
                SetAlphaModeMask(gltfMaterial, material);
#if USING_HDRP
                if (gltfMaterial.extensions?.KHR_materials_unlit != null)
                {
                    renderQueue = RenderQueue.Transparent;
                }
                else
#endif
                renderQueue = RenderQueue.AlphaTest;
            }
            else
            {
                material.SetFloat(cutoffPropId, 0);
                // double sided opaque would make errors in HDRP 7.3 otherwise
                material.SetOverrideTag(TAG_MOTION_VECTOR, TAG_MOTION_VECTOR_USER);
                material.SetShaderPassEnabled(k_MotionVectorsPass, false);
            }
            if (!renderQueue.HasValue)
            {
                if (shaderMode == ShaderMode.Opaque)
                {
                    renderQueue = gltfMaterial.alphaModeEnum == AlphaMode.MASK
                        ? RenderQueue.AlphaTest
                        : RenderQueue.Geometry;
                }
                else
                {
                    renderQueue = RenderQueue.Transparent;
                }
            }

            material.renderQueue = (int)renderQueue.Value;

            if (gltfMaterial.doubleSided)
            {
                SetDoubleSided(gltfMaterial, material);
            }

            switch (shaderMode)
            {
            case ShaderMode.Opaque:
                SetShaderModeOpaque(gltfMaterial, material);
                break;

            case ShaderMode.Blend:
                SetShaderModeBlend(gltfMaterial, material);
                break;

            case ShaderMode.Premultiply:
                SetShaderModePremultiply(gltfMaterial, material);
                break;
            }

            material.SetVector(baseColorPropId, baseColorLinear);

            if (gltfMaterial.emissive != Color.black)
            {
                material.SetColor(emissionColorPropId, gltfMaterial.emissive);
                material.EnableKeyword(KW_EMISSION);
            }

            return(material);
        }
Ejemplo n.º 3
0
        public override Material GenerateMaterial(
            Schema.Material gltfMaterial,
            ref Schema.Texture[] textures,
            ref Schema.Image[] schemaImages,
            ref Dictionary <int, Texture2D>[] imageVariants
            )
        {
            Material material;

            if (gltfMaterial.extensions?.KHR_materials_pbrSpecularGlossiness != null)
            {
                material = GetPbrSpecularGlossinessMaterial(gltfMaterial.doubleSided);
            }
            else
            if (gltfMaterial.extensions?.KHR_materials_unlit != null)
            {
                material = GetUnlitMaterial(gltfMaterial.doubleSided);
            }
            else
            {
                material = GetPbrMetallicRoughnessMaterial(gltfMaterial.doubleSided);
            }

            if (material == null)
            {
                return(null);
            }

            material.name = gltfMaterial.name;

            StandardShaderMode shaderMode = StandardShaderMode.Opaque;
            Color baseColorLinear         = Color.white;

            if (gltfMaterial.alphaModeEnum == AlphaMode.MASK)
            {
                material.SetFloat(cutoffPropId, gltfMaterial.alphaCutoff);
                shaderMode = StandardShaderMode.Cutout;
            }
            else if (gltfMaterial.alphaModeEnum == AlphaMode.BLEND)
            {
                SetAlphaModeBlend(material);
                shaderMode = StandardShaderMode.Fade;
            }

            if (gltfMaterial.extensions != null)
            {
                // Specular glossiness
                Schema.PbrSpecularGlossiness specGloss = gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness;
                if (specGloss != null)
                {
                    baseColorLinear = specGloss.diffuseColor;
                    material.SetVector(specColorPropId, specGloss.specularColor);
                    material.SetFloat(glossinessPropId, specGloss.glossinessFactor);

                    TrySetTexture(specGloss.diffuseTexture, material, mainTexPropId, ref textures, ref schemaImages, ref imageVariants);

                    if (TrySetTexture(specGloss.specularGlossinessTexture, material, specGlossMapPropId, ref textures, ref schemaImages, ref imageVariants))
                    {
                        material.EnableKeyword(KW_SPEC_GLOSS_MAP);
                    }
                }
            }

            if (gltfMaterial.pbrMetallicRoughness != null)
            {
                baseColorLinear = gltfMaterial.pbrMetallicRoughness.baseColor;
                material.SetFloat(metallicPropId, gltfMaterial.pbrMetallicRoughness.metallicFactor);
                material.SetFloat(roughnessPropId, gltfMaterial.pbrMetallicRoughness.roughnessFactor);

                TrySetTexture(
                    gltfMaterial.pbrMetallicRoughness.baseColorTexture,
                    material,
                    mainTexPropId,
                    ref textures,
                    ref schemaImages,
                    ref imageVariants
                    );

                if (TrySetTexture(gltfMaterial.pbrMetallicRoughness.metallicRoughnessTexture, material, metallicGlossMapPropId, ref textures, ref schemaImages, ref imageVariants))
                {
                    material.EnableKeyword(KW_METALLIC_ROUGNESS_MAP);
                }
            }

            if (TrySetTexture(gltfMaterial.normalTexture, material, bumpMapPropId, ref textures, ref schemaImages, ref imageVariants))
            {
                material.EnableKeyword(KW_NORMALMAP);
                material.SetFloat(bumpScalePropId, gltfMaterial.normalTexture.scale);
            }

            if (TrySetTexture(gltfMaterial.occlusionTexture, material, occlusionMapPropId, ref textures, ref schemaImages, ref imageVariants))
            {
                material.EnableKeyword(KW_OCCLUSION);
                material.SetFloat(occlusionStrengthPropId, gltfMaterial.occlusionTexture.strength);
            }

            if (TrySetTexture(gltfMaterial.emissiveTexture, material, emissionMapPropId, ref textures, ref schemaImages, ref imageVariants))
            {
                material.EnableKeyword(KW_EMISSION);
            }

            if (gltfMaterial.extensions != null)
            {
                // Transmission - Approximation
                var transmission = gltfMaterial.extensions.KHR_materials_transmission;
                if (transmission != null)
                {
#if UNITY_EDITOR
                    Debug.LogWarning("Chance of incorrect materials! glTF transmission is approximated when using built-in render pipeline!");
#endif
                    // Correct transmission is not supported in Built-In renderer
                    // This is an approximation for some corner cases
                    if (transmission.transmissionFactor > 0f && transmission.transmissionTexture.index < 0)
                    {
                        var premul = TransmissionWorkaroundShaderMode(transmission, ref baseColorLinear);
                        shaderMode = premul ? StandardShaderMode.Transparent : StandardShaderMode.Fade;
                    }
                }
            }

            switch (shaderMode)
            {
            case StandardShaderMode.Cutout:
                SetAlphaModeMask(material, gltfMaterial);
                break;

            case StandardShaderMode.Fade:
                SetAlphaModeBlend(material);
                break;

            case StandardShaderMode.Transparent:
                SetAlphaModeTransparent(material);
                break;

            default:
                SetOpaqueMode(material);
                break;
            }

            material.color = baseColorLinear.gamma;

            if (gltfMaterial.emissive != Color.black)
            {
                material.SetColor(emissionColorPropId, gltfMaterial.emissive.gamma);
                material.EnableKeyword(KW_EMISSION);
            }

            return(material);
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public override Material GenerateMaterial(
            Schema.Material gltfMaterial,
            IGltfReadable gltf
            )
        {
            Material material;

            if (gltfMaterial.extensions?.KHR_materials_pbrSpecularGlossiness != null)
            {
                material = GetPbrSpecularGlossinessMaterial(gltfMaterial.doubleSided);
            }
            else
            if (gltfMaterial.extensions?.KHR_materials_unlit != null)
            {
                material = GetUnlitMaterial(gltfMaterial.doubleSided);
            }
            else
            {
                material = GetPbrMetallicRoughnessMaterial(gltfMaterial.doubleSided);
            }

            if (material == null)
            {
                return(null);
            }

            material.name = gltfMaterial.name;

            StandardShaderMode shaderMode = StandardShaderMode.Opaque;
            Color baseColorLinear         = Color.white;

            if (gltfMaterial.alphaModeEnum == AlphaMode.MASK)
            {
                material.SetFloat(cutoffPropId, gltfMaterial.alphaCutoff);
                shaderMode = StandardShaderMode.Cutout;
            }
            else if (gltfMaterial.alphaModeEnum == AlphaMode.BLEND)
            {
                SetAlphaModeBlend(material);
                shaderMode = StandardShaderMode.Fade;
            }

            if (gltfMaterial.extensions != null)
            {
                // Specular glossiness
                Schema.PbrSpecularGlossiness specGloss = gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness;
                if (specGloss != null)
                {
                    baseColorLinear = specGloss.diffuseColor;
                    material.SetVector(specColorPropId, specGloss.specularColor);
                    material.SetFloat(glossinessPropId, specGloss.glossinessFactor);

                    TrySetTexture(
                        specGloss.diffuseTexture,
                        material,
                        gltf,
                        mainTexPropId,
                        mainTexScaleTransform,
                        mainTexRotation,
                        mainTexUVChannelPropId
                        );

                    if (TrySetTexture(
                            specGloss.specularGlossinessTexture,
                            material,
                            gltf,
                            specGlossMapPropId,
                            specGlossScaleTransformMapPropId,
                            specGlossMapRotationPropId,
                            specGlossMapUVChannelPropId
                            ))
                    {
                        material.EnableKeyword(KW_SPEC_GLOSS_MAP);
                    }
                }
            }

            if (gltfMaterial.pbrMetallicRoughness != null
                // If there's a specular-glossiness extension, ignore metallic-roughness
                // (according to extension specification)
                && gltfMaterial.extensions?.KHR_materials_pbrSpecularGlossiness == null)
            {
                baseColorLinear = gltfMaterial.pbrMetallicRoughness.baseColor;
                material.SetFloat(metallicPropId, gltfMaterial.pbrMetallicRoughness.metallicFactor);
                material.SetFloat(roughnessPropId, gltfMaterial.pbrMetallicRoughness.roughnessFactor);

                TrySetTexture(
                    gltfMaterial.pbrMetallicRoughness.baseColorTexture,
                    material,
                    gltf,
                    mainTexPropId,
                    mainTexScaleTransform,
                    mainTexRotation,
                    mainTexUVChannelPropId
                    );

                if (TrySetTexture(
                        gltfMaterial.pbrMetallicRoughness.metallicRoughnessTexture,
                        material,
                        gltf,
                        metallicGlossMapPropId,
                        metallicRoughnessMapScaleTransformPropId,
                        metallicRoughnessMapRotationPropId,
                        metallicRoughnessMapUVChannelPropId
                        ))
                {
                    material.EnableKeyword(KW_METALLIC_ROUGNESS_MAP);
                }
            }

            if (TrySetTexture(
                    gltfMaterial.normalTexture,
                    material,
                    gltf,
                    bumpMapPropId,
                    bumpMapScaleTransformPropId,
                    bumpMapRotationPropId,
                    bumpMapUVChannelPropId
                    ))
            {
                material.EnableKeyword(Constants.kwNormalMap);
                material.SetFloat(bumpScalePropId, gltfMaterial.normalTexture.scale);
            }

            if (TrySetTexture(
                    gltfMaterial.occlusionTexture,
                    material,
                    gltf,
                    occlusionMapPropId,
                    occlusionMapScaleTransformPropId,
                    occlusionMapRotationPropId,
                    occlusionMapUVChannelPropId
                    ))
            {
                material.EnableKeyword(KW_OCCLUSION);
                material.SetFloat(occlusionStrengthPropId, gltfMaterial.occlusionTexture.strength);
            }

            if (TrySetTexture(
                    gltfMaterial.emissiveTexture,
                    material,
                    gltf,
                    emissionMapPropId,
                    emissionMapScaleTransformPropId,
                    emissionMapRotationPropId,
                    emissionMapUVChannelPropId
                    ))
            {
                material.EnableKeyword(KW_EMISSION);
            }

            if (gltfMaterial.extensions != null)
            {
                // Transmission - Approximation
                var transmission = gltfMaterial.extensions.KHR_materials_transmission;
                if (transmission != null)
                {
#if UNITY_EDITOR
                    logger?.Warning(LogCode.MaterialTransmissionApprox);
#endif
                    // Correct transmission is not supported in Built-In renderer
                    // This is an approximation for some corner cases
                    if (transmission.transmissionFactor > 0f && transmission.transmissionTexture.index < 0)
                    {
                        var premul = TransmissionWorkaroundShaderMode(transmission, ref baseColorLinear);
                        shaderMode = premul ? StandardShaderMode.Transparent : StandardShaderMode.Fade;
                    }
                }
            }

            switch (shaderMode)
            {
            case StandardShaderMode.Cutout:
                SetAlphaModeMask(material, gltfMaterial);
                break;

            case StandardShaderMode.Fade:
                SetAlphaModeBlend(material);
                break;

            case StandardShaderMode.Transparent:
                SetAlphaModeTransparent(material);
                break;

            default:
                SetOpaqueMode(material);
                break;
            }

            material.color = baseColorLinear.gamma;

            if (gltfMaterial.emissive != Color.black)
            {
                material.SetColor(emissionColorPropId, gltfMaterial.emissive.gamma);
                material.EnableKeyword(KW_EMISSION);
            }

            return(material);
        }