예제 #1
0
 private void ValidateResources()
 {
     if (this._WindWaves.CopyFrom == null)
     {
         this.ValidateFFT(ref this._HeightFFT, (this._RenderedMaps & WavesRendererFFT.MapType.Displacement) != (WavesRendererFFT.MapType) 0, false);
         this.ValidateFFT(ref this._DisplacementFFT, (this._RenderedMaps & WavesRendererFFT.MapType.Displacement) != (WavesRendererFFT.MapType) 0, true);
         this.ValidateFFT(ref this._NormalFFT, (this._RenderedMaps & WavesRendererFFT.MapType.Normal) != (WavesRendererFFT.MapType) 0, true);
     }
     if (this._DisplacementMaps == null || this._NormalMaps == null)
     {
         RenderTexture[] displacementMaps;
         RenderTexture[] normalMaps;
         if (this._WindWaves.CopyFrom == null)
         {
             int finalResolution = this._WindWaves.FinalResolution;
             int num             = finalResolution << 1;
             this._SingleTargetCache = RenderTexturesCache.GetCache(num, num, 0, RenderTextureFormat.RHalf, true, this._HeightFFT is Dx11FFT, false);
             this._DoubleTargetCache = RenderTexturesCache.GetCache(num, num, 0, RenderTextureFormat.RGHalf, true, this._DisplacementFFT is Dx11FFT, false);
             if (this._DisplacementMaps == null && (this._RenderedMaps & WavesRendererFFT.MapType.Displacement) != (WavesRendererFFT.MapType) 0)
             {
                 this.CreateRenderTextures(ref this._DisplacementMaps, "[UWS] WavesRendererFFT - Water Displacement Map", RenderTextureFormat.ARGBHalf, 4, true);
             }
             if (this._NormalMaps == null && (this._RenderedMaps & WavesRendererFFT.MapType.Normal) != (WavesRendererFFT.MapType) 0)
             {
                 this.CreateRenderTextures(ref this._NormalMaps, "[UWS] WavesRendererFFT - Water Normal Map", RenderTextureFormat.ARGBHalf, 2, true);
             }
             displacementMaps = this._DisplacementMaps;
             normalMaps       = this._NormalMaps;
         }
         else
         {
             Water copyFrom = this._WindWaves.CopyFrom;
             if (copyFrom.WindWaves.WaterWavesFFT._WindWaves == null)
             {
                 copyFrom.WindWaves.ResolveFinalSettings(WaterQualitySettings.Instance.CurrentQualityLevel);
             }
             copyFrom.WindWaves.WaterWavesFFT.ValidateResources();
             displacementMaps = copyFrom.WindWaves.WaterWavesFFT._DisplacementMaps;
             normalMaps       = copyFrom.WindWaves.WaterWavesFFT._NormalMaps;
         }
         for (int i = 0; i < 4; i++)
         {
             string str = (i == 0) ? string.Empty : i.ToString();
             if (displacementMaps != null)
             {
                 string name = "_GlobalDisplacementMap" + str;
                 this._Water.Renderer.PropertyBlock.SetTexture(name, displacementMaps[i]);
             }
             if (i < 2 && normalMaps != null)
             {
                 string name2 = "_GlobalNormalMap" + str;
                 this._Water.Renderer.PropertyBlock.SetTexture(name2, normalMaps[i]);
             }
         }
         if (this.ResourcesChanged != null)
         {
             this.ResourcesChanged();
         }
     }
 }
예제 #2
0
        private void RenderReflection(Camera camera, Camera reflectionCamera)
        {
            reflectionCamera.cullingMask = this._Data.ReflectionMask;
            this.SetCameraSettings(camera, reflectionCamera);
            this._CurrentTarget            = this.GetRenderTexture(camera.pixelWidth, camera.pixelHeight, reflectionCamera);
            this._TemporaryTargets[camera] = this._CurrentTarget;
            TemporaryRenderTexture temporary = RenderTexturesCache.GetTemporary(this._CurrentTarget.Texture.width, this._CurrentTarget.Texture.height, 16, this._CurrentTarget.Texture.format, true, false, false);

            reflectionCamera.targetTexture         = temporary;
            reflectionCamera.transform.eulerAngles = PlanarReflection.CalculateReflectionAngles(camera);
            reflectionCamera.transform.position    = this.CalculateReflectionPosition(camera);
            float     w        = -this._Water.transform.position.y - 0.07f;
            Vector4   plane    = new Vector4(0f, 1f, 0f, w);
            Matrix4x4 matrix4x = Matrix4x4.zero;

            matrix4x = Reflection.CalculateReflectionMatrix(matrix4x, plane);
            Vector3 position = matrix4x.MultiplyPoint(camera.transform.position);

            reflectionCamera.worldToCameraMatrix = camera.worldToCameraMatrix * matrix4x;
            Vector4   clipPlane = Reflection.CameraSpacePlane(reflectionCamera, this._Water.transform.position, new Vector3(0f, 1f, 0f), 0.07f, 1f);
            Matrix4x4 matrix4x2 = camera.projectionMatrix;

            matrix4x2 = Reflection.CalculateObliqueMatrix(matrix4x2, clipPlane);
            reflectionCamera.projectionMatrix   = matrix4x2;
            reflectionCamera.transform.position = position;
            Vector3 eulerAngles = camera.transform.eulerAngles;

            reflectionCamera.transform.eulerAngles = new Vector3(-eulerAngles.x, eulerAngles.y, eulerAngles.z);
            reflectionCamera.clearFlags            = ((!this._Data.ReflectSkybox) ? CameraClearFlags.Color : CameraClearFlags.Skybox);
            if (this._Data.RenderShadows)
            {
                GL.invertCulling = true;
                reflectionCamera.Render();
                GL.invertCulling = false;
            }
            else
            {
                ShadowQuality shadows = QualitySettings.shadows;
                QualitySettings.shadows = ShadowQuality.Disable;
                GL.invertCulling        = true;
                reflectionCamera.Render();
                GL.invertCulling        = false;
                QualitySettings.shadows = shadows;
            }
            reflectionCamera.targetTexture = null;
            if (this._UtilitiesMaterial == null)
            {
                this._UtilitiesMaterial = new Material(this._UtilitiesShader)
                {
                    hideFlags = HideFlags.DontSave
                };
            }
            Graphics.Blit(temporary, this._CurrentTarget, this._UtilitiesMaterial, 0);
            temporary.Dispose();
        }
예제 #3
0
        private TemporaryRenderTexture GetRenderTexture(int width, int height, Camera reflectionCamera)
        {
            int  width2   = Mathf.ClosestPowerOfTwo(Mathf.RoundToInt((float)width * this._FinalResolutionMultiplier));
            int  height2  = Mathf.ClosestPowerOfTwo(Mathf.RoundToInt((float)height * this._FinalResolutionMultiplier));
            bool allowHDR = reflectionCamera.allowHDR;
            TemporaryRenderTexture temporary = RenderTexturesCache.GetTemporary(width2, height2, 0, (!allowHDR || !this._SystemSupportsHdr || !WaterProjectSettings.Instance.AllowFloatingPointMipMaps) ? RenderTextureFormat.ARGB32 : RenderTextureFormat.ARGBHalf, true, false, true);

            temporary.Texture.filterMode = FilterMode.Trilinear;
            temporary.Texture.wrapMode   = TextureWrapMode.Clamp;
            return(temporary);
        }
예제 #4
0
        internal void Smooth()
        {
            if (this.Profile.Sigma <= 0.1f)
            {
                return;
            }
            TemporaryRenderTexture temporary = RenderTexturesCache.GetTemporary(this._Width, this._Height, 0, WaterQualitySettings.Instance.Ripples.SimulationFormat, true, true, false);

            temporary.Verify(true);
            GaussianShader.VerticalInput  = this._Buffers[1];
            GaussianShader.VerticalOutput = temporary;
            GaussianShader.Dispatch(GaussianShader.KernelType.Vertical, this._Width, this._Height);
            GaussianShader.HorizontalInput  = temporary;
            GaussianShader.HorizontalOutput = this._Buffers[1];
            GaussianShader.Dispatch(GaussianShader.KernelType.Horizontal, this._Width, this._Height);
            temporary.Dispose();
        }
예제 #5
0
        private void OnRenderImage(RenderTexture source, RenderTexture destination)
        {
            Water water = (!this._HasWaterOverride) ? this._LocalWaterCamera.ContainingWater : this._WaterOverride;

            if (!this._LocalWaterCamera.enabled || water == null)
            {
                Graphics.Blit(source, destination);
                return;
            }
            source.filterMode = FilterMode.Bilinear;
            TemporaryRenderTexture temporary = RenderTexturesCache.GetTemporary(source.width, source.height, 0, (!(destination != null)) ? source.format : destination.format, true, false, false);

            temporary.Texture.filterMode = FilterMode.Bilinear;
            temporary.Texture.wrapMode   = TextureWrapMode.Clamp;
            this.RenderDepthScatter(source, temporary);
            this._Blur.TotalSize = water.Materials.UnderwaterBlurSize * this._CameraBlurScale;
            this._Blur.Apply(temporary);
            this.RenderDistortions(temporary, destination);
            temporary.Dispose();
        }
예제 #6
0
        private void RenderDistortions(Texture source, RenderTexture target)
        {
            Water water = (!this._HasWaterOverride) ? this._LocalWaterCamera.ContainingWater : this._WaterOverride;
            float underwaterDistortionsIntensity = water.Materials.UnderwaterDistortionsIntensity;

            if (underwaterDistortionsIntensity > 0f)
            {
                int width  = Camera.current.pixelWidth >> 2;
                int height = Camera.current.pixelHeight >> 2;
                TemporaryRenderTexture temporary = RenderTexturesCache.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, true, false, false);
                this.RenderDistortionMap(temporary);
                temporary.Texture.filterMode = FilterMode.Bilinear;
                this._ImeMaterial.SetTexture("_DistortionTex", temporary);
                this._ImeMaterial.SetFloat("_DistortionIntensity", underwaterDistortionsIntensity);
                GraphicsUtilities.Blit(source, target, this._ImeMaterial, 2, water.Renderer.PropertyBlock);
                temporary.Dispose();
            }
            else
            {
                Graphics.Blit(source, target);
            }
        }
예제 #7
0
        private void RenderMasks(Camera camera, WaterCamera waterCamera, MaterialPropertyBlock propertyBlock)
        {
            List <WaterVolumeSubtract> subtractiveVolumesDirect = this._Water.Volume.GetSubtractiveVolumesDirect();
            List <WaterVolumeAdd>      volumesDirect            = this._Water.Volume.GetVolumesDirect();

            if (waterCamera == null || !waterCamera.RenderVolumes || (subtractiveVolumesDirect.Count == 0 && volumesDirect.Count == 0 && this._Masks.Count == 0))
            {
                this.ReleaseTemporaryBuffers();
                return;
            }
            int    waterTempLayer      = WaterProjectSettings.Instance.WaterTempLayer;
            int    waterCollidersLayer = WaterProjectSettings.Instance.WaterCollidersLayer;
            Camera effectsCamera       = waterCamera.EffectsCamera;

            if (effectsCamera == null)
            {
                this.ReleaseTemporaryBuffers();
                return;
            }
            bool flag  = false;
            bool flag2 = false;
            bool flag3 = false;

            this.OnSharedSubtractiveMaskRender(ref flag, ref flag2, ref flag3);
            effectsCamera.CopyFrom(camera);
            effectsCamera.enabled = false;
            effectsCamera.GetComponent <WaterCamera>().enabled = false;
            effectsCamera.renderingPath    = RenderingPath.Forward;
            effectsCamera.depthTextureMode = DepthTextureMode.None;
            effectsCamera.cullingMask      = 1 << waterTempLayer;
            if (subtractiveVolumesDirect.Count != 0)
            {
                if (this._SubtractiveMaskTexture == null)
                {
                    this._SubtractiveMaskTexture = RenderTexture.GetTemporary(camera.pixelWidth, camera.pixelHeight, 24, (!SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBFloat)) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear, 1);
                }
                Graphics.SetRenderTarget(this._SubtractiveMaskTexture);
                int count = subtractiveVolumesDirect.Count;
                for (int i = 0; i < count; i++)
                {
                    subtractiveVolumesDirect[i].SetLayer(waterTempLayer);
                }
                TemporaryRenderTexture temporary = RenderTexturesCache.GetTemporary(camera.pixelWidth, camera.pixelHeight, 24, (!SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBFloat)) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGBFloat, true, false, false);
                effectsCamera.clearFlags      = CameraClearFlags.Color;
                effectsCamera.backgroundColor = new Color(0f, 0f, 0.5f, 0f);
                effectsCamera.targetTexture   = temporary;
                effectsCamera.RenderWithShader(this._VolumeFrontShader, "CustomType");
                GL.Clear(true, true, new Color(0f, 0f, 0f, 0f), 0f);
                Shader.SetGlobalTexture("_VolumesFrontDepth", temporary);
                effectsCamera.clearFlags    = CameraClearFlags.Nothing;
                effectsCamera.targetTexture = this._SubtractiveMaskTexture;
                effectsCamera.RenderWithShader(this._VolumeBackShader, "CustomType");
                temporary.Dispose();
                for (int j = 0; j < count; j++)
                {
                    subtractiveVolumesDirect[j].SetLayer(waterCollidersLayer);
                }
                propertyBlock.SetTexture(ShaderVariables.SubtractiveMask, this._SubtractiveMaskTexture);
            }
            if (volumesDirect.Count != 0)
            {
                this.OnSharedMaskAdditiveRender();
                if (this._AdditiveMaskTexture == null)
                {
                    this._AdditiveMaskTexture = RenderTexture.GetTemporary(camera.pixelWidth, camera.pixelHeight, 16, (!SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBFloat)) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear, 1);
                }
                Graphics.SetRenderTarget(this._AdditiveMaskTexture);
                GL.Clear(true, true, new Color(0f, 0f, 0f, 0f));
                int count2 = volumesDirect.Count;
                for (int k = 0; k < count2; k++)
                {
                    volumesDirect[k].SetLayer(waterTempLayer);
                    volumesDirect[k].EnableRenderers(false);
                }
                effectsCamera.clearFlags    = CameraClearFlags.Nothing;
                effectsCamera.targetTexture = this._AdditiveMaskTexture;
                effectsCamera.RenderWithShader((!waterCamera.IsInsideAdditiveVolume) ? this._VolumeFrontFastShader : this._VolumeFrontShader, "CustomType");
                effectsCamera.clearFlags    = CameraClearFlags.Nothing;
                effectsCamera.targetTexture = this._AdditiveMaskTexture;
                effectsCamera.RenderWithShader(this._VolumeBackShader, "CustomType");
                for (int l = 0; l < count2; l++)
                {
                    volumesDirect[l].SetLayer(waterCollidersLayer);
                }
                propertyBlock.SetTexture(ShaderVariables.AdditiveMask, this._AdditiveMaskTexture);
            }
            this.OnSharedMaskPostRender();
            effectsCamera.targetTexture = null;
        }