private static Matrix4x4 CalculateObliqueMatrix(Matrix4x4 projection, Vector4 clipPlane) { Vector4 b = projection.inverse * new Vector4(Floor_ReflectionScriptCamera.sgn(clipPlane.x), Floor_ReflectionScriptCamera.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); }
private void RenderReflectionFor(Camera cam, Camera reflectCamera) { if (!reflectCamera) { return; } this.SaneCameraSettings(reflectCamera); reflectCamera.backgroundColor = this.clearColor; GL.invertCulling = false; Transform transform = this.reflectiveSurfaceHeight; 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; 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 = Floor_ReflectionScriptCamera.CalculateReflectionMatrix(matrix4x, plane); this.oldpos = cam.transform.position; Vector3 position2 = matrix4x.MultiplyPoint(this.oldpos); reflectCamera.worldToCameraMatrix = cam.worldToCameraMatrix * matrix4x; Vector4 clipPlane = this.CameraSpacePlane(reflectCamera, position, up, 1f); Matrix4x4 matrix4x2 = cam.projectionMatrix; matrix4x2 = Floor_ReflectionScriptCamera.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); reflectCamera.RenderWithShader(this.replacementShader, "Reflection"); GL.invertCulling = false; }