Beispiel #1
0
        protected void ExtractBasicMaterialInfo(SyncMaterial syncMaterial, out bool transparent, out bool emission, out Color color)
        {
            transparent = StandardShaderHelper.IsTransparent(syncMaterial);
            emission    = syncMaterial.Emission != SyncColor.Black || syncMaterial.EmissionMap.TextureId != SyncId.None;

            var tint = ImportersUtils.GetUnityColor(syncMaterial.Tint, false);

            color = tint * ImportersUtils.GetUnityColor(syncMaterial.AlbedoColor, false);

            if (transparent)
            {
                color.a = syncMaterial.Alpha;
            }
        }
Beispiel #2
0
        protected override void SetMaterialPropertiesInternal(SyncedData <SyncMaterial> syncedMaterial, Material material, ITextureCache textureCache)
        {
            var syncMaterial = syncedMaterial.data;
            var sourceId     = syncedMaterial.key.source;

            ExtractBasicMaterialInfo(syncMaterial, out var transparent, out var emission, out var color);

            // Albedo
            material.SetColor("_BaseColor", color);
            AssignMap(material, sourceId, "_BaseColorMap", syncMaterial.AlbedoMap, textureCache);

            // Metallic
            material.SetFloat("_Metallic", syncMaterial.Metallic);
            if (syncMaterial.MetallicMap.TextureId != SyncId.None)
            {
                // TODO
            }

            // Smoothness
            material.SetFloat("_Smoothness", syncMaterial.Glossiness);
            if (syncMaterial.GlossinessMap.TextureId != SyncId.None)
            {
                // TODO
            }

            // Normal
            if (syncMaterial.NormalMap.TextureId != SyncId.None)
            {
                AssignMap(material, sourceId, "_NormalMap", syncMaterial.NormalMap, textureCache);
                material.SetFloat("_NormalScale", syncMaterial.NormalScale);
                material.EnableKeyword("_NORMALMAP");
                material.EnableKeyword("_NORMALMAP_TANGENT_SPACE");
            }

            // Transparency
            if (!emission && transparent)
            {
                material.SetColor("_Color", color);
                material.SetFloat("_SurfaceType", 1);
                material.SetFloat("_BlendMode", 0);
                material.SetFloat("_DstBlend", 10);
                material.SetFloat("_AlphaDstBlend", 10);
                material.SetFloat("_AlphaCutoffEnable", 0);
                material.SetFloat("_EnableBlendModePreserveSpecularLighting", 1);
                material.renderQueue = (int)RenderQueue.Transparent;

                material.EnableKeyword("_BLENDMODE_ALPHA");
                material.EnableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING");
                material.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT");
                material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
            }

            // Cutout
            // TODO Not supported?

            // Emission
            if (emission)
            {
                var emissionColor = ImportersUtils.GetUnityColor(syncMaterial.Emission);
                material.SetColor("_EmissiveColor", emissionColor);
                material.SetColor("_EmissiveColorLDR", emissionColor);

                if (syncMaterial.EmissionMap.TextureId != SyncId.None)
                {
                    AssignMap(material, sourceId, "_EmissiveColorMap", syncMaterial.EmissionMap, textureCache);
                }

                material.SetInt("_UseEmissiveIntensity", 1);
                //material.EnableKeyword("_Emissive");
                material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
            }
        }