private void OnPreCull() { this.cam = (Camera)((Component)this).GetComponent <Camera>(); int count1 = LuxWater_Projector.FoamProjectors.Count; int count2 = LuxWater_Projector.NormalProjectors.Count; if (count1 + count2 == 0) { if (LuxWater_ProjectorRenderer.cb_Foam != null) { LuxWater_ProjectorRenderer.cb_Foam.Clear(); } if (LuxWater_ProjectorRenderer.cb_Normals != null) { LuxWater_ProjectorRenderer.cb_Normals.Clear(); } Shader.DisableKeyword("USINGWATERPROJECTORS"); } else { Shader.EnableKeyword("USINGWATERPROJECTORS"); Matrix4x4 projectionMatrix = this.cam.get_projectionMatrix(); Matrix4x4 worldToCameraMatrix = this.cam.get_worldToCameraMatrix(); Matrix4x4 worldToProjectMatrix = Matrix4x4.op_Multiply(projectionMatrix, worldToCameraMatrix); int pixelWidth = this.cam.get_pixelWidth(); int pixelHeight = this.cam.get_pixelHeight(); GeomUtil.CalculateFrustumPlanes(this.frustumPlanes, worldToProjectMatrix); int num1 = Mathf.FloorToInt((float)(pixelWidth / (int)this.FoamBufferResolution)); int num2 = Mathf.FloorToInt((float)(pixelHeight / (int)this.FoamBufferResolution)); if (!Object.op_Implicit((Object)this.ProjectedFoam)) { this.ProjectedFoam = new RenderTexture(num1, num2, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)1); } else if (((Texture)this.ProjectedFoam).get_width() != num1) { Object.DestroyImmediate((Object)this.ProjectedFoam); this.ProjectedFoam = new RenderTexture(num1, num2, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)1); } GL.PushMatrix(); GL.set_modelview(worldToCameraMatrix); GL.LoadProjectionMatrix(projectionMatrix); LuxWater_ProjectorRenderer.cb_Foam.Clear(); LuxWater_ProjectorRenderer.cb_Foam.SetRenderTarget(RenderTargetIdentifier.op_Implicit((Texture)this.ProjectedFoam)); LuxWater_ProjectorRenderer.cb_Foam.ClearRenderTarget(true, true, new Color(0.0f, 0.0f, 0.0f, 0.0f), 1f); this.drawnFoamProjectors = 0; for (int index = 0; index < count1; ++index) { LuxWater_Projector foamProjector = LuxWater_Projector.FoamProjectors[index]; this.tempBounds = foamProjector.m_Rend.get_bounds(); if (GeometryUtility.TestPlanesAABB(this.frustumPlanes, this.tempBounds)) { LuxWater_ProjectorRenderer.cb_Foam.DrawRenderer(foamProjector.m_Rend, foamProjector.m_Mat); ++this.drawnFoamProjectors; } } Graphics.ExecuteCommandBuffer(LuxWater_ProjectorRenderer.cb_Foam); Shader.SetGlobalTexture(this._LuxWater_FoamOverlayPID, (Texture)this.ProjectedFoam); int num3 = Mathf.FloorToInt((float)(pixelWidth / (int)this.NormalBufferResolution)); int num4 = Mathf.FloorToInt((float)(pixelHeight / (int)this.NormalBufferResolution)); if (!Object.op_Implicit((Object)this.ProjectedNormals)) { this.ProjectedNormals = new RenderTexture(num3, num4, 0, (RenderTextureFormat)2, (RenderTextureReadWrite)1); } else if (((Texture)this.ProjectedNormals).get_width() != num3) { Object.DestroyImmediate((Object)this.ProjectedNormals); this.ProjectedNormals = new RenderTexture(num3, num4, 0, (RenderTextureFormat)2, (RenderTextureReadWrite)1); } LuxWater_ProjectorRenderer.cb_Normals.Clear(); LuxWater_ProjectorRenderer.cb_Normals.SetRenderTarget(RenderTargetIdentifier.op_Implicit((Texture)this.ProjectedNormals)); LuxWater_ProjectorRenderer.cb_Normals.ClearRenderTarget(true, true, new Color(0.0f, 0.0f, 0.0f, 0.0f), 1f); this.drawnNormalProjectors = 0; for (int index = 0; index < count2; ++index) { LuxWater_Projector normalProjector = LuxWater_Projector.NormalProjectors[index]; this.tempBounds = normalProjector.m_Rend.get_bounds(); if (GeometryUtility.TestPlanesAABB(this.frustumPlanes, this.tempBounds)) { LuxWater_ProjectorRenderer.cb_Normals.DrawRenderer(normalProjector.m_Rend, normalProjector.m_Mat); ++this.drawnNormalProjectors; } } Graphics.ExecuteCommandBuffer(LuxWater_ProjectorRenderer.cb_Normals); Shader.SetGlobalTexture(this._LuxWater_NormalOverlayPID, (Texture)this.ProjectedNormals); GL.PopMatrix(); } }
private void OnPreRender() { this.cam = base.GetComponent <Camera>(); int count = LuxWater_Projector.FoamProjectors.Count; int count2 = LuxWater_Projector.NormalProjectors.Count; if (count + count2 == 0) { if (LuxWater_ProjectorRenderer.cb_Foam != null) { LuxWater_ProjectorRenderer.cb_Foam.Clear(); } if (LuxWater_ProjectorRenderer.cb_Normals != null) { LuxWater_ProjectorRenderer.cb_Normals.Clear(); } Shader.DisableKeyword("USINGWATERPROJECTORS"); return; } Shader.EnableKeyword("USINGWATERPROJECTORS"); Matrix4x4 projectionMatrix = this.cam.projectionMatrix; Matrix4x4 worldToCameraMatrix = this.cam.worldToCameraMatrix; Matrix4x4 worldToProjectMatrix = projectionMatrix * worldToCameraMatrix; int pixelWidth = this.cam.pixelWidth; int pixelHeight = this.cam.pixelHeight; GeomUtil.CalculateFrustumPlanes(this.frustumPlanes, worldToProjectMatrix); int num = Mathf.FloorToInt((float)(pixelWidth / (int)this.FoamBufferResolution)); int height = Mathf.FloorToInt((float)(pixelHeight / (int)this.FoamBufferResolution)); if (!this.ProjectedFoam) { this.ProjectedFoam = new RenderTexture(num, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); Shader.SetGlobalTexture(this._LuxWater_FoamOverlayPID, this.ProjectedFoam); } else if (this.ProjectedFoam.width != num) { this.ProjectedFoam = new RenderTexture(num, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); } GL.PushMatrix(); GL.modelview = worldToCameraMatrix; GL.LoadProjectionMatrix(projectionMatrix); LuxWater_ProjectorRenderer.cb_Foam.Clear(); LuxWater_ProjectorRenderer.cb_Foam.SetRenderTarget(this.ProjectedFoam); LuxWater_ProjectorRenderer.cb_Foam.ClearRenderTarget(true, true, new Color(0f, 0f, 0f, 0f), 1f); this.drawnFoamProjectors = 0; for (int i = 0; i < count; i++) { LuxWater_Projector luxWater_Projector = LuxWater_Projector.FoamProjectors[i]; this.tempBounds = luxWater_Projector.m_Rend.bounds; if (GeometryUtility.TestPlanesAABB(this.frustumPlanes, this.tempBounds)) { LuxWater_ProjectorRenderer.cb_Foam.DrawRenderer(luxWater_Projector.m_Rend, luxWater_Projector.m_Mat); this.drawnFoamProjectors++; } } Graphics.ExecuteCommandBuffer(LuxWater_ProjectorRenderer.cb_Foam); num = Mathf.FloorToInt((float)(pixelWidth / (int)this.NormalBufferResolution)); height = Mathf.FloorToInt((float)(pixelHeight / (int)this.NormalBufferResolution)); if (!this.ProjectedNormals) { this.ProjectedNormals = new RenderTexture(num, height, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); Shader.SetGlobalTexture(this._LuxWater_NormalOverlayPID, this.ProjectedNormals); } else if (this.ProjectedNormals.width != num) { this.ProjectedNormals = new RenderTexture(num, height, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); } LuxWater_ProjectorRenderer.cb_Normals.Clear(); LuxWater_ProjectorRenderer.cb_Normals.SetRenderTarget(this.ProjectedNormals); LuxWater_ProjectorRenderer.cb_Normals.ClearRenderTarget(true, true, new Color(0f, 0f, 1f, 0f), 1f); this.drawnNormalProjectors = 0; for (int j = 0; j < count2; j++) { LuxWater_Projector luxWater_Projector2 = LuxWater_Projector.NormalProjectors[j]; this.tempBounds = luxWater_Projector2.m_Rend.bounds; if (GeometryUtility.TestPlanesAABB(this.frustumPlanes, this.tempBounds)) { LuxWater_ProjectorRenderer.cb_Normals.DrawRenderer(luxWater_Projector2.m_Rend, luxWater_Projector2.m_Mat); this.drawnNormalProjectors++; } } Graphics.ExecuteCommandBuffer(LuxWater_ProjectorRenderer.cb_Normals); GL.PopMatrix(); }