private void RenderColorMap(GStylizedTerrain t, RenderTexture targetRt)
        {
            GShading shading = t.TerrainData.Shading;

            if (shading.Splats == null)
            {
                return;
            }
            Material mat = GInternalMaterials.SplatsToAlbedoMaterial;

            for (int i = 0; i < shading.SplatControlMapCount; ++i)
            {
                Texture2D controlMap = shading.GetSplatControl(i);
                mat.SetTexture("_Control0", controlMap);
                for (int channel = 0; channel < 4; ++channel)
                {
                    int prototypeIndex = i * 4 + channel;
                    if (prototypeIndex < shading.Splats.Prototypes.Count)
                    {
                        GSplatPrototype p = shading.Splats.Prototypes[prototypeIndex];
                        mat.SetTexture("_Splat" + channel, p.Texture);
                        Vector2 terrainSize  = new Vector2(t.TerrainData.Geometry.Width, t.TerrainData.Geometry.Length);
                        Vector2 textureScale = new Vector2(
                            p.TileSize.x != 0 ? terrainSize.x / p.TileSize.x : 0,
                            p.TileSize.y != 0 ? terrainSize.y / p.TileSize.y : 0);
                        Vector2 textureOffset = new Vector2(
                            p.TileOffset.x != 0 ? terrainSize.x / p.TileOffset.x : 0,
                            p.TileOffset.y != 0 ? terrainSize.y / p.TileOffset.y : 0);
                        mat.SetTextureScale("_Splat" + channel, textureScale);
                        mat.SetTextureOffset("_Splat" + channel, textureOffset);
                    }
                    else
                    {
                        mat.SetTexture("_Splat" + channel, null);
                        mat.SetTextureScale("_Splat" + channel, Vector2.zero);
                        mat.SetTextureOffset("_Splat" + channel, Vector2.zero);
                    }
                }

                GCommon.DrawQuad(targetRt, GCommon.FullRectUvPoints, mat, 0);
            }
        }
Example #2
0
        public void Override(GShading s)
        {
            if (OverrideCustomMaterial && CustomMaterial != null)
            {
                if (s.CustomMaterial == null)
                {
                    Material mat = Object.Instantiate(CustomMaterial);
                    mat.name = "TerrainMaterial_" + s.TerrainData.Id;
#if UNITY_EDITOR
                    UnityEditor.AssetDatabase.CreateAsset(mat, string.Format("Assets/{0}.mat", mat.name));
#endif
                    s.CustomMaterial = mat;
                }
                else
                {
                    s.CustomMaterial.shader = CustomMaterial.shader;
                }
                s.UpdateMaterials();
            }
            if (OverrideAlbedoMapResolution)
            {
                s.AlbedoMapResolution = AlbedoMapResolution;
            }
            if (OverrideMetallicMapResolution)
            {
                s.MetallicMapResolution = MetallicMapResolution;
            }
            if (OverrideAlbedoMapPropertyName)
            {
                s.AlbedoMapPropertyName = AlbedoMapPropertyName;
            }
            if (OverrideMetallicMapPropertyName)
            {
                s.MetallicMapPropertyName = MetallicMapPropertyName;
            }
            if (OverrideColorByHeight)
            {
                s.ColorByHeight = GUtilities.Clone(ColorByHeight);
            }
            if (OverrideColorByNormal)
            {
                s.ColorByNormal = GUtilities.Clone(ColorByNormal);
            }
            if (OverrideColorBlendCurve)
            {
                s.ColorBlendCurve = GUtilities.Clone(ColorBlendCurve);
            }
            if (OverrideColorByHeightPropertyName)
            {
                s.ColorByHeightPropertyName = ColorByHeightPropertyName;
            }
            if (OverrideColorByNormalPropertyName)
            {
                s.ColorByNormalPropertyName = ColorByNormalPropertyName;
            }
            if (OverrideColorBlendPropertyName)
            {
                s.ColorBlendPropertyName = ColorBlendPropertyName;
            }
            if (OverrideDimensionPropertyName)
            {
                s.DimensionPropertyName = DimensionPropertyName;
            }
            if (OverrideSplats)
            {
                s.Splats = Splats;
            }
            if (OverrideSplatControlResolution)
            {
                s.SplatControlResolution = SplatControlResolution;
            }
            if (OverrideSplatControlMapPropertyName)
            {
                s.SplatControlMapPropertyName = SplatControlMapPropertyName;
            }
            if (OverrideSplatMapPropertyName)
            {
                s.SplatMapPropertyName = SplatMapPropertyName;
            }
            if (OverrideSplatNormalPropertyName)
            {
                s.SplatNormalPropertyName = SplatNormalPropertyName;
            }
            if (OverrideSplatMetallicPropertyName)
            {
                s.SplatMetallicPropertyName = SplatMetallicPropertyName;
            }
            if (OverrideSplatSmoothnessPropertyName)
            {
                s.SplatSmoothnessPropertyName = SplatSmoothnessPropertyName;
            }
            s.UpdateLookupTextures();
        }