public void OnValidate() { if (spectrumShader == null) { spectrumShader = Shader.Find("PlayWay Water/Spectrum/Water Spectrum"); } if (dynamicSmoothness != null) { dynamicSmoothness.OnValidate(this); } if (isActiveAndEnabled && Application.isPlaying) { CopyFrom = copyFrom; } #if UNITY_EDITOR if (copyFrom != null && !Application.isPlaying) { renderMode = copyFrom.renderMode; resolution = copyFrom.resolution; highPrecision = copyFrom.highPrecision; cpuWaveThreshold = copyFrom.cpuWaveThreshold; cpuMaxWaves = copyFrom.cpuMaxWaves; } #endif if (spectrumResolver != null) { ResolveFinalSettings(WaterQualitySettings.Instance.CurrentQualityLevel); waterWavesFFT.OnValidate(this); waterWavesGerstner.OnValidate(this); water.OnValidate(); } if (water != null) { UpdateShaderParams(); } }
private void CheckSupport() { if (highPrecision && (!SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RGFloat) || !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBFloat))) { finalHighPrecision = false; } if (!highPrecision && (!SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RGHalf) || !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf))) { if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RGFloat)) { finalHighPrecision = true; } else if (renderMode == WaveSpectrumRenderMode.FullFFT) { #if UNITY_EDITOR Debug.LogError("Your hardware doesn't support floating point render textures. FFT water waves won't work in editor."); #endif finalRenderMode = WaveSpectrumRenderMode.Gerstner; return; } } }
internal void ResolveFinalSettings(WaterQualityLevel quality) { this.CreateObjects(); WaterWavesMode wavesMode = quality.WavesMode; if (wavesMode == WaterWavesMode.DisallowAll) { this._WaterWavesFFT.Disable(); this._WaterWavesGerstner.Disable(); return; } bool flag = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBFloat) || SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf); int num = Mathf.Min(new int[] { this._Data.Resolution, quality.MaxSpectrumResolution, SystemInfo.maxTextureSize }); bool flag2 = this._Data.HighPrecision && quality.AllowHighPrecisionTextures && SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBFloat); WindWavesRenderMode windWavesMode = this._Water.ShaderSet.WindWavesMode; if (windWavesMode == WindWavesRenderMode.FullFFT && wavesMode == WaterWavesMode.AllowAll && flag) { this._FinalRenderMode = WaveSpectrumRenderMode.FullFFT; } else if (windWavesMode <= WindWavesRenderMode.GerstnerAndFFTNormals && wavesMode <= WaterWavesMode.AllowNormalFFT && flag) { this._FinalRenderMode = WaveSpectrumRenderMode.GerstnerAndFFTNormals; } else { this._FinalRenderMode = WaveSpectrumRenderMode.Gerstner; } if (this._FinalResolution != num) { lock (this) { this._FinalResolution = num; this._FinalHighPrecision = flag2; if (this._SpectrumResolver != null) { this._SpectrumResolver.OnMapsFormatChanged(true); } if (this.ResolutionChanged != null) { this.ResolutionChanged.Invoke(this); } } } else if (this._FinalHighPrecision != flag2) { lock (this) { this._FinalHighPrecision = flag2; if (this._SpectrumResolver != null) { this._SpectrumResolver.OnMapsFormatChanged(false); } } } WaveSpectrumRenderMode finalRenderMode = this._FinalRenderMode; if (finalRenderMode != WaveSpectrumRenderMode.FullFFT) { if (finalRenderMode != WaveSpectrumRenderMode.GerstnerAndFFTNormals) { if (finalRenderMode == WaveSpectrumRenderMode.Gerstner) { this._WaterWavesFFT.Disable(); this._WaterWavesGerstner.Enable(); } } else { this._WaterWavesFFT.RenderedMaps = WavesRendererFFT.MapType.Normal; this._WaterWavesFFT.Enable(); this._WaterWavesGerstner.Enable(); } } else { this._WaterWavesFFT.RenderedMaps = (WavesRendererFFT.MapType.Displacement | WavesRendererFFT.MapType.Normal); this._WaterWavesFFT.Enable(); this._WaterWavesGerstner.Disable(); } }
/// <summary> /// Resolves final component settings based on the desired values, quality settings and hardware limitations. /// </summary> internal void ResolveFinalSettings(WaterQualityLevel quality) { CreateObjects(); var wavesMode = quality.wavesMode; if (wavesMode == WaterWavesMode.DisallowAll) { enabled = false; return; } bool supportsFloats = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBFloat) || SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf); int finalResolution = Mathf.Min(resolution, quality.maxSpectrumResolution, SystemInfo.maxTextureSize); bool finalHighPrecision = highPrecision && quality.allowHighPrecisionTextures && SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBFloat); if (renderMode == WaveSpectrumRenderMode.FullFFT && wavesMode == WaterWavesMode.AllowAll && supportsFloats) { finalRenderMode = WaveSpectrumRenderMode.FullFFT; } else if (renderMode <= WaveSpectrumRenderMode.GerstnerAndFFTSlope && wavesMode <= WaterWavesMode.AllowSlopeFFT && supportsFloats) { finalRenderMode = WaveSpectrumRenderMode.GerstnerAndFFTSlope; } else { finalRenderMode = WaveSpectrumRenderMode.Gerstner; } if (this.finalResolution != finalResolution) { lock (this) { this.finalResolution = finalResolution; this.finalHighPrecision = finalHighPrecision; if (spectrumResolver != null) { spectrumResolver.OnMapsFormatChanged(true); } if (ResolutionChanged != null) { ResolutionChanged.Invoke(this); } } } else if (this.finalHighPrecision != finalHighPrecision) { lock (this) { this.finalHighPrecision = finalHighPrecision; if (spectrumResolver != null) { spectrumResolver.OnMapsFormatChanged(false); } } } switch (finalRenderMode) { case WaveSpectrumRenderMode.FullFFT: { waterWavesFFT.RenderedMaps = WavesRendererFFT.MapType.Displacement | WavesRendererFFT.MapType.Slope; waterWavesFFT.Enable(this); waterWavesGerstner.Disable(); break; } case WaveSpectrumRenderMode.GerstnerAndFFTSlope: { waterWavesFFT.RenderedMaps = WavesRendererFFT.MapType.Slope; waterWavesFFT.Enable(this); waterWavesGerstner.Enable(this); break; } case WaveSpectrumRenderMode.Gerstner: { waterWavesFFT.Disable(); waterWavesGerstner.Enable(this); break; } } }