Esempio n. 1
0
        internal void OnValidate(WindWaves windWaves)
        {
            if (fftShader == null)
            {
                fftShader = Shader.Find("PlayWay Water/Base/FFT");
            }

            if (fftUtilitiesShader == null)
            {
                fftUtilitiesShader = Shader.Find("PlayWay Water/Utilities/FFT Utilities");
            }

#if UNITY_EDITOR
            if (dx11FFT == null)
            {
                var guids = UnityEditor.AssetDatabase.FindAssets("\"DX11 FFT\" t:ComputeShader");

                if (guids.Length != 0)
                {
                    string path = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[0]);
                    dx11FFT = (ComputeShader)UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(ComputeShader));
                    UnityEditor.EditorUtility.SetDirty(windWaves);
                }
            }
#endif

            if (Application.isPlaying && enabled)
            {
                ResolveFinalSettings(WaterQualitySettings.Instance.CurrentQualityLevel);
            }
        }
Esempio n. 2
0
        void Awake()
        {
            windWaves = wavesParticleSystem.GetComponent <WindWaves>();

            OnValidate();
            wavesParticleSystem.RegisterPlugin(this);
        }
Esempio n. 3
0
 internal void OnValidate(WindWaves windWaves)
 {
     if (enabled)
     {
         FindBestWaves();
     }
 }
Esempio n. 4
0
        public void Start(WindWaves windWaves)
        {
            this.windWaves = windWaves;
            this.supported = CheckSupport();

            OnCopyModeChanged();
            OnValidate(windWaves);
        }
Esempio n. 5
0
        public void Start(Water water)
        {
            this.water        = water;
            this.windWaves    = water.GetComponent <WindWaves>();
            this.hasWindWaves = windWaves != null;

            bumpMapST         = Shader.PropertyToID("_BumpMap_ST");
            detailAlbedoMapST = Shader.PropertyToID("_DetailAlbedoMap_ST");
        }
Esempio n. 6
0
        private void OnResolutionChanged(WindWaves windWaves)
        {
            if (blankOutput != null)
            {
                Destroy(blankOutput);
                blankOutput = null;
            }

            resourcesReady = false;
        }
Esempio n. 7
0
        public void BuildShaderVariant(ShaderVariant variant, Water water, WindWaves windWaves, WaterQualityLevel qualityLevel)
        {
            OnValidate(windWaves);

            ResolveFinalSettings(qualityLevel);

            variant.SetWaterKeyword("_WAVES_FFT_SLOPE", enabled && renderedMaps == MapType.Slope);
            variant.SetUnityKeyword("_WAVES_ALIGN", (!water.Volume.Boundless && water.Volume.HasRenderableAdditiveVolumes && flattenMode == FlattenMode.Auto) || flattenMode == FlattenMode.ForcedOn);
            variant.SetUnityKeyword("_WAVES_FFT", enabled && (renderedMaps & MapType.Displacement) != 0);
        }
Esempio n. 8
0
        public SpectrumResolver(WindWaves windWaves, Shader spectrumShader) : base(windWaves, 4)
        {
            this.water     = windWaves.GetComponent <Water>();
            this.windWaves = windWaves;

            renderTimeId = Shader.PropertyToID("_RenderTime");

            animationMaterial           = new Material(spectrumShader);
            animationMaterial.hideFlags = HideFlags.DontSave;
            animationMaterial.SetFloat(renderTimeId, Time.time);
        }
Esempio n. 9
0
        void Start()
        {
            water     = GetComponent <Water>();
            windWaves = GetComponent <WindWaves>();
            windWaves.ResolutionChanged.AddListener(OnResolutionChanged);
            overlays = GetComponent <WaterOverlays>();

            supported = CheckSupport();

            if (!supported)
            {
                enabled = false;
                return;
            }
        }
Esempio n. 10
0
        internal void OnValidate(WindWaves windWaves)
        {
#if UNITY_EDITOR
            if (varianceShader == null)
            {
                var guids = UnityEditor.AssetDatabase.FindAssets("\"Spectral Variances\" t:ComputeShader");

                if (guids.Length != 0)
                {
                    string path = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[0]);
                    varianceShader = (ComputeShader)UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(ComputeShader));
                    UnityEditor.EditorUtility.SetDirty(windWaves);
                }
            }
#endif
        }
Esempio n. 11
0
        public SpectrumResolverCPU(WindWaves windWaves, int numScales)
        {
            this.water            = windWaves.GetComponent <Water>();
            this.windWaves        = windWaves;
            this.spectraDataCache = new Dictionary <WaterWavesSpectrum, WaterWavesSpectrumData>();
            this.spectraDataList  = new List <WaterWavesSpectrumData>();
            this.filteredCpuWaves = new WaterWave[0];
            this.numTiles         = numScales;
            this.cachedSeed       = windWaves.GetComponent <Water>().Seed;

            if (fftComputationCosts == null)
            {
                PrecomputeFFTCosts();
            }

            CreateSpectraLevels();
        }
Esempio n. 12
0
        void Awake()
        {
            runtimeCopyFrom = copyFrom;

            tileSizeId        = Shader.PropertyToID("_WaterTileSize");
            tileSizeScalesId  = Shader.PropertyToID("_WaterTileSizeScales");
            maxDisplacementId = Shader.PropertyToID("_MaxDisplacement");

            CheckSupport();

            if (!initialized)
            {
                Initialize();
            }

            ResolveFinalSettings(WaterQualitySettings.Instance.CurrentQualityLevel);
        }
Esempio n. 13
0
        internal void Enable(WindWaves windWaves)
        {
            if (enabled)
            {
                return;
            }

            enabled = true;

            this.water     = windWaves.GetComponent <Water>();
            this.windWaves = windWaves;

            if (Application.isPlaying)
            {
                water.ProfilesChanged.AddListener(OnProfilesChanged);
                FindBestWaves();
            }
        }
Esempio n. 14
0
        public void OnCopyModeChanged()
        {
            copyModeDirty = true;

            if (lastCopyFrom != null)
            {
                lastCopyFrom.WaterWavesFFT.ResourcesChanged -= ValidateResources;
            }

            if (windWaves.CopyFrom != null)
            {
                windWaves.CopyFrom.WaterWavesFFT.ResourcesChanged += ValidateResources;
            }

            lastCopyFrom = windWaves.CopyFrom;

            Dispose(false);
        }
Esempio n. 15
0
        void OnValidate()
        {
            if (globalFoamSimulationShader == null)
            {
                globalFoamSimulationShader = Shader.Find("PlayWay Water/Foam/Global");
            }

            if (localFoamSimulationShader == null)
            {
                localFoamSimulationShader = Shader.Find("PlayWay Water/Foam/Local");
            }

            supersampling = Mathf.ClosestPowerOfTwo(Mathf.RoundToInt(supersampling * 4096)) / 4096.0f;

            water     = GetComponent <Water>();
            windWaves = GetComponent <WindWaves>();
            overlays  = GetComponent <WaterOverlays>();
        }
Esempio n. 16
0
        private void ValidateVarianceTextures(WindWaves windWaves)
        {
            if (varianceTexture == null)
            {
                varianceTexture = CreateVarianceTexture(RenderTextureFormat.RGHalf);
            }

            if (!varianceTexture.IsCreated())
            {
                varianceTexture.Create();

                var water = windWaves.GetComponent <Water>();
                water.WaterMaterial.SetTexture("_SlopeVariance", varianceTexture);
                varianceShader.SetTexture(0, "_Variance", varianceTexture);

                lastResetIndex = 0;
                currentIndex   = 0;
            }
        }
Esempio n. 17
0
        void Start()
        {
            water     = GetComponent <Water>();
            windWaves = GetComponent <WindWaves>();
            overlays  = GetComponent <WaterOverlays>();

            foamParametersId = Shader.PropertyToID("_FoamParameters");
            foamIntensityId  = Shader.PropertyToID("_FoamIntensity");

            windWaves.ResolutionChanged.AddListener(OnResolutionChanged);

            resolution = Mathf.RoundToInt(windWaves.FinalResolution * supersampling);

            globalFoamSimulationMaterial           = new Material(globalFoamSimulationShader);
            globalFoamSimulationMaterial.hideFlags = HideFlags.DontSave;

            localFoamSimulationMaterial           = new Material(localFoamSimulationShader);
            localFoamSimulationMaterial.hideFlags = HideFlags.DontSave;

            firstFrame = true;
        }
Esempio n. 18
0
        internal void Enable(WindWaves windWaves)
        {
            if (enabled)
            {
                return;
            }

            if (dx11FFT != null)
            {
                defaultDx11Fft = dx11FFT;
            }
            else
            {
                dx11FFT = defaultDx11Fft;
            }

            enabled = true;

            this.water     = windWaves.GetComponent <Water>();
            this.windWaves = windWaves;

            OnCopyModeChanged();

            if (Application.isPlaying)
            {
                if (lastCopyFrom == null)
                {
                    ValidateResources();
                }

                windWaves.ResolutionChanged.AddListener(OnResolutionChanged);
            }

            OnValidate(windWaves);

            water.InvalidateMaterialKeywords();

            fftUtilitiesMaterial           = new Material(fftUtilitiesShader);
            fftUtilitiesMaterial.hideFlags = HideFlags.DontSave;
        }
Esempio n. 19
0
        private void OnResolutionChanged(WindWaves windWaves)
        {
            resolution = Mathf.RoundToInt(windWaves.FinalResolution * supersampling);

            Dispose(false);
        }
Esempio n. 20
0
 public void BuildShaderVariant(ShaderVariant variant, Water water, WindWaves windWaves, WaterQualityLevel qualityLevel)
 {
     variant.SetUnityKeyword("_WAVES_GERSTNER", enabled);
 }
Esempio n. 21
0
 public WaterWavesSpectrumData(Water water, WaterWavesSpectrum spectrum)
 {
     this.water     = water;
     this.windWaves = water.GetComponent <WindWaves>();
     this.spectrum  = spectrum;
 }
Esempio n. 22
0
 private void OnResolutionChanged(WindWaves windWaves)
 {
     Dispose(false);
     ValidateResources();
 }
Esempio n. 23
0
 private void OnWindDirectionChanged(WindWaves windWaves)
 {
     ResetComputations();
 }
Esempio n. 24
0
 public WaterTileSpectrum(WindWaves windWaves, int index)
 {
     this.windWaves = windWaves;
     this.water     = windWaves.GetComponent <Water>();
     this.tileIndex = index;
 }