private static Matrix4x4 CalculateObliqueMatrix(Matrix4x4 projection, Vector4 clipPlane) { Vector4 b = projection.inverse * new Vector4(LuxWater_PlanarReflection.Sgn(clipPlane.x), LuxWater_PlanarReflection.Sgn(clipPlane.y), 1f, 1f); Vector4 vector = clipPlane * (2f / Vector4.Dot(clipPlane, b)); projection[2] = vector.x - projection[3]; projection[6] = vector.y - projection[7]; projection[10] = vector.z - projection[11]; projection[14] = vector.w - projection[15]; return(projection); }
void AcquireComponents() { if (!reflection) { if (transform.parent) { reflection = transform.parent.GetComponent <LuxWater_PlanarReflection>(); } else { reflection = transform.GetComponent <LuxWater_PlanarReflection>(); } } }
private void AcquireComponents() { if (Object.op_Implicit((Object)this.reflection)) { return; } if (Object.op_Implicit((Object)((Component)this).get_transform().get_parent())) { this.reflection = (LuxWater_PlanarReflection)((Component)((Component)this).get_transform().get_parent()).GetComponent <LuxWater_PlanarReflection>(); } else { this.reflection = (LuxWater_PlanarReflection)((Component)((Component)this).get_transform()).GetComponent <LuxWater_PlanarReflection>(); } }
private void RenderReflectionFor(Camera cam, Camera reflectCamera) { if (!reflectCamera) { return; } if (this.m_SharedMaterial && !this.m_SharedMaterial.HasProperty(this.reflectionSampler)) { return; } reflectCamera.cullingMask = (this.reflectionMask & ~(1 << LayerMask.NameToLayer("Water"))); this.SaneCameraSettings(reflectCamera); reflectCamera.backgroundColor = this.clearColor; reflectCamera.clearFlags = (this.reflectSkybox ? CameraClearFlags.Skybox : CameraClearFlags.Color); GL.invertCulling = true; Transform transform = base.transform; Vector3 eulerAngles = cam.transform.eulerAngles; reflectCamera.transform.eulerAngles = new Vector3(-eulerAngles.x, eulerAngles.y, eulerAngles.z); reflectCamera.transform.position = cam.transform.position; Vector3 position = transform.transform.position; position.y = transform.position.y + this.WaterSurfaceOffset; Vector3 up = transform.transform.up; float w = -Vector3.Dot(up, position) - this.clipPlaneOffset; Vector4 plane = new Vector4(up.x, up.y, up.z, w); Matrix4x4 matrix4x = Matrix4x4.zero; matrix4x = LuxWater_PlanarReflection.CalculateReflectionMatrix(matrix4x, plane); this.m_Oldpos = cam.transform.position; Vector3 position2 = matrix4x.MultiplyPoint(this.m_Oldpos); reflectCamera.worldToCameraMatrix = cam.worldToCameraMatrix * matrix4x; Vector4 clipPlane = this.CameraSpacePlane(reflectCamera, position, up, 1f); Matrix4x4 matrix4x2 = cam.projectionMatrix; matrix4x2 = LuxWater_PlanarReflection.CalculateObliqueMatrix(matrix4x2, clipPlane); reflectCamera.projectionMatrix = matrix4x2; reflectCamera.transform.position = position2; Vector3 eulerAngles2 = cam.transform.eulerAngles; reflectCamera.transform.eulerAngles = new Vector3(-eulerAngles2.x, eulerAngles2.y, eulerAngles2.z); int pixelLightCount = QualitySettings.pixelLightCount; if (this.disablePixelLights) { QualitySettings.pixelLightCount = 0; } float num = QualitySettings.shadowDistance; int shadowCascades = QualitySettings.shadowCascades; if (!this.renderShadows) { QualitySettings.shadowDistance = 0f; } else if (this.shadowDistance > 0f) { QualitySettings.shadowDistance = this.shadowDistance; } QualitySettings.shadowCascades = (int)this.ShadowCascades; reflectCamera.Render(); GL.invertCulling = false; if (this.disablePixelLights) { QualitySettings.pixelLightCount = pixelLightCount; } if (!this.renderShadows || this.shadowDistance > 0f) { QualitySettings.shadowDistance = num; } QualitySettings.shadowCascades = shadowCascades; if (this.isMaster) { for (int i = 0; i < this.WaterMaterials.Length; i++) { this.WaterMaterials[i].SetTexture(this.reflectionSampler, reflectCamera.targetTexture); } } }
private static Matrix4x4 CalculateObliqueMatrix( Matrix4x4 projection, Vector4 clipPlane) { Vector4 vector4_1 = Matrix4x4.op_Multiply(((Matrix4x4) ref projection).get_inverse(), new Vector4(LuxWater_PlanarReflection.Sgn((float)clipPlane.x), LuxWater_PlanarReflection.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)); return(projection); }
private void RenderReflectionFor(Camera cam, Camera reflectCamera) { if (!Object.op_Implicit((Object)reflectCamera) || Object.op_Implicit((Object)this.m_SharedMaterial) && !this.m_SharedMaterial.HasProperty(this.reflectionSampler)) { return; } reflectCamera.set_cullingMask(LayerMask.op_Implicit(this.reflectionMask) & ~(1 << LayerMask.NameToLayer("Water"))); this.SaneCameraSettings(reflectCamera); reflectCamera.set_backgroundColor(this.clearColor); reflectCamera.set_clearFlags(!this.reflectSkybox ? (CameraClearFlags)2 : (CameraClearFlags)1); GL.set_invertCulling(true); Transform transform = ((Component)this).get_transform(); Vector3 eulerAngles1 = ((Component)cam).get_transform().get_eulerAngles(); ((Component)reflectCamera).get_transform().set_eulerAngles(new Vector3((float)-eulerAngles1.x, (float)eulerAngles1.y, (float)eulerAngles1.z)); ((Component)reflectCamera).get_transform().set_position(((Component)cam).get_transform().get_position()); reflectCamera.set_orthographic(cam.get_orthographic()); reflectCamera.set_orthographicSize(cam.get_orthographicSize()); Vector3 position = ((Component)transform).get_transform().get_position(); position.y = (__Null)(transform.get_position().y + (double)this.WaterSurfaceOffset); Vector3 up = ((Component)transform).get_transform().get_up(); float num = -Vector3.Dot(up, position) - this.clipPlaneOffset; Vector4 plane; ((Vector4) ref plane).\u002Ector((float)up.x, (float)up.y, (float)up.z, num); Matrix4x4 reflectionMatrix = LuxWater_PlanarReflection.CalculateReflectionMatrix(Matrix4x4.get_zero(), plane); this.m_Oldpos = ((Component)cam).get_transform().get_position(); Vector3 vector3 = ((Matrix4x4) ref reflectionMatrix).MultiplyPoint(this.m_Oldpos); reflectCamera.set_worldToCameraMatrix(Matrix4x4.op_Multiply(cam.get_worldToCameraMatrix(), reflectionMatrix)); Vector4 clipPlane = this.CameraSpacePlane(reflectCamera, position, up, 1f); Matrix4x4 obliqueMatrix = LuxWater_PlanarReflection.CalculateObliqueMatrix(cam.get_projectionMatrix(), clipPlane); reflectCamera.set_projectionMatrix(obliqueMatrix); ((Component)reflectCamera).get_transform().set_position(vector3); Vector3 eulerAngles2 = ((Component)cam).get_transform().get_eulerAngles(); ((Component)reflectCamera).get_transform().set_eulerAngles(new Vector3((float)-eulerAngles2.x, (float)eulerAngles2.y, (float)eulerAngles2.z)); int pixelLightCount = QualitySettings.get_pixelLightCount(); if (this.disablePixelLights) { QualitySettings.set_pixelLightCount(0); } float shadowDistance = QualitySettings.get_shadowDistance(); int shadowCascades = QualitySettings.get_shadowCascades(); if (!this.renderShadows) { QualitySettings.set_shadowDistance(0.0f); } else if ((double)this.shadowDistance > 0.0) { QualitySettings.set_shadowDistance(this.shadowDistance); } QualitySettings.set_shadowCascades((int)this.ShadowCascades); reflectCamera.Render(); GL.set_invertCulling(false); if (this.disablePixelLights) { QualitySettings.set_pixelLightCount(pixelLightCount); } if (!this.renderShadows || (double)this.shadowDistance > 0.0) { QualitySettings.set_shadowDistance(shadowDistance); } QualitySettings.set_shadowCascades(shadowCascades); if (!this.isMaster) { return; } for (int index = 0; index < this.WaterMaterials.Length; ++index) { this.WaterMaterials[index].SetTexture(this.reflectionSampler, (Texture)reflectCamera.get_targetTexture()); } }