Beispiel #1
0
        private void WriteTerrainMaterial(TerrainData terrain, PrefabContext prefabContext)
        {
            using (var writer =
                       _engine.TryCreateXml(terrain.GetKey(), EvaluateMaterial(terrain),
                                            ExportUtils.GetLastWriteTimeUtc(terrain)))
            {
                if (writer == null)
                {
                    return;
                }

                var layers       = terrain.terrainLayers;
                var layerIndices = GetTerrainLayersByPopularity(terrain).Take(_maxLayers).ToArray();

                var material = new UrhoPBRMaterial();
                material.Technique = "Techniques/PBR/PBRTerrainBlend.xml";
                material.TextureUnits.Add(EvaluateWeightsMap(terrain));
                Vector2 detailTiling = new Vector2(1, 1);
                for (var layerIndex = 0; layerIndex < layerIndices.Length; ++layerIndex)
                {
                    var layer = layers[layerIndices[layerIndex]];
                    detailTiling = new Vector2(terrain.size.x / layer.tileSize.x, terrain.size.z / layer.tileSize.y);
                    if (layer.diffuseTexture != null)
                    {
                        _engine.ScheduleTexture(layer.diffuseTexture);
                        var urhoAssetName = _engine.EvaluateTextrueName(layer.diffuseTexture);
                        material.TextureUnits.Add(urhoAssetName);
                    }
                    else
                    {
                        material.TextureUnits.Add(null);
                    }
                }
                material.MatSpecColor = new Color(0.0f, 0.0f, 0.0f, 1.0f);
                material.Roughness    = 1;
                material.Metallic     = 0;
                material.ExtraParameters.Add("DetailTiling", detailTiling);
                material.PixelShaderDefines.Add("TERRAINLAYERS" + layerIndices.Length.ToString(CultureInfo.InvariantCulture));

                StandardMaterialExporter.WriteMaterial(writer, material, prefabContext);
            }
        }
        public string TryGetSkyboxCubemap(Material skyboxMaterial)
        {
            if (!_skyboxMaterialExporter.CanExportMaterial(skyboxMaterial))
            {
                return(null);
            }
            var arguments = _skyboxMaterialExporter.SetupSkybox(skyboxMaterial);

            if (arguments.Skybox != null)
            {
                return(_engine.EvaluateTextrueName(arguments.Skybox));
            }
            var anyFace = arguments.BackTex ?? arguments.DownTex ?? arguments.FrontTex ??
                          arguments.LeftTex ?? arguments.RightTex ?? arguments.UpTex;

            if (anyFace != null)
            {
                return(ExportUtils.ReplaceExtension(_engine.EvaluateMaterialName(skyboxMaterial), ".Cubemap.xml"));
            }

            return(null);
        }