// get, load, or create the property texture for this material..
    public static MicroSplatPropData FindOrCreatePropTex(Material targetMat)
    {
        MicroSplatPropData propData = null;
        // look for it next to the material?
        var path = AssetDatabase.GetAssetPath(targetMat);

        path = path.Replace("\\", "/");
        if (!string.IsNullOrEmpty(path))
        {
            path  = path.Substring(0, path.IndexOf("."));
            path += "_propdata.asset";
            // mesh terrains are in a sub directory when lod'd, so seak back and get the shared propData
            if (path.Contains("MeshTerrain/MicroSplatData/") && !System.IO.File.Exists(path))
            {
                path = path.Replace("MeshTerrain/MicroSplatData/", "");
            }
            propData = AssetDatabase.LoadAssetAtPath <MicroSplatPropData>(path);
            if (propData == null)
            {
                propData = MicroSplatPropData.CreateInstance <MicroSplatPropData>();
                AssetDatabase.CreateAsset(propData, path);
                AssetDatabase.SaveAssets();
            }
        }
        targetMat.SetTexture("_PerTexProps", propData.GetTexture());
        return(propData);
    }
    protected void ApplySharedData(Material m)
    {
        if (propData != null)
        {
            m.SetTexture("_PerTexProps", propData.GetTexture());
        }
#if __MICROSPLAT_GLOBALTEXTURE__
        if (m.HasProperty("_GeoCurve") && propData != null)
        {
            m.SetTexture("_GeoCurve", propData.GetGeoCurve());
        }
        if (m.HasProperty("_GeoSlopeTex") && propData != null)
        {
            m.SetTexture("_GeoSlopeTex", propData.GetGeoSlopeFilter());
        }
        if (m.HasProperty("_GlobalSlopeTex") && propData != null)
        {
            m.SetTexture("_GlobalSlopeTex", propData.GetGlobalSlopeFilter());
        }
#endif


#if __MICROSPLAT_PROCTEX__
        if (procTexCfg != null)
        {
            if (m.HasProperty("_ProcTexCurves"))
            {
                m.SetTexture("_ProcTexCurves", procTexCfg.GetCurveTexture());
                m.SetTexture("_ProcTexParams", procTexCfg.GetParamTexture());
                m.SetInt("_PCLayerCount", procTexCfg.layers.Count);
            }
            if (m.HasProperty("_PCHeightGradients"))
            {
                m.SetTexture("_PCHeightGradients", procTexCfg.GetHeightGradientTexture());
            }
            if (m.HasProperty("_PCHeightHSV"))
            {
                m.SetTexture("_PCHeightHSV", procTexCfg.GetHeightHSVTexture());
            }

            if (m.HasProperty("_PCSlopeGradients"))
            {
                m.SetTexture("_PCSlopeGradients", procTexCfg.GetSlopeGradientTexture());
            }
            if (m.HasProperty("_PCSlopeHSV"))
            {
                m.SetTexture("_PCSlopeHSV", procTexCfg.GetSlopeHSVTexture());
            }
        }
#endif
    }
Пример #3
0
    protected void ApplyMaps(Material m)
    {
        if (m.IsKeywordEnabled("_GEOMAP") && geoTextureOverride != null)
        {
            m.SetTexture("_GeoTex", geoTextureOverride);
        }
        if (m.IsKeywordEnabled("_GEOCURVE") && propData != null)
        {
            m.SetTexture("_GeoCurve", propData.GetGeoCurve());
        }
        if (m.IsKeywordEnabled("_ALPHAHOLETEXTURE") && clipMap != null)
        {
            m.SetTexture("_AlphaHoleTexture", clipMap);
        }

        if (m.IsKeywordEnabled("_GLOBALTINT") && tintMapOverride != null)
        {
            m.SetTexture("_GlobalTintTex", tintMapOverride);
        }
        if (m.IsKeywordEnabled("_GLOBALNORMALS") && globalNormalOverride != null)
        {
            m.SetTexture("_GlobalNormalTex", globalNormalOverride);
        }
        if (m.IsKeywordEnabled("_VSGRASSMAP") && vsGrassMap != null)
        {
            m.SetTexture("_VSGrassMap", vsGrassMap);
        }
        if (m.IsKeywordEnabled("_VSSHADOWMAP") && vsShadowMap != null)
        {
            m.SetTexture("_VSShadowMap", vsShadowMap);
        }
        if (m.HasProperty("_StreamControl"))
        {
            m.SetTexture("_StreamControl", streamTexture);
        }
        if (m.IsKeywordEnabled("_ADVANCED_DETAIL"))
        {
            m.SetTexture("_AdvDetailControl", advDetailControl);
        }

        if (propData != null)
        {
            m.SetTexture("_PerTexProps", propData.GetTexture());
        }
    }
    protected void ApplyMaps(Material m)
    {
        if (m.HasProperty("_GeoTex") && geoTextureOverride != null)
        {
            m.SetTexture("_GeoTex", geoTextureOverride);
        }
        if (m.HasProperty("_GeoCurve") && propData != null)
        {
            m.SetTexture("_GeoCurve", propData.GetGeoCurve());
        }
        if (m.HasProperty("_AlphaHoleTexture") && clipMap != null)
        {
            m.SetTexture("_AlphaHoleTexture", clipMap);
        }
        if (m.HasProperty("_PerPixelNormal"))
        {
            m.SetTexture("_PerPixelNormal", perPixelNormal);
        }


        if (m.HasProperty("_GlobalTintTex") && tintMapOverride != null)
        {
            m.SetTexture("_GlobalTintTex", tintMapOverride);
        }
        if (m.HasProperty("_GlobalNormalTex") && globalNormalOverride != null)
        {
            m.SetTexture("_GlobalNormalTex", globalNormalOverride);
        }
        if (m.HasProperty("_VSGrassMap") && vsGrassMap != null)
        {
            m.SetTexture("_VSGrassMap", vsGrassMap);
        }
        if (m.HasProperty("_VSShadowMap") && vsShadowMap != null)
        {
            m.SetTexture("_VSShadowMap", vsShadowMap);
        }
        if (m.HasProperty("_StreamControl"))
        {
            m.SetTexture("_StreamControl", streamTexture);
        }
        if (m.HasProperty("_AdvDetailControl"))
        {
            m.SetTexture("_AdvDetailControl", advDetailControl);
        }

        if (propData != null)
        {
            m.SetTexture("_PerTexProps", propData.GetTexture());
        }

      #if __MICROSPLAT_PROCTEX__
        if (procTexCfg != null)
        {
            if (m.HasProperty("_ProcTexCurves"))
            {
                m.SetTexture("_ProcTexCurves", procTexCfg.GetCurveTexture());
                m.SetTexture("_ProcTexParams", procTexCfg.GetParamTexture());
                m.SetInt("_PCLayerCount", procTexCfg.layers.Count);
                if (procBiomeMask != null && m.HasProperty("_ProcTexBiomeMask"))
                {
                    m.SetTexture("_ProcTexBiomeMask", procBiomeMask);
                }
            }
            if (m.HasProperty("_PCHeightGradients"))
            {
                m.SetTexture("_PCHeightGradients", procTexCfg.GetHeightGradientTexture());
            }
            if (m.HasProperty("_PCHeightHSV"))
            {
                m.SetTexture("_PCHeightHSV", procTexCfg.GetHeightHSVTexture());
            }
            if (m.HasProperty("_CavityMap"))
            {
                m.SetTexture("_CavityMap", cavityMap);
            }
        }
      #endif
    }
    public void Sync()
    {
        if (templateMaterial == null)
        {
            return;
        }

      #if UNITY_EDITOR
        if (terrain.materialType != Terrain.MaterialType.Custom || terrain.materialTemplate == null)
        {
            oldBaseMapSize     = terrain.terrainData.baseMapResolution;
            oldBaseMapDistance = terrain.basemapDistance;
        }
        if (addPass == null)
        {
            addPass = Shader.Find("Hidden/MicroSpat/AddPass");
        }
      #endif
        Material m = null;



        if (terrain.materialTemplate == matInstance && matInstance != null)
        {
            terrain.materialTemplate.CopyPropertiesFromMaterial(templateMaterial);
            m = terrain.materialTemplate;
        }
        else
        {
            m = new Material(templateMaterial);
        }
        terrain.materialType = Terrain.MaterialType.Custom;


        m.hideFlags = HideFlags.HideAndDontSave;
        terrain.materialTemplate = m;
        matInstance = m;

        if (m.IsKeywordEnabled("_GEOMAP") && geoTextureOverride != null)
        {
            m.SetTexture("_GeoTex", geoTextureOverride);
        }
        if (m.IsKeywordEnabled("_GEOCURVE") && propData != null)
        {
            m.SetTexture("_GeoCurve", propData.GetGeoCurve());
        }

        if (m.IsKeywordEnabled("_GLOBALTINT") && tintMapOverride != null)
        {
            m.SetTexture("_GlobalTintTex", tintMapOverride);
        }
        if (m.IsKeywordEnabled("_GLOBALNORMALS") && globalNormalOverride != null)
        {
            m.SetTexture("_GlobalNormalTex", globalNormalOverride);
        }
        if (m.IsKeywordEnabled("_VSGRASSMAP") && vsGrassMap != null)
        {
            m.SetTexture("_VSGrassMap", vsGrassMap);
        }
        if (m.IsKeywordEnabled("_VSSHADOWMAP") && vsShadowMap != null)
        {
            m.SetTexture("_VSShadowMap", vsShadowMap);
        }
        if (m.HasProperty("_StreamControl"))
        {
            m.SetTexture("_StreamControl", streamTexture);
        }
        if (m.IsKeywordEnabled("_ADVANCED_DETAIL"))
        {
            m.SetTexture("_AdvDetailControl", advDetailControl);
        }

        if (propData != null)
        {
            m.SetTexture("_PerTexProps", propData.GetTexture());
        }



        var controls = terrain.terrainData.alphamapTextures;
        m.SetTexture("_Control0", controls.Length > 0 ? controls[0] : Texture2D.blackTexture);
        m.SetTexture("_Control1", controls.Length > 1 ? controls[1] : Texture2D.blackTexture);
        m.SetTexture("_Control2", controls.Length > 2 ? controls[2] : Texture2D.blackTexture);
        m.SetTexture("_Control3", controls.Length > 3 ? controls[3] : Texture2D.blackTexture);

        // set base map distance to max of fancy features
        // base map does not use the "base map" texture, so slam to 16
        // only do this stuff editor time to avoid runtime cost
      #if UNITY_EDITOR
        if (terrain.terrainData.baseMapResolution != 16)
        {
            terrain.terrainData.baseMapResolution = 16;
        }
        float basemapDistance = 0;

        if (m.HasProperty("_TessData2"))
        {
            float d = m.GetVector("_TessData2").y;
            if (d > basemapDistance)
            {
                basemapDistance = d;
            }
        }
        if (m.HasProperty("_ParallaxParams"))
        {
            Vector4 v = m.GetVector("_ParallaxParams");
            float   d = v.y + v.z;
            if (d > basemapDistance)
            {
                basemapDistance = d;
            }
        }
        if (m.HasProperty("_DetailNoiseScaleStrengthFade"))
        {
            float d = m.GetVector("_DetailNoiseScaleStrengthFade").z;
            if (d > basemapDistance)
            {
                basemapDistance = d;
            }
        }

        terrain.basemapDistance = basemapDistance;
      #endif

        if (OnMaterialSync != null)
        {
            OnMaterialSync(m);
        }

        if (blendMat != null && terrainDesc != null)
        {
            if (blendMatInstance == null)
            {
                blendMatInstance = new Material(blendMat);
            }

            SyncBlendMat();
        }


      #if UNITY_EDITOR
        RestorePrototypes();
      #endif
    }
Пример #6
0
    protected void ApplyMaps(Material m)
    {
        SetMap(m, "_PerPixelNormal", perPixelNormal);
        SetMap(m, "_StreamControl", streamTexture);

#if __MICROSPLAT_ALPHAHOLE__
        SetMap(m, "_AlphaHoleTexture", clipMap);
#endif

#if __MICROSPLAT_GLOBALTEXTURE__
        SetMap(m, "_GeoTex", geoTextureOverride);
        SetMap(m, "_GlobalTintTex", tintMapOverride);
        SetMap(m, "_GlobalNormalTex", globalNormalOverride);
        SetMap(m, "_GlobalSAOMTex", globalSAOMOverride);
        SetMap(m, "_GlobalEmisTex", globalEmisOverride);
        if (m.HasProperty("_GeoCurve") && propData != null)
        {
            m.SetTexture("_GeoCurve", propData.GetGeoCurve());
        }
        if (m.HasProperty("_GeoSlopeTex") && propData != null)
        {
            m.SetTexture("_GeoSlopeTex", propData.GetGeoSlopeFilter());
        }
        if (m.HasProperty("_GlobalSlopeTex") && propData != null)
        {
            m.SetTexture("_GlobalSlopeTex", propData.GetGlobalSlopeFilter());
        }
#endif

#if __MICROSPLAT_SCATTER__
        SetMap(m, "_ScatterControl", scatterMapOverride);
#endif

#if __MICROSPLAT_SNOW__
        SetMap(m, "_SnowMask", snowMaskOverride);
#endif

#if (VEGETATION_STUDIO || VEGETATION_STUDIO_PRO)
        SetMap(m, "_VSGrassMap", vsGrassMap);
        SetMap(m, "_VSShadowMap", vsShadowMap);
#endif

#if __MICROSPLAT_ADVANCED_DETAIL__
        SetMap(m, "_AdvDetailControl", advDetailControl);
#endif


        if (propData != null)
        {
            m.SetTexture("_PerTexProps", propData.GetTexture());
        }

#if __MICROSPLAT_PROCTEX__
        if (procTexCfg != null)
        {
            if (m.HasProperty("_ProcTexCurves"))
            {
                m.SetTexture("_ProcTexCurves", procTexCfg.GetCurveTexture());
                m.SetTexture("_ProcTexParams", procTexCfg.GetParamTexture());
                m.SetInt("_PCLayerCount", procTexCfg.layers.Count);
                if (procBiomeMask != null && m.HasProperty("_ProcTexBiomeMask"))
                {
                    m.SetTexture("_ProcTexBiomeMask", procBiomeMask);
                }
            }
            if (m.HasProperty("_PCHeightGradients"))
            {
                m.SetTexture("_PCHeightGradients", procTexCfg.GetHeightGradientTexture());
            }
            if (m.HasProperty("_PCHeightHSV"))
            {
                m.SetTexture("_PCHeightHSV", procTexCfg.GetHeightHSVTexture());
            }
            if (m.HasProperty("_CavityMap"))
            {
                m.SetTexture("_CavityMap", cavityMap);
            }

            if (m.HasProperty("_PCSlopeGradients"))
            {
                m.SetTexture("_PCSlopeGradients", procTexCfg.GetSlopeGradientTexture());
            }
            if (m.HasProperty("_PCSlopeHSV"))
            {
                m.SetTexture("_PCSlopeHSV", procTexCfg.GetSlopeHSVTexture());
            }
        }
#endif
    }