Example #1
0
 public override void OnDestroy()
 {
     base.OnDestroy();
     advectSediment.Destroy();
     sedimentField.Destroy();
     sedimentDeposition.Destroy();
     //sedimentOutFlow.Destroy();
     GameObject.Destroy(tiltAngle);
 }
        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 #3
0
 virtual public void OnDestroy()
 {
     main.Destroy();
     outFlow.Destroy();
 }
Example #4
0
 public override void OnDestroy()
 {
     base.OnDestroy();
     velocity.Destroy();
 }