See how the Universal Render Pipeline (URP) leveled up with new Package Samples for enhanced camera stacking, decals, and Renderer Features.
To import these samples into your own project, open the Package Manager window, select the Universal RP package, unfold the Samples section, and hit Import. In the Assets folder, a new Samples folder will then be created with relevant scenes showcasing certain URP features.
The scenes include basic functionalities like adding Screen Space Ambient Occlusion to your project. We also provide more advanced examples, such as creating a sand trail effect with multiple cameras and a custom Renderer Feature. We encourage you to load up the samples and follow along as we unpack some of them in Unity 2021.2.
This collection shows different use cases for the Camera Stacking system. For instance, the advanced 3D Skybox example demonstrates how an overlay camera can be used to draw parts of the 3D world that are inaccessible from a balcony, such as distant buildings and planets.
Intuitively, you might want to have the base camera draw the cityscape and then have an overlay camera draw the balcony on top, but this could cause potential overdraw. Instead, you’ll see that the balcony camera is used as the base camera, and the stencil settings in the Pipeline Asset are set so that the overlay camera only draws the cityscape in pixels that haven’t already been written by the base camera.
More specifically, the balcony camera specifies the value of one to the stencil buffer, and the overlay camera only draws in areas where the stencil buffer’s value differs. In order for this to work, it is imperative to uncheck the Don’t Clear option on the overlay camera, as the stencil buffer is embedded in the depth buffer and would otherwise be cleared with it.
The Decal Projector is useful for creating surface data without unnecessary high-resolution textures. This allows for more dynamic effects like bullet holes or splatters. With the power of Shader Graph, the Decal system can be leveraged to create diverse and complex effects.
In the Paint Splat example, we show how decals and Shader Graph can be combined to produce procedural effects. The alpha of the decal is determined by sampling a noise texture with UV coordinates based on their world position.
The simplest way to achieve this involves taking the x and y coordinates of the position node (in world space) and using them for the UVs. This approach is quite limiting though, as the decal can only project properly on the z-plane.
That’s why we define a subgraph that will provide the world space UVs where the axis aligns with the Decal Projector. This way, the U and V axes are always aligned with the X and Y axes of the Projector Transform.
A common side effect of this method is that the UVs will slide around – especially if the projector is rotated far away from the origin. But because these paint splats are not meant to move around after being spawned, it does not pose a problem.
In the Proxy Lighting scene, decals are also used to modify the emissive color of surfaces in a cone shape. This makes surfaces appear as though they’re being lit by a spotlight, even though there are no real-time lights involved in this example.
Similarly, decals are used under the capsule to create the impression of a shadow. This kind of “blob shadow” is a common technique used in video games, where real-time lights and shadows are too expensive.
The position node (in Object mode) is key for achieving these effects, as it returns the 3D position of the fragment within the bounds of the Decal Projector bounding box.
Custom Renderer Features further highlight the customization capabilities of URP. The Renderer Feature samples show how to use some of the Renderer Features already provided by URP, as well as how to implement your own effects using the API.
The Keep Frame example, in particular, uses a custom Renderer Feature to modify the pipeline. The Renderer Feature copies color at the end of a frame and then redraws it at the beginning of the next frame. Seeing as Camera Clear Flags are not supported by URP, this Renderer Feature can be used to recreate effects that rely on the “Don’t Clear” flag from the Built-in Render Pipeline.
One major benefit of the Renderer Feature is that it will work on all platforms. It also pairs well with Shader Graph to modify the frame color as it is drawn. In the example scene, the material used to redraw the frame modifies the UVs, which rotates and shrinks the frame, effectively swirling the particles onscreen.
Then there’s Trail Effect, an example that takes advantage of the Keep Frame Renderer Feature. In this example, the Renderer Feature is added to a renderer that is used on a camera separate from the main camera. This “trail camera” is orthographic, and positioned beneath the scene, pointing upward. It renders to an offscreen render texture.
The Keep Frame Renderer feature makes sure that no color data is lost, whereas the shader on the feature encodes the depth and normal direction of selected objects into a color that is drawn to the render texture. The red channel stores depth, and the green and blue ones store normal information.
The result is a “trail map” that can be used on a shader to displace vertices under objects, like simulating the displacement of snow or sand when objects move on its surface. In the Sand Shader Graph, the trail map is sampled and blurred, vertices are displaced, and normals are recreated.
The samples discussed in this post represent only a fraction of those available in the Unity 2021.2 release. We will keep these samples up to date in upcoming releases, as new features continue to be added to URP.
We also want to ensure that these samples cover the use cases that matter most to you, so please don’t hesitate to share your feedback and solution requests in the forum thread.
For more information on what’s new for artists in 2021.2, visit our artist blog.
Technical Artist Jonas Mortensen recently joined Unity after obtaining a MSc in Computer Science from the IT University of Copenhagen, where he wrote his thesis on advanced algorithms. His technical background, along with his passion for art, led up to his current role at Unity, where he focuses on improving the features and workflows for the Universal Render Pipeline.
Jonas is particularly interested in learning and sharing his knowledge by teaching users how to customize and fully leverage the capabilities of the Scriptable Render Pipelines (SRPs).