public void ChangeWaterQuality(int level, AQUAS_Reflection water) { switch (level) { case 0: water.m_ReflectLayers = 0; break; case 1: water.m_ReflectLayers = ~(1 << LayerMask.NameToLayer("UI")); water.m_TextureSize = 4; break; case 2: water.m_ReflectLayers = ~(1 << LayerMask.NameToLayer("UI")); water.m_TextureSize = 16; break; case 3: water.m_ReflectLayers = ~(1 << LayerMask.NameToLayer("UI")); water.m_TextureSize = 64; break; } }
public void OnWillRenderObject() { if (Object.op_Equality((Object)this._renderer, (Object)null)) { this._renderer = (Renderer)((Component)this).GetComponent <Renderer>(); } if (!((Behaviour)this).get_enabled() || !this._renderer.get_enabled() || (Object.op_Equality((Object)this._renderer, (Object)null) || Object.op_Equality((Object)this._renderer.get_sharedMaterial(), (Object)null)) || !this._renderer.get_isVisible()) { return; } Camera camera = this._camera; if (!Object.op_Implicit((Object)camera) || AQUAS_Reflection.s_InsideRendering) { return; } AQUAS_Reflection.s_InsideRendering = true; Camera reflectionCamera; Skybox skybox; this.CreateMirrorObjects(camera, out reflectionCamera, out skybox); Vector3 position1 = ((Component)this).get_transform().get_position(); Vector3 up = ((Component)this).get_transform().get_up(); int pixelLightCount = QualitySettings.get_pixelLightCount(); if (this.m_DisablePixelLights) { QualitySettings.set_pixelLightCount(0); } this.UpdateCameraModes(camera, reflectionCamera, skybox); float num = -Vector3.Dot(up, position1) - this.m_ClipPlaneOffset; Vector4 plane; ((Vector4) ref plane).\u002Ector((float)up.x, (float)up.y, (float)up.z, num); if (this.ignoreOcclusionCulling) { reflectionCamera.set_useOcclusionCulling(false); } else { reflectionCamera.set_useOcclusionCulling(true); } Matrix4x4 zero = Matrix4x4.get_zero(); AQUAS_Reflection.CalculateReflectionMatrix(ref zero, plane); Vector3 position2 = ((Component)camera).get_transform().get_position(); Vector3 vector3 = ((Matrix4x4) ref zero).MultiplyPoint(position2); reflectionCamera.set_worldToCameraMatrix(Matrix4x4.op_Multiply(camera.get_worldToCameraMatrix(), zero)); Vector4 clipPlane = this.CameraSpacePlane(reflectionCamera, position1, up, 1f); Matrix4x4 projectionMatrix = camera.get_projectionMatrix(); AQUAS_Reflection.CalculateObliqueMatrix(ref projectionMatrix, clipPlane); reflectionCamera.set_projectionMatrix(projectionMatrix); reflectionCamera.set_cullingMask(-17 & ((LayerMask) ref this.m_ReflectLayers).get_value()); reflectionCamera.set_targetTexture(this.m_ReflectionTexture); GL.set_invertCulling(true); ((Component)reflectionCamera).get_transform().set_position(vector3); Vector3 eulerAngles = ((Component)camera).get_transform().get_eulerAngles(); ((Component)reflectionCamera).get_transform().set_eulerAngles(new Vector3(0.0f, (float)eulerAngles.y, (float)eulerAngles.z)); reflectionCamera.Render(); ((Component)reflectionCamera).get_transform().set_position(position2); GL.set_invertCulling(false); Material[] sharedMaterials = this._renderer.get_sharedMaterials(); foreach (Material material in sharedMaterials) { if (material.HasProperty("_ReflectionTex")) { material.SetTexture("_ReflectionTex", (Texture)this.m_ReflectionTexture); } } Matrix4x4 matrix4x4_1 = Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0.5f), Quaternion.get_identity(), new Vector3(0.5f, 0.5f, 0.5f)); Vector3 lossyScale = ((Component)this).get_transform().get_lossyScale(); Matrix4x4 matrix4x4_2 = Matrix4x4.op_Multiply(((Component)this).get_transform().get_localToWorldMatrix(), Matrix4x4.Scale(new Vector3((float)(1.0 / lossyScale.x), (float)(1.0 / lossyScale.y), (float)(1.0 / lossyScale.z)))); Matrix4x4 matrix4x4_3 = Matrix4x4.op_Multiply(Matrix4x4.op_Multiply(Matrix4x4.op_Multiply(matrix4x4_1, camera.get_projectionMatrix()), camera.get_worldToCameraMatrix()), matrix4x4_2); foreach (Material material in sharedMaterials) { material.SetMatrix("_ProjMatrix", matrix4x4_3); } if (this.m_DisablePixelLights) { QualitySettings.set_pixelLightCount(pixelLightCount); } AQUAS_Reflection.s_InsideRendering = false; }
private static void CalculateObliqueMatrix(ref Matrix4x4 projection, Vector4 clipPlane) { Vector4 vector4_1 = Matrix4x4.op_Multiply(((Matrix4x4) ref projection).get_inverse(), new Vector4(AQUAS_Reflection.sgn((float)clipPlane.x), AQUAS_Reflection.sgn((float)clipPlane.y), 1f, 1f)); Vector4 vector4_2 = Vector4.op_Multiply(clipPlane, 2f / Vector4.Dot(clipPlane, vector4_1)); ((Matrix4x4) ref projection).set_Item(2, (float)vector4_2.x - ((Matrix4x4) ref projection).get_Item(3)); ((Matrix4x4) ref projection).set_Item(6, (float)vector4_2.y - ((Matrix4x4) ref projection).get_Item(7)); ((Matrix4x4) ref projection).set_Item(10, (float)vector4_2.z - ((Matrix4x4) ref projection).get_Item(11)); ((Matrix4x4) ref projection).set_Item(14, (float)vector4_2.w - ((Matrix4x4) ref projection).get_Item(15)); }