예제 #1
0
        private static void UpdateMaterialContent(Material material, ShaderConfigData shaderConfigData)
        {
            var shader = UnityEngine.Shader.Find(shaderConfigData.NewShaderName);

            if (shader == null)
            {
                return;
            }

            _logger.LogNewShader(shaderConfigData.NewShaderName);

            var originalMaterial = new Material(material);

            material.shader             = shader;
            _shouldUpdatePropertyFactor = false;

            UpdateMaterialRendering(material, shaderConfigData);
            UpdateMaterialBase(material, originalMaterial);

            UpdateMaterialSpecular(material, shaderConfigData, originalMaterial);
            UpdateMaterialReflection(material, shaderConfigData, originalMaterial);
            UpdateMaterialRimWrap(material, shaderConfigData, originalMaterial);

            UpdateMaterialDiscolor(material, shaderConfigData, originalMaterial);

            UpdateMaterialNormalmap(material, shaderConfigData, originalMaterial);
            UpdateMaterialToonmap(material, shaderConfigData, originalMaterial);

            UpdateMaterialBottomLayer(material, shaderConfigData, originalMaterial);
            UpdateMaterialDecalLayer(material, shaderConfigData, originalMaterial);

            UpdateMaterialPropertyFactor(material, originalMaterial);

            DestroyImmediate(originalMaterial);
        }
예제 #2
0
        private static void UpdateMaterialDecalLayer(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            var decalLayers = CollectOriginalMaterialDecalLayers(originalMaterial, shaderConfigData.DecalLayerType);

            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.DecalLayerPropertyGroupConfigData, decalLayers.Count, true))
            {
                return;
            }

            bool useUv2 = false;
            var  index  = 0;
            var  decalTextureConfigDatas = UpdaterHelper.DecalLayerTextureConfigDatas;

            foreach (var decalLayer in decalLayers)
            {
                if (index >= decalTextureConfigDatas.Count)
                {
                    break;
                }

                var decalTextureConfigData = decalTextureConfigDatas [index];
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialTexture, decalTextureConfigData.TexturePropertyName, decalLayer.Key);
                if (decalLayer.Value)
                {
                    material.SetFloat(decalTextureConfigData.UVPropertyName, 1);
                    material.EnableKeyword(decalTextureConfigData.UVKeyword);
                    useUv2 = true;
                }
                else
                {
                    material.SetFloat(decalTextureConfigData.UVPropertyName, 0);
                    material.DisableKeyword(decalTextureConfigData.UVKeyword);
                }

                index++;
            }


            if (index == 1)
            {
                _logger.LogFeature(UpdaterLogFeature.DecalLayer1);
            }
            else if (index == 2)
            {
                _logger.LogFeature(UpdaterLogFeature.DecalLayer2);
            }
            else if (index > 2)
            {
                _logger.LogFeature(UpdaterLogFeature.DecalLayer3);
            }
            if (useUv2)
            {
                _logger.LogFeature(UpdaterLogFeature.DecalLayerUv2);
            }
        }
예제 #3
0
        private static void UpdateMaterialRendering(Material material, ShaderConfigData shaderConfigData)
        {
            material.SetFloat(TCShaderUtil.PROPERTY_RENDING_MODE, (float)shaderConfigData.RenderingMode);
            TCShaderUtil.SetupMaterialWithRenderingMode(material, shaderConfigData.RenderingMode, true);
            if (shaderConfigData.RenderQueueAdd != 0)
            {
                material.renderQueue += shaderConfigData.RenderQueueAdd;
            }

            _logger.LogRenderingMode(shaderConfigData.RenderingMode, shaderConfigData.RenderQueueAdd);
        }
예제 #4
0
        private static void UpdateMaterialSpecular(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.SpecularPropertyGroupConfigData, 1, shaderConfigData.IsSpecularEnabled))
            {
                return;
            }

            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialColor, TCShaderUtil.PROPERTY_SPEC_COLOR);
            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_SHININESS);

            _logger.LogFeature(UpdaterLogFeature.Specular);
        }
예제 #5
0
        private static void UpdateMaterialToonmap(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            var textureExists = ExistsMaterialTexture(material, TCShaderUtil.PROPERTY_TOONMAP_CUBE);

            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.ToonmapPropertyGroupConfigData, 1, shaderConfigData.IsToonmapEnabled && textureExists))
            {
                return;
            }

            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialTexture, TCShaderUtil.PROPERTY_TOONMAP_CUBE, "_ToonShade");

            _logger.LogFeature(UpdaterLogFeature.Toonmap);
        }
예제 #6
0
        private static void UpdateMaterialNormalmap(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            var textureExists = ExistsMaterialTexture(material, TCShaderUtil.PROPERTY_NORMAL_BUMP_MAP);

            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.NormalmapPropertyGroupConfigData, 1,
                                                           shaderConfigData.IsNormalmapEnabled && textureExists))
            {
                return;
            }

            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialTexture, TCShaderUtil.PROPERTY_NORMAL_BUMP_MAP);

            _logger.LogFeature(UpdaterLogFeature.Normalmap);
        }
예제 #7
0
        private static void UpdateMaterialRimWrap(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.RimWrapPropertyGroupConfigData, 1, shaderConfigData.IsRimWrapEnabled))
            {
                return;
            }

            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialColor, TCShaderUtil.PROPERTY_RIM_COLOR);
            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_RIM_POWER);
            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_WRAP_POWER);
            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_LIGHT_POWER);

            _logger.LogFeature(UpdaterLogFeature.RimWrap);
        }
예제 #8
0
        private static void UpdateMaterialReflection(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.ReflectionPropertyGroupConfigData, 1, shaderConfigData.IsReflectionEnabled))
            {
                return;
            }


            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialColor, TCShaderUtil.PROPERTY_REFLECT_COLOR);
            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialTexture, TCShaderUtil.PROPERTY_REFLECT_CUBE, "_Cube");

            _shouldUpdatePropertyFactor = true;

            _logger.LogFeature(UpdaterLogFeature.Reflection);
        }
예제 #9
0
        private static void UpdateMaterialBottomLayer(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            var textureExists = ExistsMaterialTexture(material, TCShaderUtil.PROPERTY_BOTTOM_TEX);

            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.BottomLayerPropertyGroupConfigData, 1,
                                                           shaderConfigData.IsBottomLayerEnabled && textureExists))
            {
                return;
            }

            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialTexture, TCShaderUtil.PROPERTY_BOTTOM_TEX);

            _shouldUpdatePropertyFactor = true;

            _logger.LogFeature(UpdaterLogFeature.BottomLayer);
        }
예제 #10
0
        private static void UpdateMaterialDiscolor(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            var shouldEnabled           = true;
            var originalHuePropertyName = "_Hue";

            // check hue alpha
            if (shaderConfigData.DiscolorMode == TCShaderDiscolorMode.HueReplace)
            {
                var originalHuePropertyId = UnityEngine.Shader.PropertyToID(originalHuePropertyName);
                if (originalMaterial.HasProperty(originalHuePropertyId))
                {
                    var hueColor = originalMaterial.GetColor(originalHuePropertyId);
                    shouldEnabled = hueColor.a > 0.01f;
                }
            }

            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.DiscolorPropertyGroupConfigData, (int)shaderConfigData.DiscolorMode, shouldEnabled))
            {
                return;
            }

            switch (shaderConfigData.DiscolorMode)
            {
            case TCShaderDiscolorMode.HslBlend:
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_HUE);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_SATURATION);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_LIGHTNESS);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_MIXING_FACTOR);

                _logger.LogFeature(UpdaterLogFeature.HslBlend);
                break;

            case TCShaderDiscolorMode.HueReplace:
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialColor, TCShaderUtil.PROPERTY_HUE_COLOR, originalHuePropertyName);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_SATUR_MIN);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_SATUR_RATIO);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_SATUR_ADD);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_LIGHT_MAX);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_LIGHT_RATIO);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_LIGHT_ADD);

                _logger.LogFeature(UpdaterLogFeature.HueReplace);
                break;
            }
        }