コード例 #1
0
 public Gerstner4(GerstnerWave wave0, GerstnerWave wave1, GerstnerWave wave2, GerstnerWave wave3)
 {
     this.wave0 = wave0;
     this.wave1 = wave1;
     this.wave2 = wave2;
     this.wave3 = wave3;
 }
コード例 #2
0
        public GerstnerWave[] SelectShorelineWaves(int count, float angle, float coincidenceRange)
        {
            var list = new List <FoundWave>();

            foreach (var spectrum in spectraDataList)
            {
                if (spectrum.Weight < 0.001f)
                {
                    continue;
                }

                spectrum.UpdateSpectralValues(windDirection, water.Directionality);

                lock (this)
                {
                    var shorelineCandidates = spectrum.ShorelineCandidates;
                    int countToAdd          = count;

                    for (int i = 0; i < shorelineCandidates.Length && countToAdd != 0; ++i)
                    {
                        float waveAngle = Mathf.Atan2(shorelineCandidates[i].nkx, shorelineCandidates[i].nky) * Mathf.Rad2Deg;

                        if (Mathf.Abs(Mathf.DeltaAngle(waveAngle, angle)) < coincidenceRange && shorelineCandidates[i].amplitude > 0.025f)
                        {
                            list.Add(new FoundWave(spectrum, shorelineCandidates[i]));
                            --countToAdd;
                        }
                    }
                }
            }

            list.Sort((a, b) => b.importance.CompareTo(a.importance));

            // compute texture offsets from the FFT shader to match Gerstner waves to FFT
            Vector2[] offsets = new Vector2[4];

            for (int i = 0; i < 4; ++i)
            {
                float tileSize = windWaves.TileSizes[i];

                offsets[i].x = tileSize + (0.5f / windWaves.FinalResolution) * tileSize;
                offsets[i].y = -tileSize + (0.5f / windWaves.FinalResolution) * tileSize;
            }

            int c         = Mathf.Min(list.Count, count);
            var gerstners = new GerstnerWave[c];

            for (int i = 0; i < c; ++i)
            {
                gerstners[i] = list[list.Count - i - 1].ToGerstner(offsets);                            // shoreline waves have a reversed order here...
            }
            return(gerstners);
        }
コード例 #3
0
        public GerstnerWave[] FindMostMeaningfulWaves(int count, bool mask)
        {
            var list = new List <FoundWave>();

            foreach (var spectrum in spectraDataList)
            {
                if (spectrum.Weight < 0.001f)
                {
                    continue;
                }

                spectrum.UpdateSpectralValues(windDirection, water.Directionality);

                lock (this)
                {
                    var cpuWaves = GetFilteredCpuWaves();
                    int numWaves = Mathf.Min(cpuWaves.Length, count);

                    for (int i = 0; i < numWaves; ++i)
                    {
                        list.Add(new FoundWave(spectrum, cpuWaves[i]));
                    }
                }
            }

            list.Sort((a, b) => b.importance.CompareTo(a.importance));

            // compute texture offsets from the FFT shader to match Gerstner waves to FFT
            Vector2[] offsets = new Vector2[4];

            for (int i = 0; i < 4; ++i)
            {
                float tileSize = windWaves.TileSizes[i];

                offsets[i].x = tileSize + (0.5f / windWaves.FinalResolution) * tileSize;
                offsets[i].y = -tileSize + (0.5f / windWaves.FinalResolution) * tileSize;
            }

            var gerstners = new GerstnerWave[count];

            for (int i = 0; i < count; ++i)
            {
                gerstners[i] = list[i].ToGerstner(offsets);
            }

            return(gerstners);
        }