コード例 #1
0
 public void UpdateSpectralValues(Vector2 windDirection, float directionality)
 {
     this.ValidateSpectrumData();
     if (this._CpuWavesDirty)
     {
         lock (this)
         {
             if (this.CpuWaves != null && this._CpuWavesDirty)
             {
                 object cpuWaves = this.CpuWaves;
                 lock (cpuWaves)
                 {
                     this._CpuWavesDirty = false;
                     float       directionalityInv           = 1f - directionality;
                     float       horizontalDisplacementScale = this._Water.Materials.HorizontalDisplacementScale;
                     int         finalResolution             = this._WindWaves.FinalResolution;
                     bool        mostlySorted = Vector2.Dot(this._LastWindDirection, windDirection) >= 0.97f;
                     WaterWave[] cpuWaves2    = this.CpuWaves;
                     for (int i = 0; i < cpuWaves2.Length; i++)
                     {
                         cpuWaves2[i].UpdateSpectralValues(this.SpectrumValues, windDirection, directionalityInv, finalResolution, horizontalDisplacementScale);
                     }
                     WaterWavesSpectrumDataBase.SortCpuWaves(cpuWaves2, mostlySorted);
                     WaterWave[] shorelineCandidates = this.ShorelineCandidates;
                     for (int j = 0; j < shorelineCandidates.Length; j++)
                     {
                         shorelineCandidates[j].UpdateSpectralValues(this.SpectrumValues, windDirection, directionalityInv, finalResolution, horizontalDisplacementScale);
                     }
                     this._LastWindDirection = windDirection;
                 }
             }
         }
     }
 }
コード例 #2
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);
     }
 }
コード例 #3
0
 public bool SetResolveMode(bool resolveByFFT, int resolution)
 {
     if (this.ResolveByFFT != resolveByFFT || (this.ResolveByFFT && this._ResolutionFFT != resolution))
     {
         if (resolveByFFT)
         {
             lock (this)
             {
                 bool flag = this.WindWaves.LoopDuration != 0f;
                 int  num  = (!flag) ? 4 : ((int)(this.WindWaves.LoopDuration * 5f + 0.6f));
                 this._ResolutionFFT = resolution;
                 this._MipIndexFFT   = WaterWavesSpectrumDataBase.GetMipIndex(resolution);
                 int num2 = resolution * resolution;
                 this.DirectionalSpectrum = new Vector2[num2];
                 this.Displacements       = new Vector2[num][];
                 this.ForceAndHeight      = new Vector4[num][];
                 this.ResultsTiming       = new float[num];
                 this.SetDirty();
                 this._CachedTime = float.NegativeInfinity;
                 for (int i = 0; i < num; i++)
                 {
                     this.Displacements[i]  = new Vector2[num2];
                     this.ForceAndHeight[i] = new Vector4[num2];
                 }
                 if (!this.ResolveByFFT)
                 {
                     WaterAsynchronousTasks.Instance.AddFFTComputations(this);
                     this.ResolveByFFT = true;
                 }
             }
         }
         else
         {
             WaterAsynchronousTasks.Instance.RemoveFFTComputations(this);
             this.ResolveByFFT = false;
         }
         return(true);
     }
     return(false);
 }
コード例 #4
0
ファイル: CpuFFT.cs プロジェクト: looki666/Green-Hell
        private void ComputeDirectionalSpectra(int scaleIndex, Vector2[] directional, Vector3[] kMap)
        {
            float num = 1f - this._TargetSpectrum.WindWaves.SpectrumDirectionality;
            Dictionary <WaterWavesSpectrum, WaterWavesSpectrumData> cachedSpectraDirect = this._TargetSpectrum.WindWaves.SpectrumResolver.GetCachedSpectraDirect();
            int     num2            = this._Resolution * this._Resolution;
            int     num3            = this._Resolution >> 1;
            int     finalResolution = this._TargetSpectrum.WindWaves.FinalResolution;
            Vector2 windDirection   = this._TargetSpectrum.WindWaves.SpectrumResolver.WindDirection;

            for (int i = 0; i < num2; i++)
            {
                directional[i].x = 0f;
                directional[i].y = 0f;
            }
            object obj = cachedSpectraDirect;

            lock (obj)
            {
                Dictionary <WaterWavesSpectrum, WaterWavesSpectrumData> .ValueCollection.Enumerator enumerator = cachedSpectraDirect.Values.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    WaterWavesSpectrumData waterWavesSpectrumData = enumerator.Current;
                    if (waterWavesSpectrumData != null)
                    {
                        float weight = waterWavesSpectrumData.Weight;
                        if (waterWavesSpectrumData.GetStandardDeviation() * weight > 0.003f)
                        {
                            int       num4  = 0;
                            int       num5  = 0;
                            Vector3[] array = waterWavesSpectrumData.SpectrumValues[scaleIndex];
                            for (int j = 0; j < this._Resolution; j++)
                            {
                                if (j == num3)
                                {
                                    num5 += (finalResolution - this._Resolution) * finalResolution;
                                }
                                for (int k = 0; k < this._Resolution; k++)
                                {
                                    if (k == num3)
                                    {
                                        num5 += finalResolution - this._Resolution;
                                    }
                                    float x = kMap[num4].x;
                                    float y = kMap[num4].y;
                                    if (x == 0f && y == 0f)
                                    {
                                        x = windDirection.x;
                                        y = windDirection.y;
                                    }
                                    float num6 = windDirection.x * x + windDirection.y * y;
                                    float num7 = Mathf.Sqrt(1f + array[num5].z * (2f * num6 * num6 - 1f));
                                    if (num6 < 0f)
                                    {
                                        num7 *= num;
                                    }
                                    float num8 = num7 * weight;
                                    int   num9 = num4;
                                    directional[num9].x = directional[num9].x + array[num5].x * num8;
                                    int num10 = num4++;
                                    directional[num10].y = directional[num10].y + array[num5++].y * num8;
                                }
                            }
                        }
                    }
                }
                enumerator.Dispose();
            }
            List <WaterWavesSpectrumDataBase> overlayedSpectraDirect = this._TargetSpectrum.WindWaves.SpectrumResolver.GetOverlayedSpectraDirect();
            object obj2 = overlayedSpectraDirect;

            lock (obj2)
            {
                for (int l = overlayedSpectraDirect.Count - 1; l >= 0; l--)
                {
                    WaterWavesSpectrumDataBase waterWavesSpectrumDataBase = overlayedSpectraDirect[l];
                    float weight2 = waterWavesSpectrumDataBase.Weight;
                    windDirection = waterWavesSpectrumDataBase.WindDirection;
                    if (waterWavesSpectrumDataBase.GetStandardDeviation() * weight2 > 0.003f)
                    {
                        float     x2 = waterWavesSpectrumDataBase.WeatherSystemOffset.x;
                        float     y2 = waterWavesSpectrumDataBase.WeatherSystemOffset.y;
                        float     weatherSystemRadius = waterWavesSpectrumDataBase.WeatherSystemRadius;
                        float     num11  = Mathf.Sqrt(x2 * x2 + y2 * y2);
                        float     num12  = 0.84f * Mathf.Pow((float)Math.Tanh((double)Mathf.Pow(num11 / 22000f, 0.4f)), -0.75f);
                        float     num13  = waterWavesSpectrumDataBase.Gravity * FastMath.Pow2(num12 / 10f);
                        int       num14  = 0;
                        int       num15  = 0;
                        Vector3[] array2 = waterWavesSpectrumDataBase.SpectrumValues[scaleIndex];
                        for (int m = 0; m < this._Resolution; m++)
                        {
                            if (m == num3)
                            {
                                num15 += (finalResolution - this._Resolution) * finalResolution;
                            }
                            int n = 0;
                            while (n < this._Resolution)
                            {
                                if (n == num3)
                                {
                                    num15 += finalResolution - this._Resolution;
                                }
                                float x3 = kMap[num14].x;
                                float y3 = kMap[num14].y;
                                if (x3 == 0f && y3 == 0f)
                                {
                                    x3 = windDirection.x;
                                    y3 = windDirection.y;
                                }
                                float num16 = windDirection.x * x3 + windDirection.y * y3;
                                float num17 = Mathf.Sqrt(1f + array2[num15].z * (2f * num16 * num16 - 1f));
                                if (num16 < 0f)
                                {
                                    num17 *= num;
                                }
                                float num18 = num17 * weight2;
                                if (weatherSystemRadius == 0f)
                                {
                                    goto IL_5EA;
                                }
                                float z     = kMap[num14].z;
                                float num19 = -2f * x3 * x2 + -2f * y3 * y2;
                                float num20 = x2 * x2 + y2 * y2 - weatherSystemRadius * weatherSystemRadius;
                                float num21 = num19 * num19 - 4f * num20;
                                if (num21 < 0f)
                                {
                                    directional[num14].x   = 0f;
                                    directional[num14++].y = 0f;
                                    num15++;
                                }
                                else
                                {
                                    float num22 = Mathf.Sqrt(num21);
                                    float num23 = (num22 - num19) * 0.5f;
                                    float num24 = (-num22 - num19) * 0.5f;
                                    if (num23 > 0f && num24 > 0f)
                                    {
                                        directional[num14].x   = 0f;
                                        directional[num14++].y = 0f;
                                        num15++;
                                    }
                                    else
                                    {
                                        Vector2 a     = new Vector2(x3 * num23, y3 * num23);
                                        Vector2 b     = new Vector2(x3 * num24, y3 * num24);
                                        float   num25 = Vector2.Distance(a, b) / (weatherSystemRadius * 2f);
                                        num18 *= num25;
                                        if (num23 * num24 > 0f)
                                        {
                                            float num26 = Mathf.Min(-num23, -num24);
                                            float num27 = z / num13;
                                            float num28 = Mathf.Exp(-1E-06f * num26 * num27 * num27);
                                            num18 *= num28;
                                            goto IL_5EA;
                                        }
                                        goto IL_5EA;
                                    }
                                }
IL_63E:
                                n++;
                                continue;
IL_5EA:
                                int num29            = num14;
                                directional[num29].x = directional[num29].x + array2[num15].x * num18;
                                int num30 = num14++;
                                directional[num30].y = directional[num30].y + array2[num15++].y * num18;
                                goto IL_63E;
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
        private void AnalyzeSpectrum()
        {
            int finalResolution    = this._WindWaves.FinalResolution;
            int num                = finalResolution >> 1;
            int num2               = Mathf.RoundToInt(Mathf.Log((float)(finalResolution >> 1), 2f)) - 4;
            Heap <WaterWave> heap  = new Heap <WaterWave>();
            Heap <WaterWave> heap2 = new Heap <WaterWave>();

            this._StdDev = 0f;
            for (byte b = 0; b < 4; b += 1)
            {
                Vector3[] array   = this.SpectrumValues[(int)b];
                float[]   array2  = this._StandardDeviationData[(int)b] = new float[num2 + 1];
                float     num3    = 6.28318548f / this._TileSize;
                float     offsetX = this._TileSize + 0.5f / (float)finalResolution * this._TileSize;
                float     offsetZ = -this._TileSize + 0.5f / (float)finalResolution * this._TileSize;
                for (int i = 0; i < finalResolution; i++)
                {
                    float  num4 = num3 * (float)(i - num);
                    ushort num5 = (ushort)((i + num) % finalResolution);
                    ushort num6 = (ushort)((int)num5 * finalResolution);
                    for (int j = 0; j < finalResolution; j++)
                    {
                        float   num7   = num3 * (float)(j - num);
                        ushort  num8   = (ushort)((j + num) % finalResolution);
                        Vector3 vector = array[(int)(num6 + num8)];
                        float   num9   = vector.x * vector.x + vector.y * vector.y;
                        float   num10  = Mathf.Sqrt(num9);
                        float   num11  = Mathf.Sqrt(num4 * num4 + num7 * num7);
                        float   w      = Mathf.Sqrt(this._Gravity * num11);
                        if (num10 >= 0.0025f)
                        {
                            heap2.Insert(new WaterWave(b, offsetX, offsetZ, num5, num8, num4, num7, num11, w, num10));
                            if (heap2.Count > 100)
                            {
                                heap2.ExtractMax();
                            }
                        }
                        if (num10 > 0.025f)
                        {
                            heap.Insert(new WaterWave(b, offsetX, offsetZ, num5, num8, num4, num7, num11, w, num10));
                            if (heap.Count > 200)
                            {
                                heap.ExtractMax();
                            }
                        }
                        int mipIndex = WaterWavesSpectrumDataBase.GetMipIndex(Mathf.Max(Mathf.Min((int)num5, finalResolution - (int)num5 - 1), Mathf.Min((int)num8, finalResolution - (int)num8 - 1)));
                        array2[mipIndex] += num9;
                    }
                }
                for (int k = 0; k < array2.Length; k++)
                {
                    array2[k]     = Mathf.Sqrt(2f * array2[k]);
                    this._StdDev += array2[k];
                }
            }
            this.CpuWaves = heap2.ToArray <WaterWave>();
            WaterWavesSpectrumDataBase.SortCpuWaves(this.CpuWaves, false);
            this.ShorelineCandidates = heap.ToArray <WaterWave>();
            Array.Sort <WaterWave>(this.ShorelineCandidates);
        }
コード例 #6
0
 public override void RemoveSpectrum(WaterWavesSpectrumDataBase spectrum)
 {
     base.RemoveSpectrum(spectrum);
     this._DirectionalSpectrumDirty = true;
 }