protected internal override void PreSpecularRender(Camera receiver) { // Called before any portal cameras are rendered for the current frame Teleportation.SliceTravellers(_tracked_travellers: ref this._tracked_travellers, portal: this, receiver: receiver); }
void OnTriggerEnter(Collider other) { var traveller = other.GetComponent <PortalTraveller>(); if (traveller) { Teleportation.OnTravellerEnterPortal(traveller: traveller, this_portal: this); } }
protected internal override void PostSpecularRender(Camera receiver) { // Called once all portals have been rendered, but before the player camera renders Teleportation.SliceTravellers(_tracked_travellers: ref this._tracked_travellers, portal: this, receiver: receiver); Rendering.ProtectScreenFromClipping(view_point: receiver.transform.position, this_portal: this, receiver: receiver); }
void LateUpdate() { Teleportation.HandleTravellers(_tracked_travellers: ref this._tracked_travellers, linkedPortal: this.linkedPortal, transform: this.transform); }
internal static void HandleClipping(Portal this_portal, Camera receiver) { // There are two main graphical issues when slicing travellers // 1. Tiny sliver of mesh drawn on backside of portal // Ideally the oblique clip plane would sort this out, but even with 0 offset, tiny sliver still visible // 2. Tiny seam between the sliced mesh, and the rest of the model drawn onto the portal screen // This function tries to address these issues by modifying the slice parameters when rendering the view from the portal // Would be great if this could be fixed more elegantly, but this is the best I can figure out for now const float hide_dst = -1000; const float show_dst = 1000; var screen_thickness = ProtectScreenFromClipping(view_point: this_portal._Specular_Camera.transform.position, this_portal: this_portal.linkedPortal, receiver: receiver); for (var index = 0; index < this_portal.TrackedTravellers.Count; index++) { var traveller = this_portal.TrackedTravellers[index : index]; if (Teleportation.SameSideOfPortal(pos_a : traveller.transform.position, pos_b : this_portal._Specular_Camera.transform.position, portal : this_portal)) { // Addresses issue 1 traveller.SetSliceOffsetDst(dst: hide_dst, false); } else { // Addresses issue 2 traveller.SetSliceOffsetDst(dst: show_dst, false); } // Ensure clone is properly sliced, in case it's visible through this portal: var clone_side_of_linked_portal = -Teleportation.SideOfPortal(pos: traveller.transform.position, portal: this_portal); var cam_same_side_as_clone = Teleportation.SideOfPortal(pos: this_portal._Specular_Camera.transform.position, portal: this_portal.linkedPortal) == clone_side_of_linked_portal; if (cam_same_side_as_clone) { traveller.SetSliceOffsetDst(dst: screen_thickness, true); } else { traveller.SetSliceOffsetDst(dst: -screen_thickness, true); } } //var offset_from_portal_to_cam = this.PortalCamPos - this.transform.position; for (var index = 0; index < this_portal.linkedPortal.TrackedTravellers.Count; index++) { var linked_traveller = this_portal.linkedPortal.TrackedTravellers[index : index]; var traveller_pos = linked_traveller.graphicsObject.transform.position; var clone_pos = linked_traveller.GraphicsClone.transform.position; // Handle clone of linked portal coming through this portal: var clone_on_same_side_as_cam = Teleportation.SideOfPortal(pos: traveller_pos, portal: this_portal.linkedPortal) != Teleportation.SideOfPortal(pos: this_portal._Specular_Camera.transform.position, portal: this_portal); if (clone_on_same_side_as_cam) { // Addresses issue 1 linked_traveller.SetSliceOffsetDst(dst: hide_dst, true); } else { // Addresses issue 2 linked_traveller.SetSliceOffsetDst(dst: show_dst, true); } // Ensure traveller of linked portal is properly sliced, in case it's visible through this portal: var cam_same_side_as_traveller = Teleportation.SameSideOfPortal(pos_a: linked_traveller.transform.position, pos_b: this_portal._Specular_Camera.transform.position, portal: this_portal.linkedPortal); if (cam_same_side_as_traveller) { linked_traveller.SetSliceOffsetDst(dst: screen_thickness, false); } else { linked_traveller.SetSliceOffsetDst(dst: -screen_thickness, false); } } }