public void RenderOverlays(WaterOverlaysData overlays)
 {
     if (enabled)
     {
         RenderParticles(overlays);
     }
 }
Exemple #2
0
        public void RenderOverlays(WaterOverlaysData overlays)
        {
            if (!enabled)
            {
                return;
            }

            CheckResources();
            SpawnWindWavesParticlesLocal(overlays);
            GenerateLocalFoam(overlays);
        }
Exemple #3
0
        public void RenderOverlays(WaterOverlaysData overlays)
        {
            if (!enabled)
            {
                return;
            }

            localFoamSimulationMaterial.CopyPropertiesFromMaterial(water.WaterMaterial);

            float t = foamThreshold * overlays.DynamicDisplacementMap.width / 2048.0f * 0.7f;

            localFoamSimulationMaterial.SetVector(foamParametersId, new Vector4(foamIntensity * 0.6f, t, 0.0f, foamFadingFactor));
            localFoamSimulationMaterial.SetTexture("_DisplacementMap", overlays.DynamicDisplacementMap);
            localFoamSimulationMaterial.SetTexture("_SlopeMapPrevious", overlays.SlopeMapPrevious);
            localFoamSimulationMaterial.SetTexture("_TotalDisplacementMap", overlays.GetTotalDisplacementMap());
            localFoamSimulationMaterial.SetVector("_Offset", new Vector4((UnityEngine.Random.value - 0.5f) * 0.001f, (UnityEngine.Random.value - 0.5f) * 0.001f, 0.0f, 0.0f));
            Graphics.Blit(overlays.SlopeMapPrevious, overlays.SlopeMap, localFoamSimulationMaterial, overlays.Initialization ? 1 : 0);
        }
Exemple #4
0
        private void RenderInteractions(WaterOverlaysData overlays)
        {
            int numRenderers = shorelineRenderers.Count;

            if (numRenderers == 0)
            {
                return;
            }

            Rect rect = overlays.Camera.LocalMapsRect;

            if (rect.width == 0.0f)
            {
                return;
            }

            var effectsCamera = overlays.Camera.EffectsCamera;

            effectsCamera.enabled            = false;
            effectsCamera.depthTextureMode   = DepthTextureMode.None;
            effectsCamera.orthographic       = true;
            effectsCamera.orthographicSize   = rect.width * 0.5f;
            effectsCamera.cullingMask        = 1 << WaterProjectSettings.Instance.WaterTempLayer;
            effectsCamera.farClipPlane       = 2000.0f;
            effectsCamera.clearFlags         = CameraClearFlags.Nothing;
            effectsCamera.transform.position = new Vector3(rect.center.x, 1000.0f, rect.center.y);
            effectsCamera.transform.rotation = Quaternion.LookRotation(new Vector3(0.0f, -1.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f));
            effectsCamera.targetTexture      = overlays.SlopeMap;

            for (int i = 0; i < numRenderers; ++i)
            {
                if (((1 << shorelineRenderers[i].Layer) & interactionMask) != 0)
                {
                    shorelineRenderers[i].InteractionRenderer.enabled = true;
                }
            }

            effectsCamera.Render();

            for (int i = 0; i < numRenderers; ++i)
            {
                shorelineRenderers[i].InteractionRenderer.enabled = false;
            }
        }
Exemple #5
0
        private void SpawnWindWavesParticlesLocal(WaterOverlaysData overlays)
        {
            sprayLocalGeneratorMaterial.CopyPropertiesFromMaterial(water.WaterMaterial);
            sprayLocalGeneratorMaterial.SetVector("_SurfaceOffset", -water.SurfaceOffset);
            sprayLocalGeneratorMaterial.SetVector("_Params", new Vector4(spawnThreshold * 0.25835f, spawnSkipRatio, 0.0f, scale * 0.455f));
            sprayLocalGeneratorMaterial.SetTexture("_TotalDisplacementMap", overlays.GetTotalDisplacementMap());
            sprayLocalGeneratorMaterial.SetTexture("_LocalSlopeMap", overlays.SlopeMapPrevious);
            sprayLocalGeneratorMaterial.SetTexture("_LocalUtilityMap", overlays.UtilityMap);

            float size       = overlays.Camera.LocalMapsRect.width / water.UniformWaterScale;
            int   iterations = 7 + Mathf.CeilToInt(size / 650.0f);

            iterations = Mathf.Clamp(iterations, 8, 12);

            sprayLocalGeneratorMaterial.SetInt("_Iterations", iterations);

            Graphics.SetRandomWriteTarget(1, particlesA);
            Graphics.Blit(null, blankOutput, sprayLocalGeneratorMaterial, 0);
            Graphics.ClearRandomWriteTargets();
        }
Exemple #6
0
        public WaterOverlaysData GetCameraOverlaysData(Camera camera)
        {
            WaterOverlaysData overlaysData;

            if (!buffers.TryGetValue(camera, out overlaysData))
            {
                int resolution = Mathf.NextPowerOfTwo((camera.pixelWidth + camera.pixelHeight) >> 1);
                buffers[camera] = overlaysData = new WaterOverlaysData(this, WaterCamera.GetWaterCamera(camera), resolution, antialiasing);

                RenderInteractions(overlaysData);
                overlaysData.SwapSlopeMaps();

                for (int i = 0; i < overlayRenderers.Length; ++i)
                {
                    overlayRenderers[i].RenderOverlays(overlaysData);
                }

                overlaysData.Initialization = false;
            }

            return(overlaysData);
        }
        private void RenderParticles(WaterOverlaysData overlays)
        {
            if (overlays.UtilityMap == null)
            {
                Graphics.SetRenderTarget(new RenderBuffer[] { overlays.DynamicDisplacementMap.colorBuffer, overlays.SlopeMap.colorBuffer }, overlays.DynamicDisplacementMap.depthBuffer);
            }
            else
            {
                Graphics.SetRenderTarget(new RenderBuffer[] { overlays.DynamicDisplacementMap.colorBuffer, overlays.SlopeMap.colorBuffer, overlays.UtilityMap.colorBuffer }, overlays.DynamicDisplacementMap.depthBuffer);
            }

            //var spray = GetComponent<WaterSpray>();
            //Graphics.SetRandomWriteTarget(2, spray.ParticlesBuffer);
            Vector4 localMapsShaderCoords = overlays.Camera.LocalMapsShaderCoords;
            float   uniformWaterScale     = GetComponent <Water>().UniformWaterScale;

            waterWavesParticlesMaterial.SetFloat("_WaterScale", uniformWaterScale);
            waterWavesParticlesMaterial.SetVector("_LocalMapsCoords", localMapsShaderCoords);
            waterWavesParticlesMaterial.SetPass(0);

            particles.Render(overlays.Camera.LocalMapsRect);
            //Graphics.ClearRandomWriteTargets();
        }
Exemple #8
0
        private void GenerateLocalFoam(WaterOverlaysData overlays)
        {
            Graphics.SetRenderTarget(overlays.DynamicDisplacementMap);

            sprayToFoamMaterial.SetBuffer("_Particles", particlesA);
            sprayToFoamMaterial.SetVector("_LocalMapsCoords", overlays.Camera.LocalMapsShaderCoords);
            sprayToFoamMaterial.SetFloat("_UniformWaterScale", water.UniformWaterScale);

            Vector4 particleParams = sprayMaterial.GetVector("_ParticleParams");

            particleParams.x *= 8.0f;
            particleParams.z  = 1.0f;
            sprayToFoamMaterial.SetVector("_ParticleParams", particleParams);

            int numMeshes = propertyBlocks.Length;

            for (int i = 0; i < numMeshes; ++i)
            {
                sprayToFoamMaterial.SetFloat("_ParticleOffset", i * 65535);
                sprayToFoamMaterial.SetPass(0);

                Graphics.DrawMeshNow(mesh, Matrix4x4.identity, 0);
            }
        }