Exemplo n.º 1
0
        protected override void UpdateNode()
        {
            if (DrawOcean == true)
            {
                var t = Time.realtimeSinceStartup;

                InitWaveSpectrum(t);

                // Perform fourier transform and record what is the current index
                IDX = Fourier.PeformFFT(FourierBuffer0, FourierBuffer1, FourierBuffer2);
                Fourier.PeformFFT(FourierBuffer3, FourierBuffer4);

                // Copy the contents of the completed fourier transform to the map textures.
                // You could just use the buffer textures (FourierBuffer0,1,2,etc) to read from for the ocean shader
                // but they need to have mipmaps and unity updates the mipmaps
                // every time the texture is renderer into. This impacts performance during fourier transform stage as mipmaps would be updated every pass
                // and there is no way to disable and then enable mipmaps on render textures in Unity at time of writting.

                Graphics.Blit(FourierBuffer0[IDX], Map0);
                Graphics.Blit(FourierBuffer1[IDX], Map1);
                Graphics.Blit(FourierBuffer2[IDX], Map2);
                Graphics.Blit(FourierBuffer3[IDX], Map3);
                Graphics.Blit(FourierBuffer4[IDX], Map4);

                OceanMaterial.SetVector("_Ocean_MapSize", new Vector2(FloatSize, FloatSize));
                OceanMaterial.SetVector("_Ocean_Choppyness", Choppyness);
                OceanMaterial.SetVector("_Ocean_GridSizes", GridSizes);
                OceanMaterial.SetFloat("_Ocean_HeightOffset", OceanLevel);
                OceanMaterial.SetTexture("_Ocean_Variance", Variance);
                OceanMaterial.SetTexture("_Ocean_Map0", Map0);
                OceanMaterial.SetTexture("_Ocean_Map1", Map1);
                OceanMaterial.SetTexture("_Ocean_Map2", Map2);
                OceanMaterial.SetTexture("_Ocean_Map3", Map3);
                OceanMaterial.SetTexture("_Ocean_Map4", Map4);
            }

            base.UpdateNode();
        }
Exemplo n.º 2
0
    public void SimulateWaves(float t)
    {
        InitWaveSpectrum(t);

        m_idx = m_fourier.PeformFFT(m_fourierBuffer0, m_fourierBuffer1, m_fourierBuffer2);

        //Copy the contents of the completed fourier transform to the map textures.
        //Graphics Blit is needed as ReadPixels is not able to copy from one render texture to another at time of writting
        //You could just use the buffer textures (m_fourierBuffer0,1,2) to read from for the ocean shader but they need to have mipmaps and unity updates the mipmaps
        //every time the texture is renderer into. This impacts performance during fourier transform stage as mipmaps would be updated every pass
        //and there is no way to disable and then enable mipmaps on render textures at time of writting.

        Graphics.Blit(m_fourierBuffer0[m_idx], m_map0);
        Graphics.Blit(m_fourierBuffer1[m_idx], m_map1);
        Graphics.Blit(m_fourierBuffer2[m_idx], m_map2);
    }