Exemplo n.º 1
0
 private static void AddQuads(Vector3[] vertices, Vector3[] origins, Vector2[] uvs, int index, float xOffset, float yOffset)
 {
     SpectrumResolver.AddQuad(vertices, origins, uvs, index, xOffset, yOffset, 0);
     SpectrumResolver.AddQuad(vertices, origins, uvs, index + 4, xOffset + 0.25f, yOffset, 3);
     SpectrumResolver.AddQuad(vertices, origins, uvs, index + 8, xOffset, yOffset + 0.25f, 1);
     SpectrumResolver.AddQuad(vertices, origins, uvs, index + 12, xOffset + 0.25f, yOffset + 0.25f, 2);
 }
Exemplo n.º 2
0
        private static Mesh CreateDownsamplingMesh()
        {
            Mesh mesh = new Mesh
            {
                name = "[PW Water] Spectrum Downsampling Mesh"
            };

            Vector3[] vertices = new Vector3[64];
            Vector3[] array    = new Vector3[64];
            Vector2[] array2   = new Vector2[64];
            int[]     array3   = new int[64];
            for (int i = 0; i < array3.Length; i++)
            {
                array3[i] = i;
            }
            SpectrumResolver.AddQuads(vertices, array, array2, 0, 0f, 0f);
            SpectrumResolver.AddQuads(vertices, array, array2, 16, 0.5f, 0f);
            SpectrumResolver.AddQuads(vertices, array, array2, 32, 0f, 0.5f);
            SpectrumResolver.AddQuads(vertices, array, array2, 48, 0.5f, 0.5f);
            mesh.vertices = vertices;
            mesh.normals  = array;
            mesh.uv       = array2;
            mesh.SetIndices(array3, MeshTopology.Quads, 0);
            return(mesh);
        }
Exemplo n.º 3
0
 private void AddOverlayToDirectionalSpectrum()
 {
     if (this._SpectrumDownsamplingMesh == null)
     {
         this._SpectrumDownsamplingMesh = SpectrumResolver.CreateDownsamplingMesh();
     }
     for (int i = this._OverlayedSpectra.Count - 1; i >= 0; i--)
     {
         WaterWavesSpectrumDataBase waterWavesSpectrumDataBase = this._OverlayedSpectra[i];
         Texture2D texture = waterWavesSpectrumDataBase.Texture;
         this._AnimationMaterial.SetFloat("_Weight", waterWavesSpectrumDataBase.Weight);
         this._AnimationMaterial.SetVector("_WindDirection", waterWavesSpectrumDataBase.WindDirection);
         float weatherSystemRadius = waterWavesSpectrumDataBase.WeatherSystemRadius;
         this._AnimationMaterial.SetVector("_WeatherSystemRadius", new Vector4(2f * weatherSystemRadius, weatherSystemRadius * weatherSystemRadius, 0f, 0f));
         Vector2 weatherSystemOffset = waterWavesSpectrumDataBase.WeatherSystemOffset;
         this._AnimationMaterial.SetVector("_WeatherSystemOffset", new Vector4(weatherSystemOffset.x, weatherSystemOffset.y, weatherSystemOffset.magnitude, 0f));
         Graphics.Blit(texture, this._DirectionalSpectrum, this._AnimationMaterial, 6);
     }
 }
Exemplo n.º 4
0
 private void RunFFTTask()
 {
     try
     {
         CpuFFT    cpuFFT    = new CpuFFT();
         Stopwatch stopwatch = new Stopwatch();
         bool      flag      = false;
         while (this._Run)
         {
             WaterTileSpectrum waterTileSpectrum = null;
             object            fftspectra        = this._FFTSpectra;
             lock (fftspectra)
             {
                 if (this._FFTSpectra.Count != 0)
                 {
                     if (this._FFTSpectrumIndex >= this._FFTSpectra.Count)
                     {
                         this._FFTSpectrumIndex = 0;
                     }
                     if (this._FFTSpectrumIndex == 0)
                     {
                         if ((float)stopwatch.ElapsedMilliseconds > this._FFTTimeStep * 900f)
                         {
                             if (flag)
                             {
                                 this._FFTTimeStep += 0.05f;
                             }
                             else
                             {
                                 flag = true;
                             }
                         }
                         else
                         {
                             flag = false;
                             if (this._FFTTimeStep > 0.2f)
                             {
                                 this._FFTTimeStep -= 0.001f;
                             }
                         }
                         stopwatch.Reset();
                         stopwatch.Start();
                     }
                     waterTileSpectrum = this._FFTSpectra[this._FFTSpectrumIndex++];
                 }
             }
             if (waterTileSpectrum == null)
             {
                 stopwatch.Reset();
                 Thread.Sleep(6);
             }
             else
             {
                 bool             flag2            = false;
                 SpectrumResolver spectrumResolver = waterTileSpectrum.WindWaves.SpectrumResolver;
                 if (spectrumResolver != null)
                 {
                     int   recentResultIndex = waterTileSpectrum.RecentResultIndex;
                     int   num           = (recentResultIndex + 2) % waterTileSpectrum.ResultsTiming.Length;
                     int   num2          = (recentResultIndex + 1) % waterTileSpectrum.ResultsTiming.Length;
                     float num3          = waterTileSpectrum.ResultsTiming[recentResultIndex];
                     float num4          = waterTileSpectrum.ResultsTiming[num];
                     float num5          = waterTileSpectrum.ResultsTiming[num2];
                     float lastFrameTime = spectrumResolver.LastFrameTime;
                     if (num4 <= lastFrameTime || num5 > lastFrameTime)
                     {
                         float loopDuration = waterTileSpectrum.WindWaves.LoopDuration;
                         float num6;
                         if (loopDuration != 0f)
                         {
                             num6 = Mathf.Round((num3 % loopDuration + 0.2f) / 0.2f) * 0.2f;
                         }
                         else if (num5 > lastFrameTime)
                         {
                             num6 = lastFrameTime + this._FFTTimeStep;
                         }
                         else
                         {
                             num6 = Mathf.Max(num3, lastFrameTime) + this._FFTTimeStep;
                         }
                         if (num6 != num5)
                         {
                             cpuFFT.Compute(waterTileSpectrum, num6, num2);
                             waterTileSpectrum.ResultsTiming[num2] = num6;
                             flag2 = true;
                         }
                         waterTileSpectrum.RecentResultIndex = num2;
                     }
                     if (!flag2)
                     {
                         stopwatch.Reset();
                         Thread.Sleep(3);
                     }
                 }
             }
         }
     }
     catch (Exception threadException)
     {
         this._ThreadException = threadException;
     }
 }