示例#1
0
        protected override void ParseFloatOrRange(string propertyName, float value, MetallicGlossinessShaderArguments arguments)
        {
            switch (propertyName)
            {
            case "_NormalScale":
                arguments.BumpScale = value;
                break;

            case "_Cutoff":
                arguments.Cutoff = value;
                break;

            case "_SmoothnessRemapMin":
                arguments.SmoothnessRemapMin = value;
                break;

            case "_SmoothnessRemapMax":
                arguments.SmoothnessRemapMax = value;
                break;

            case "_Smoothness":
                arguments.Glossiness = value;
                break;

            case "_Metallic":
                arguments.Metallic      = 0;
                arguments.MetallicScale = value;
                break;

            case "_AORemapMax":
                arguments.OcclusionStrength = value;
                break;
            }
        }
        public override void ExportMaterial(Material material, PrefabContext prefabContext)
        {
            var urhoPath = EvaluateMaterialName(material);

            using (var writer =
                       Engine.TryCreateXml(material.GetKey(), urhoPath, ExportUtils.GetLastWriteTimeUtc(material)))
            {
                if (writer == null)
                {
                    return;
                }

                var urhoMaterial = new UrhoPBRMaterial();
                urhoMaterial.Technique = "Techniques/PBR/PBRWater.xml";
                var metallicGlossinessShaderArguments = new MetallicGlossinessShaderArguments();

                var _SlowWaterNormal = GetTexture(material, "_SlowWaterNormal");
                var _SlowNormalScale = GetFloat(material, "_SlowNormalScale", 1);

                metallicGlossinessShaderArguments.Bump      = _SlowWaterNormal;
                metallicGlossinessShaderArguments.BumpScale = _SlowNormalScale;
                urhoMaterial.NormalTexture = GetScaledNormalTextureName(_SlowWaterNormal, _SlowNormalScale);

                urhoMaterial.ExtraParameters.Add("WaterMetallic", 1);
                urhoMaterial.ExtraParameters.Add("WaterRoughness", 1.0f - 1);
                urhoMaterial.ExtraParameters.Add("WaterFlowSpeed", 0.2);
                urhoMaterial.ExtraParameters.Add("WaterTimeScale", 1);
                urhoMaterial.ExtraParameters.Add("WaterFresnelPower", 4);

                Engine.SchedulePBRTextures(metallicGlossinessShaderArguments, urhoMaterial);

                WriteMaterial(writer, urhoMaterial, prefabContext);
            }
        }
示例#3
0
        protected virtual void ParseFloatOrRange(string propertyName, float value,
                                                 MetallicGlossinessShaderArguments arguments)
        {
            switch (propertyName)
            {
            case "_BumpScale":
                arguments.BumpScale = value;
                break;

            case "_DetailNormalMapScale": break;

            case "_DstBlend": break;

            case "_GlossyReflections": break;

            case "_Mode": break;

            case "_SmoothnessTextureChannel":
                arguments.SmoothnessTextureChannel = (SmoothnessTextureChannel)value;
                break;

            case "_SpecularHighlights": break;

            case "_SrcBlend": break;

            case "_UVSec": break;

            case "_ZWrite": break;

            case "_Cutoff":
                arguments.Cutoff = value;
                break;

            case "_GlossMapScale":
                arguments.SmoothnessRemapMax = value;
                break;

            case "_Glossiness":
                arguments.Glossiness = value;
                break;

            case "_Metallic":
                arguments.Metallic = value;
                break;

            case "_OcclusionStrength":
                arguments.OcclusionStrength = value;
                break;

            case "_Parallax": break;
            }
        }
示例#4
0
        protected virtual void ParseColor(string propertyName, Color color, MetallicGlossinessShaderArguments arguments)
        {
            switch (propertyName)
            {
            case "_Color":
                arguments.BaseColorColor = color;
                break;

            case "_EmissionColor":
                arguments.EmissiveColor = color;
                break;
            }
        }
        protected override UrhoPBRMaterial FromMetallicGlossiness(Material mat, MetallicGlossinessShaderArguments arguments)
        {
            var material           = base.FromMetallicGlossiness(mat, arguments);
            var _WindHeightFactor  = mat.GetFloat("_WindHeightFactor");
            var _WindHeightPivot   = mat.GetFloat("_WindHeightPivot");
            var _WindStemAxisX     = mat.GetFloat("_WindStemAxisX");
            var _WindStemAxisY     = mat.GetFloat("_WindStemAxisY");
            var _WindStemAxisZ     = mat.GetFloat("_WindStemAxisZ");
            var _WindPeriod        = mat.GetFloat("_WindPeriod");
            var _WindWorldSpacingX = mat.GetFloat("_WindWorldSpacingX");
            var _WindWorldSpacingY = mat.GetFloat("_WindWorldSpacingY");

            material.ExtraParameters.Add("WindHeightFactor", _WindHeightFactor);
            material.ExtraParameters.Add("WindHeightPivot", _WindHeightPivot);
            var windStemAxis = new Vector3(_WindStemAxisX, _WindStemAxisY, _WindStemAxisZ);

            material.ExtraParameters.Add("WindStemAxis", windStemAxis);
            material.ExtraParameters.Add("WindPeriod", _WindPeriod);
            material.ExtraParameters.Add("WindWorldSpacingX", new Vector2(_WindWorldSpacingX, _WindWorldSpacingY));

            CullMode cull = (CullMode)mat.GetFloat("_Cull");

            switch (cull)
            {
            case CullMode.Off:
                material.Cull       = Urho3DCulling.none;
                material.ShadowCull = Urho3DCulling.none;
                break;

            case CullMode.Front:
                material.Cull       = Urho3DCulling.cw;
                material.ShadowCull = Urho3DCulling.cw;
                break;

            default:
                material.Cull       = Urho3DCulling.ccw;
                material.ShadowCull = Urho3DCulling.ccw;
                break;
            }

            if (windStemAxis != Vector3.up)
            {
                material.VertexShaderDefines.Add("WINDSTEMAXIS");
            }
            material.Technique = "Techniques/PBR/PBRVegetationDiff.xml";

            return(material);
        }
示例#6
0
        protected virtual void ParseTexture(string propertyName, Texture texture,
                                            MetallicGlossinessShaderArguments arguments)
        {
            if (texture == null)
            {
                return;
            }
            switch (propertyName)
            {
            case "_BumpMap":
                arguments.Bump = texture;
                break;

            case "_DetailAlbedoMap":
                arguments.DetailBaseColor = texture;
                break;

            case "_DetailMask":
                arguments.Detail = texture;
                break;

            case "_DetailNormalMap":
                arguments.DetailNormal = texture;
                break;

            case "_EmissionMap":
                arguments.Emission = texture;
                break;

            case "_MainTex":
                arguments.BaseColor = texture;
                break;

            case "_MetallicGlossMap":
                arguments.MetallicGloss = texture;
                break;

            case "_OcclusionMap":
                arguments.Occlusion = texture;
                break;

            case "_ParallaxMap":
                arguments.Parallax = texture;
                break;
            }
        }
示例#7
0
        public void ExportPBRTextures(MetallicGlossinessShaderArguments arguments, UrhoPBRMaterial urhoMaterial)
        {
            if (!_engine.Options.ExportTextures)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(urhoMaterial.MetallicRoughnessTexture))
            {
                TransformMetallicGlossiness(arguments, urhoMaterial.MetallicRoughnessTexture);
            }
            if (!string.IsNullOrWhiteSpace(urhoMaterial.AOTexture))
            {
                TransformAOTexture(arguments, urhoMaterial.AOTexture);
            }
            if (!string.IsNullOrWhiteSpace(urhoMaterial.NormalTexture))
            {
                TransformNormal(arguments.Bump, arguments.BumpScale, urhoMaterial.NormalTexture);
            }
        }
示例#8
0
        protected override void ParseColor(string propertyName, Color color, MetallicGlossinessShaderArguments arguments)
        {
            switch (propertyName)
            {
            case "_BaseColor":
                arguments.BaseColorColor = color;
                break;

            case "_EmissiveColor":
                arguments.EmissiveColor = color;
                break;

            case "_EmissiveColorLDR":
                //arguments.EmissiveColorLDR = color;
                break;

            case "_EmissionColor":
                //arguments.EmissionColor = color;
                break;

            case "_SpecularColor":
                //arguments.SpecularColor = color;
                break;

            case "_UVDetailsMappingMask":
                //arguments.UVDetailsMappingMask = color;
                break;

            case "_UVMappingMaskEmissive":
                //arguments.UVMappingMaskEmissive = color;
                break;

            case "_TransmittanceColor":
                //arguments.TransmittanceColor = color;
                break;

            default:
                Debug.Log("Color " + propertyName + " = " + color);
                break;
            }
        }
示例#9
0
        private void TransformMetallicGlossiness(MetallicGlossinessShaderArguments arguments, string baseColorName)
        {
            var sourceFileTimestampUtc = ExportUtils.GetLastWriteTimeUtc(arguments.MetallicGloss, arguments.Smoothness);
            var assetGuid = (arguments.MetallicGloss ?? arguments.Smoothness).GetKey();

            if (_engine.IsUpToDate(assetGuid, baseColorName, sourceFileTimestampUtc))
            {
                return;
            }

            var shader      = Shader.Find("Hidden/UnityToCustomEngineExporter/Urho3D/ConvertToMetallicRoughness");
            var tmpMaterial = new Material(shader);

            Texture mainTexture       = null;
            Texture smoothnessTexture = null;

            try
            {
                mainTexture = EnsureTexture(new TextureOrColor(arguments.MetallicGloss,
                                                               new Color(arguments.Metallic, arguments.Metallic, arguments.Metallic, arguments.Glossiness)));
                smoothnessTexture =
                    EnsureTexture(new TextureOrColor(arguments.Smoothness, new Color(0, 0, 0, arguments.Glossiness)));
                var(width, height) = MaxTexutreSize(mainTexture, smoothnessTexture);
                tmpMaterial.SetTexture("_MainTex", mainTexture);
                tmpMaterial.SetFloat("_MetallicScale", arguments.MetallicScale);
                tmpMaterial.SetFloat("_SmoothnessRemapMin", arguments.SmoothnessRemapMin);
                tmpMaterial.SetFloat("_SmoothnessRemapMax", arguments.SmoothnessRemapMax);
                tmpMaterial.SetTexture("_Smoothness", smoothnessTexture);
                new TextureProcessor().ProcessAndSaveTexture(mainTexture, width, height, tmpMaterial,
                                                             _engine.GetTargetFilePath(baseColorName));
                WriteOptions(assetGuid, baseColorName, sourceFileTimestampUtc,
                             (ExportUtils.GetTextureOptions(mainTexture) ?? ExportUtils.GetTextureOptions(smoothnessTexture))
                             .WithSRGB(false));
            }
            finally
            {
                Object.DestroyImmediate(tmpMaterial);
                DestroyTmpTexture(arguments.MetallicGloss, mainTexture);
                DestroyTmpTexture(arguments.Smoothness, smoothnessTexture);
            }
        }
示例#10
0
        protected override UrhoPBRMaterial FromMetallicGlossiness(Material mat, MetallicGlossinessShaderArguments arguments)
        {
            var material         = base.FromMetallicGlossiness(mat, arguments);
            var _WaterMetallic   = mat.GetFloat("_WaterMetallic");
            var _WaterSmoothness = mat.GetFloat("_WaterSmoothness");
            var _FlowSpeed       = mat.GetFloat("_FlowSpeed");
            var _TimeScale       = mat.GetFloat("_TimeScale");
            var _FresnelPower    = mat.GetFloat("_FresnelPower");

            material.ExtraParameters.Add("WaterMetallic", _WaterMetallic);
            material.ExtraParameters.Add("WaterRoughness", 1.0f - _WaterSmoothness);
            material.ExtraParameters.Add("WaterFlowSpeed", _FlowSpeed);
            material.ExtraParameters.Add("WaterTimeScale", _TimeScale);
            material.ExtraParameters.Add("WaterFresnelPower", _FresnelPower);
            if (arguments.BaseColor != null)
            {
                material.PixelShaderDefines.Add("DIFFMAP");
            }
            material.Technique = "Techniques/PBR/PBRWater.xml";

            return(material);
        }
示例#11
0
 public void SchedulePBRTextures(MetallicGlossinessShaderArguments arguments, UrhoPBRMaterial urhoMaterial)
 {
     EditorTaskScheduler.Default.ScheduleForegroundTask(
         () => _textureExporter.ExportPBRTextures(arguments, urhoMaterial),
         urhoMaterial.MetallicRoughnessTexture);
 }
示例#12
0
        protected virtual UrhoPBRMaterial FromMetallicGlossiness(Material mat, MetallicGlossinessShaderArguments arguments)
        {
            var material = new UrhoPBRMaterial();

            material.NormalTexture    = GetScaledNormalTextureName(arguments.Bump, arguments.BumpScale, material);
            material.EmissiveTexture  = Engine.EvaluateTextrueName(arguments.Emission);
            material.AOTexture        = BuildAOTextureName(arguments.Occlusion, arguments.OcclusionStrength);
            material.BaseColorTexture = Engine.EvaluateTextrueName(arguments.BaseColor);
            var metalicGlossinesTexture = Engine.EvaluateTextrueName(arguments.MetallicGloss);
            var smoothnessTexture       = Engine.EvaluateTextrueName(arguments.Smoothness);
            var linearMetallic          = new Color(arguments.Metallic, 0, 0, 1).linear.r;

            if (string.IsNullOrWhiteSpace(metalicGlossinesTexture) && string.IsNullOrWhiteSpace(smoothnessTexture))
            {
                material.Metallic  = linearMetallic;
                material.Roughness = 1.0f - arguments.Glossiness;
            }
            else
            {
                var texNameBuilder = new StringBuilder();
                if (!string.IsNullOrWhiteSpace(metalicGlossinesTexture))
                {
                    texNameBuilder.Append(Path.GetDirectoryName(metalicGlossinesTexture).FixAssetSeparator());
                }
                else
                {
                    texNameBuilder.Append(Path.GetDirectoryName(smoothnessTexture).FixAssetSeparator());
                }
                if (texNameBuilder.Length > 0)
                {
                    texNameBuilder.Append('/');
                }

                if (!string.IsNullOrWhiteSpace(metalicGlossinesTexture))
                {
                    texNameBuilder.Append(Path.GetFileNameWithoutExtension(metalicGlossinesTexture));
                }
                else
                {
                    texNameBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0:0.00}", linearMetallic);
                }

                if (smoothnessTexture != metalicGlossinesTexture)
                {
                    texNameBuilder.Append('.');
                    texNameBuilder.Append(Path.GetFileNameWithoutExtension(smoothnessTexture));
                }

                if (arguments.SmoothnessRemapMax < 0.999f)
                {
                    texNameBuilder.Append('.');
                    texNameBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0:0.000}",
                                                arguments.SmoothnessRemapMax);
                }

                texNameBuilder.Append(".MetallicRoughness.png");
                material.MetallicRoughnessTexture = texNameBuilder.ToString();
            }

            material.BaseColor  = arguments.BaseColorColor.linear;
            material.AlphaBlend = arguments.Transparent;
            material.Cull       = Urho3DCulling.ccw;
            material.ShadowCull = Urho3DCulling.ccw;
            if (arguments.AlphaTest)
            {
                material.PixelShaderDefines.Add("ALPHAMASK");
            }
            material.EmissiveColor = arguments.EmissiveColor.linear;
            material.MatSpecColor  = new Color(1, 1, 1, 0);
            material.UOffset       = new Vector4(arguments.MainTextureScale.x, 0, 0, arguments.MainTextureOffset.x);
            material.VOffset       = new Vector4(0, arguments.MainTextureScale.y, 0, arguments.MainTextureOffset.y);
            material.EvaluateTechnique();
            return(material);
        }