Ejemplo n.º 1
0
        /// <summary>
        /// Executes the modifiers in order and generates the necessary splatmaps
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="modifiers"></param>
        /// <param name="output"></param>
        public static void ProcessSingleLayer(Terrain terrain, LayerSettings settings)
        {
            //Disable or with no settings (result in a fill with black)
            if (settings.enabled == false)
            {
                return;
            }

            Graphics.SetRenderTarget(alphaMap);

            //Start with a full white base
            Graphics.Blit(Texture2D.whiteTexture, alphaMap);

            //Reverse order
            for (int i = settings.modifierStack.Count - 1; i >= 0; i--)
            {
                settings.modifierStack[i].Configure(filterMat);
                settings.modifierStack[i].Execute(alphaMap);
            }

            //Scale splatmap to fit in terrain
            Vector2 scaledSplatmapSize = new Vector2((terrain.terrainData.size.x / m_resolution) * m_resolution, (terrain.terrainData.size.z / m_resolution) * m_resolution);

            //PaintContext handles creation of splatmaps. Subtracting the weights of a splatmap, from the ones before it.
            //A single pixels of all combined alpha maps must not exceed a value of one. The 2nd pass of Hidden/TerrainEngine/TerrainLayerUtils is used internally to do this
            //Note: Paintcontext must use a serialized terrain reference, otherwise breaks when executing "ApplyDelayedActions" when the project is saved!
            PaintContext c = TerrainPaintUtility.BeginPaintTexture(terrain, new Rect(0, 0, scaledSplatmapSize.x, scaledSplatmapSize.y), settings.layer);

            Graphics.Blit(alphaMap, c.destinationRenderTexture);

            TerrainPaintUtility.EndPaintTexture(c, UndoActionName);
        }
Ejemplo n.º 2
0
        public void CreateSettingsForLayer(TerrainLayer layer)
        {
            if (layer == null)
            {
                return;
            }

            LayerSettings s = new LayerSettings();

            s.layer         = layer;
            s.modifierStack = new List <Modifier>();

            layerSettings.Insert(0, s);

            SetTerrainLayers();
        }