Unity-NorthStar / data /Assets /Tutorial /pages /Spyglass.asset
introvoyz041's picture
Migrated from GitHub
d883ffe verified
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4510294d23d964fe59443526f1ca7c4b, type: 3}
m_Name: Spyglass
m_EditorClassIdentifier:
m_displayName: Spyglass
m_hierarchyName: Spyglass
m_context: {fileID: 11400000, guid: 87f11e1c7753cd242b2c673090d8513b, type: 2}
m_markdownFile: {fileID: 0}
m_priority: 1014
m_overrideMarkdownText: "## Spyglass\n\nIn NorthStar, a telescope helps players
see farther through dense fog. It uses an adjusted projection matrix to magnify
objects and reduce fog density, allowing players to view distant objects. The
telescope opens by pulling on the eyeglass, which extends its length.\n\n![](./Images/Eyeglass/Fig1.png)\n\n###
Interactions\n\nThe telescope consists of two parts: a Front and a Back, each
with a Rigidbody and multiple grab points. A joint connects these parts. A script
monitors the separation between the Rigidbodies and updates the telescope's state
(open or closed) based on this separation. When the state changes, the joint's
target position adjusts to keep the telescope open or closed, and eyeglass rendering
is enabled or disabled.\n\nWhen the telescope is near the user\u2019s eye, any
jitter becomes noticeable and can make it difficult or uncomfortable to use.
To stabilize, the telescope attaches to the nearest eye using another joint.\n\n![](./Images/Eyeglass/Fig2.png)\n\n###
Rendering\n\nInitially, the system rendered the world to a RenderTexture and
composited it over the eyeglass. However, this method was too slow for real-time
rendering. To reduce processing costs, a ScriptableRenderPass renders the visible
world directly to the screen with adjusted projection matrices and viewport,
stenciled to render only inside the eyeglass. It uses the same culling as the
main scene.\n\nFirst, the lens is drawn, writing a stencil bit to mark visible
eyeglass pixels. This ensures the magnified world is only visible through the
eyeglass, and any objects obscuring the eyeglass will also obscure the magnified
world.\n\nA screen rect is calculated for each eye based on the lens mesh bounds.
Due to eye separation, the screen-space bounds of the lens can differ significantly
for each eye. These rects combine to create a screen-space viewport containing
the lens for both eyes, used to adjust each eye's projection matrix. The projection
matrix is skewed by the relative telescope orientation multiplied by a \u201CtrackingFactor.\u201D\n\nFog
density is adjusted by overwriting the FogParams vector, and control passes to
the base DrawObjectsPass to render the game scene before restoring everything
to its initial state.\n\nFinally, the lens is drawn again with a smooth transparent
material to give it a glassy look.\n\n### Relevant Files\n- [Telescope.cs](../Assets/NorthStar/Scripts/Items/Telescope.cs)\n-
[ViewportRenderer.cs](https://github.com/meta-quest/Unity-UtilityPackages/tree/main/com.meta.utilities.viewport-renderer/Scripts/ViewportRenderer.cs)\n-
[EyeStencilWrite.shader](https://github.com/meta-quest/Unity-UtilityPackages/tree/main/com.meta.utilities.viewport-renderer/Materials/EyeStencilWrite.shader)\n"
m_overrideMarkdownRoot: .\Documentation/