-
Notifications
You must be signed in to change notification settings - Fork 411
FPS Demo
Felipe Lira edited this page Feb 11, 2020
·
3 revisions
This demo showcases a setup to render first person perspective objects with a FOV(Field Of View) that differs from the game scene rendering FOV, this is common in first person games where the FOV needed for the experience is too wide for the objects held in hand ends up distorted.
- Can be found at
_CompletedDemos/FPS/FPSRenderPass/FPSCameraDemo.unity
- Uses the
Render Objects (Experimental)
feature that is provided with the URP Package - Different FOV for GameObjects with the Layer set to
First Person Objects
- Depth settings to avoid rendering inside close objects like walls
- Stencil settings to properly handle transparencies
We need three Render Objects (Experimental)
features and to also override both the Default Layer Mask
and Stencil
settings as shown below:
-
Default Layer Mask
is set to ignore theFirst Person Objects
layer as these will be rendered by the three Renderer Features. -
Stencil
settings have been overidden, this changes the default passes(Forward Opaque and Forward Transparent) handling of stencil values:-
Value
andCompare Function
are important here, because we only want to write pixels if the existing value is equal to 0, this is because we will render the weapon into Stencil Value 1
-
this Renderer Feature is rendering the opaque parts of the weapon
- Uses
Before Rendering Opaques
event to execute before the URP Forward Opaque Pass - Filters
Opaque
renderers that have been taggedFirst Person Objects
- Overrides
Stencil
-
Value
that will be used set to 1 -
Compare Function
set toAlways
return true -
Replace
the existing value when passing(the initial value of the Stencil Buffer is 0) with theValue
specified
-
- Overrides
Camera
- Use a
Field Of View
of 40 -
Restore
the camera after finishing this render pass
- Use a
this Renderer Feature renders the transparent parts of the weapon that overlap with the Opaque parts
- Uses
After Rendering Tranparents
event to execute after the URP Forward Transparent Pass - Filters
Transparent
renderers that have been taggedFirst Person Objects
- Overrides
Stencil
-
Value
that will be used set to 1 -
Compare Function
set toEqual
so we only render if the existing value is the same as 1, this is rendering to any pixels inside of the opaque weapon
-
- Overrides
Camera
- Use a
Field Of View
of 40 -
Restore
the camera after finishing this render pass
- Use a
this Renderer Feature renders the transparent parts of the weapon that do not overlap with the Opaque parts but always render over the scene regardless of depth.
- Uses
After Rendering Tranparents
event to execute after the URP Forward Transparent Pass and after the previous pass due to the ordering in the list - Filters
Transparent
renderers that have been taggedFirst Person Objects
- Overrides
Depth
-
Depth Test
is set toAlways
to make sure regardless of the existing depth value, we always pass.
-
- Overrides
Stencil
-
Value
that will be used set to 0 -
Compare Function
set toEqual
so we only render if the existing value is the same as 0, this is rendering to any pixels outside of the opaque weapon
-
- Overrides
Camera
- Use a
Field Of View
of 40 -
Restore
the camera after finishing this render pass
- Use a