Example #1
0
        /// <summary>
        ///  Calculates how much ground should go in sediment flow aka force-based erosion
        ///  Transfers m_terrainField to m_sedimentField basing on
        ///  m_waterVelocity, m_sedimentCapacity, m_dissolvingConstant,
        ///  m_depositionConstant, m_tiltAngle, m_minTiltAngle
        /// Also calculates m_tiltAngle
        /// </summary>
        private void DissolveAndDeposition(DoubleDataTexture terrainField, Vector4 dissolvingConstant, float minTiltAngle, int TERRAIN_LAYERS)
        {
            link.m_tiltAngleMat.SetFloat("_TexSize", size);
            link.m_tiltAngleMat.SetFloat("_Layers", TERRAIN_LAYERS);
            link.m_tiltAngleMat.SetTexture("_TerrainField", terrainField.READ);

            Graphics.Blit(null, tiltAngle, link.m_tiltAngleMat);

            link.dissolutionAndDepositionMat.SetTexture("_TerrainField", terrainField.READ);
            link.dissolutionAndDepositionMat.SetTexture("_SedimentField", sedimentField.READ);
            link.dissolutionAndDepositionMat.SetTexture("_VelocityField", velocity.READ);
            link.dissolutionAndDepositionMat.SetTexture("_WaterField", main.READ);
            link.dissolutionAndDepositionMat.SetTexture("_TiltAngle", tiltAngle);
            link.dissolutionAndDepositionMat.SetFloat("_MinTiltAngle", minTiltAngle);
            link.dissolutionAndDepositionMat.SetFloat("_SedimentCapacity", sedimentCapacity);
            link.dissolutionAndDepositionMat.SetVector("_DissolvingConstant", dissolvingConstant);
            link.dissolutionAndDepositionMat.SetFloat("_DepositionConstant", depositionConstant);
            link.dissolutionAndDepositionMat.SetFloat("_Layers", (float)TERRAIN_LAYERS);
            link.dissolutionAndDepositionMat.SetFloat("_DissolveLimit", dissolveLimit); //nash added it

            RenderTexture[] terrainAndSediment = new RenderTexture[3] {
                terrainField.WRITE, sedimentField.WRITE, sedimentDeposition.WRITE
            };

            RTUtility.MultiTargetBlit(terrainAndSediment, link.dissolutionAndDepositionMat);
            terrainField.Swap();
            sedimentField.Swap();
            sedimentDeposition.Swap();
        }
Example #2
0
        public Layer(string name, int size, float damping, ErosionSim link, float overwriteFluidity, float fluidity)
        {
            main = new DoubleDataTexture(name, size, RenderTextureFormat.ARGBFloat, FilterMode.Point);    // was RFloat
            main.ClearColor();
            outFlow = new DoubleDataTexture(name, size, RenderTextureFormat.ARGBFloat, FilterMode.Point); //was ARGBHalf
            outFlow.ClearColor();
            this.damping = damping;
            this.link    = link;
            this.size    = size;

            this.overwriteFluidity = overwriteFluidity;
            this.fluidity          = fluidity;
        }
        private void InitLayers()
        {
            terrainField = new DoubleDataTexture("Terrain Height Field", TEX_SIZE, RenderTextureFormat.ARGBFloat, FilterMode.Point);


            regolithField   = new DoubleDataTexture("Regolith Field", TEX_SIZE, RenderTextureFormat.RFloat, FilterMode.Point);
            regolithOutFlow = new DoubleDataTexture("Regolith outflow", TEX_SIZE, RenderTextureFormat.ARGBHalf, FilterMode.Point);



            slippageHeight  = DoubleDataTexture.Create("Slippage Height", TEX_SIZE, RenderTextureFormat.RHalf, FilterMode.Point);     // was RHalf
            slippageOutflow = DoubleDataTexture.Create("Slippage Outflow", TEX_SIZE, RenderTextureFormat.ARGBHalf, FilterMode.Point); // was ARGBHalf

            magmaVelocity = new DoubleDataTexture("Magma Velocity", TEX_SIZE, RenderTextureFormat.ARGBHalf, FilterMode.Bilinear);     // was RGHalf
        }
        static DoubleDataTexture()
        {
            tempRTARGB = DoubleDataTexture.Create("tempRTARGB", 1, RenderTextureFormat.ARGBFloat, FilterMode.Point);

            tempT2DRGBA            = new Texture2D(1, 1, TextureFormat.RGBAFloat, false);
            tempT2DRGBA.wrapMode   = TextureWrapMode.Clamp;
            tempT2DRGBA.filterMode = FilterMode.Point;

            tempRTRFloat = DoubleDataTexture.Create("tempRTRFloat", 1, RenderTextureFormat.RFloat, FilterMode.Point);

            tempT2DRFloat            = new Texture2D(1, 1, TextureFormat.RFloat, false);
            tempT2DRFloat.wrapMode   = TextureWrapMode.Clamp;
            tempT2DRFloat.filterMode = FilterMode.Point;
            LoadMaterials();
        }
Example #5
0
        public LayerWithErosion(string name, int size, float viscosity, ErosionSim link) : base(name, size, viscosity, link)
        {
            //waterField = new DoubleDataTexture("Water Field", TEX_SIZE, RenderTextureFormat.RFloat, FilterMode.Point);
            //waterOutFlow = new DoubleDataTexture("Water outflow", TEX_SIZE, RenderTextureFormat.ARGBHalf, FilterMode.Point);


            sedimentField = new DoubleDataTexture("Sediment Field", size, RenderTextureFormat.ARGBFloat, FilterMode.Bilinear);        // was RHalf
            sedimentField.ClearColor();
            advectSediment = new DoubleDataTexture("Sediment Advection", size, RenderTextureFormat.RHalf, FilterMode.Bilinear);       // was RHalf
            advectSediment.ClearColor();
            sedimentDeposition = new DoubleDataTexture("Sediment Deposition", size, RenderTextureFormat.ARGBFloat, FilterMode.Point); // was RHalf
            sedimentDeposition.ClearColor();

            tiltAngle = DoubleDataTexture.Create("Tilt Angle", size, RenderTextureFormat.RHalf, FilterMode.Point);// was RHalf

            //sedimentOutFlow = DoubleDataTexture.Create("sedimentOutFlow", size, RenderTextureFormat.ARGBHalf, FilterMode.Point);// was ARGBHalf
            //sedimentOutFlow.ClearColor();
        }
        private void OnDestroy()
        {
            Destroy(slippageHeight);
            Destroy(slippageOutflow);
            water.OnDestroy();
            lava.OnDestroy();
            DoubleDataTexture.DestroyAll();

            int numGrids = TOTAL_GRID_SIZE / GRID_SIZE + 1;

            for (int x = 0; x < numGrids; x++)
            {
                for (int y = 0; y < numGrids; y++)
                {
                    int idx = x + y * numGrids;

                    Destroy(gridLand[idx]);
                    Destroy(gridWater[idx]);
                    //Destroy(gridLava[idx]);
                }
            }
        }
Example #7
0
        static public RenderTexture Load(string path)
        {
            Texture2D tex = Texture2DExtensions.LoadPNG(path);

            if (tex == null)
            {
                Debug.Log("Can't load " + path + " texture");
                return(null);
            }
            var changeFormatTexture = new Texture2D(tex.width, tex.width, TextureFormat.RGBAFloat, false);

            changeFormatTexture.SetPixels(tex.GetPixels());
            changeFormatTexture.Apply();

            var res = DoubleDataTexture.Create("Loaded", tex.width, RenderTextureFormat.ARGBFloat, FilterMode.Point);// was RHalf

            Graphics.CopyTexture(changeFormatTexture, 0, 0, res, 0, 0);
            GameObject.Destroy(tex);
            GameObject.Destroy(changeFormatTexture);

            return(res);
        }
        private void InitMaps()
        {
            terrainField.ClearColor();
            //waterOutFlow.ClearColor();
            //waterVelocity.ClearColor();
            //advectSediment.ClearColor();
            //waterField.ClearColor();
            //sedimentField.ClearColor();
            regolithField.ClearColor();
            regolithOutFlow.ClearColor();
            //sedimentDeposition.ClearColor();
            magmaVelocity.ClearColor();



            DoubleDataTexture noiseTex;

            noiseTex = new DoubleDataTexture("", TEX_SIZE, RenderTextureFormat.RFloat, FilterMode.Bilinear);

            GPUPerlinNoise perlin = new GPUPerlinNoise(m_seed);

            perlin.LoadResourcesFor2DNoise();

            m_noiseMat.SetTexture("_PermTable1D", perlin.PermutationTable1D);
            m_noiseMat.SetTexture("_Gradient2D", perlin.Gradient2D);

            for (int j = 0; j < TERRAIN_LAYERS; j++)
            {
                m_noiseMat.SetFloat("_Offset", m_offset[j]);

                float amp  = 0.5f;
                float freq = m_frequency[j];

                //Must clear noise from last pass
                noiseTex.ClearColor();

                //write noise into texture with the settings for this layer
                for (int i = 0; i < m_octaves[j]; i++)
                {
                    m_noiseMat.SetFloat("_Frequency", freq);
                    m_noiseMat.SetFloat("_Amp", amp);
                    m_noiseMat.SetFloat("_Pass", (float)i);

                    Graphics.Blit(noiseTex.READ, noiseTex.WRITE, m_noiseMat, (int)m_layerStyle[j]);
                    noiseTex.Swap();

                    freq *= m_lacunarity[j];
                    amp  *= m_gain[j];
                }

                float useAbs = 0.0f;
                if (m_finalNosieIsAbs[j])
                {
                    useAbs = 1.0f;
                }

                //Mask the layers that we dont want to write into
                Vector4 mask = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
                mask[j] = 1.0f;

                m_initTerrainMat.SetFloat("_Amp", m_amp[j]);
                m_initTerrainMat.SetFloat("_UseAbs", useAbs);
                m_initTerrainMat.SetVector("_Mask", mask);
                m_initTerrainMat.SetTexture("_NoiseTex", noiseTex.READ);
                m_initTerrainMat.SetFloat("_Height", TERRAIN_HEIGHT);

                //Apply the noise for this layer to the terrain field
                Graphics.Blit(terrainField.READ, terrainField.WRITE, m_initTerrainMat);
                terrainField.Swap();
            }

            //dont need this tex anymore
            noiseTex.Destroy();
        }
Example #9
0
 internal void SimulateErosion(DoubleDataTexture terrainField, Vector4 dissolvingConstant, float minTiltAngle, int TERRAIN_LAYERS, float TIME_STEP)
 {
     DissolveAndDeposition(terrainField, dissolvingConstant, minTiltAngle, TERRAIN_LAYERS);
     AdvectSediment(TIME_STEP);
     //AlternativeAdvectSediment();
 }
Example #10
0
 public LayerWithVelocity(string name, int size, float viscosity, ErosionSim link) : base(name, size, viscosity, link, 0.96f, 4181f, 1f, 1f)
 {
     velocity = new DoubleDataTexture("Water Velocity", size, RenderTextureFormat.ARGBFloat, FilterMode.Bilinear);// was RGHalf
     velocity.ClearColor();
 }