Exemplo n.º 1
0
 internal void Simulate()
 {
     Shader.SetGlobalFloat("_WaterHeight", this._Water.transform.position.y);
     if (base.transform.position.x != this._Position.x || base.transform.position.z != this._Position.z)
     {
         this.RenderStaticDepthTexture();
         this.MoveSimulation();
         this._Position = base.transform.position;
     }
     if (this._Buffers[0].Verify(false) || this._Buffers[1].Verify(false))
     {
         this._Buffers[0].Clear(Color.clear, false, true);
         this._Buffers[1].Clear(Color.clear, false, true);
     }
     RipplesShader.SetPrimary(this._Buffers[0], this._RipplesMaterial);
     RipplesShader.SetSecondary(this._Buffers[1], this._RipplesMaterial);
     WaterRipplesData.ShaderModes shaderMode = WaterQualitySettings.Instance.Ripples.ShaderMode;
     if (shaderMode != WaterRipplesData.ShaderModes.ComputeShader)
     {
         if (shaderMode == WaterRipplesData.ShaderModes.PixelShader)
         {
             this.SimulatePixelShader();
         }
     }
     else
     {
         this.SimulateComputeShader();
     }
 }
Exemplo n.º 2
0
        internal void UpdateShaderVariables()
        {
            if (this.Profile == null)
            {
                return;
            }
            if (this._DisplacementMaterial.IsNullReference(this))
            {
                return;
            }
            float num = (float)this._PixelsPerUnit / 32f;

            RipplesShader.SetPropagation(this.Profile.Propagation * num, this._RipplesMaterial);
            RipplesShader.SetStaticDepth(DefaultTextures.Get(Color.clear), this._RipplesMaterial);
            RipplesShader.SetDamping(this.Profile.Damping / 32f, this._RipplesMaterial);
            RipplesShader.SetGain(this.Profile.Gain, this._RipplesMaterial);
            RipplesShader.SetHeightGain(this.Profile.HeightGain, this._RipplesMaterial);
            RipplesShader.SetHeightOffset(this.Profile.HeightOffset, this._RipplesMaterial);
            float[] array = UltimateWater.Utils.Math.GaussianTerms(this.Profile.Sigma);
            GaussianShader.Term0 = array[0];
            GaussianShader.Term1 = array[1];
            GaussianShader.Term2 = array[2];
            this._DisplacementMaterial.SetFloat("_Amplitude", this.Profile.Amplitude * 0.05f);
            this._DisplacementMaterial.SetFloat("_Spread", this.Profile.Spread);
            this._DisplacementMaterial.SetFloat("_Multiplier", this.Profile.Multiplier);
            this._DisplacementMaterial.SetFloat("_Fadeout", (!this._Fade) ? 0f : 1f);
            this._DisplacementMaterial.SetFloat("_FadePower", this._FadePower);
        }
Exemplo n.º 3
0
        private void RenderStaticDepthTexture()
        {
            if (!this._EnableStaticCalculations)
            {
                if (this._StaticDepth != null)
                {
                    this._StaticDepth.Release();
                    this._StaticDepth = null;
                }
                return;
            }
            if (this._DepthCamera.IsNullReference(this))
            {
                return;
            }
            if (this._StaticDepth == null)
            {
                TextureUtility.RenderTextureDesc desc = new TextureUtility.RenderTextureDesc("[UWS] - Static Depth")
                {
                    Width  = this._StaticWidth,
                    Height = this._StaticHeight,
                    Depth  = 24,
                    Format = RenderTextureFormat.RFloat,
                    Filter = FilterMode.Point
                };
                this._StaticDepth = desc.CreateRenderTexture();
                this._StaticDepth.Clear(Color.clear, false, true);
            }
            float y             = this._DepthCamera.transform.localPosition.y;
            float nearClipPlane = this._DepthCamera.nearClipPlane;
            float farClipPlane  = this._DepthCamera.farClipPlane;

            WaterSimulationArea.SetDepthCameraParameters(ref this._DepthCamera, 40f, 0f, 80f);
            this._DepthCamera.cullingMask   = WaterQualitySettings.Instance.Ripples.StaticDepthMask;
            this._DepthCamera.targetTexture = this._StaticDepth;
            this._DepthCamera.SetReplacementShader(ShaderUtility.Instance.Get(ShaderList.Depth), string.Empty);
            this._DepthCamera.Render();
            WaterSimulationArea.SetDepthCameraParameters(ref this._DepthCamera, y, nearClipPlane, farClipPlane);
            RipplesShader.SetStaticDepth(this._StaticDepth, this._RipplesMaterial);
        }
Exemplo n.º 4
0
        private void RenderDepth()
        {
            if (this._DepthCamera.IsNullReference(this))
            {
                return;
            }
            TextureUtility.Swap <RenderTexture>(ref this._Depth, ref this._PreviousDepth);
            GL.PushMatrix();
            GL.modelview = this._DepthCamera.worldToCameraMatrix;
            GL.LoadProjectionMatrix(this._DepthCamera.projectionMatrix);
            this._CommandBuffer.Clear();
            this._CommandBuffer.SetRenderTarget(this._Depth);
            this._CommandBuffer.ClearRenderTarget(true, true, Color.clear);
            List <IWavesInteractive> interactions = DynamicWater.Interactions;

            for (int i = 0; i < interactions.Count; i++)
            {
                interactions[i].Render(this._CommandBuffer);
            }
            Graphics.ExecuteCommandBuffer(this._CommandBuffer);
            GL.PopMatrix();
            RipplesShader.SetDepth(this._Depth, this._RipplesMaterial);
            RipplesShader.SetPreviousDepth(this._PreviousDepth, this._RipplesMaterial);
        }
Exemplo n.º 5
0
 private void SimulateComputeShader()
 {
     RipplesShader.Size = this.Resolution;
     RipplesShader.Dispatch(this._Width, this._Height);
 }
Exemplo n.º 6
0
 public static void SetGain(float value, Material material)
 {
     RipplesShader.SetFloatShaderVariable("Gain", value, material);
 }
Exemplo n.º 7
0
 public static void SetHeightOffset(float value, Material material)
 {
     RipplesShader.SetFloatShaderVariable("HeightOffset", value, material);
 }
Exemplo n.º 8
0
 public static void SetPropagation(float value, Material material)
 {
     RipplesShader.SetFloatShaderVariable("Propagation", value, material);
 }
Exemplo n.º 9
0
 public static void SetDamping(float value, Material material)
 {
     RipplesShader.SetFloatShaderVariable("Damping", value, material);
 }
Exemplo n.º 10
0
 public static void SetSecondary(Texture value, Material material)
 {
     RipplesShader.SetTextureShaderVariable("MatrixT2", value, material);
 }
Exemplo n.º 11
0
 public static void SetStaticDepth(Texture value, Material material)
 {
     RipplesShader.SetTextureShaderVariable("StaticDepth", value, material);
 }
Exemplo n.º 12
0
 public static void SetPreviousDepth(Texture value, Material material)
 {
     RipplesShader.SetTextureShaderVariable("DepthT1", value, material);
 }