Creating high-fidelity environments for your game can be a massive undertaking. That’s why we introduced a number of updates during the 2021.2 Tech Stream release, including new Terrain stamping brushes, refined material painting controls, GPU instancing capabilities for Terrain Details, and SpeedTree integration, among other improvements to the Terrain authoring experience. We even updated the free Terrain Sample Asset Pack to help jump-start your development. Behind it all, a team of technical artists worked to author and optimize a believable environment scene using Unity’s High Definition Render Pipeline (HDRP) for PC and high-end consoles, and migrating it to Unity’s Universal Render Pipeline (URP) for cross-platform reach. We now bring you a collection of tips, tricks, and best practices to go with the new Unity Terrain URP Demo scene and HDRP Demo scene.
Hello everyone. My name is Xiaoxi Liu and I joined Unity in 2018 as a technical artist focused on improving features and artist workflows in Unity, from the Terrain system to Shader Graph. In my spare time, I enjoy outdoor activities with my very active four-year-old son.
Hi there, my name is Barrington Campbell. I joined Unity in 2019 as an intern and then transitioned to a full-time position as a technical artist in 2020. While at Unity, I’ve aimed to enhance the Terrain system, specializing in tool development and user workflows. Outside of work, I enjoy building my time-attack car and racing it on the weekends.
While the Terrain Tools package was initially verified in the 2021.2 Tech release, it’s now available to install in your project via the Package Manager and Worldbuilding feature set. The package comes equipped with additional artistic Terrain painting brushes and utility tools to boost your worldbuilding processes.
In the preproduction phase of the Terrain Demo project, our technical art team narrowed down several key elements to highlight, ultimately prioritizing the detailed Terrain heightmap and dense foliage coverage.
We used a procedural Terrain generation tool called Gaea to generate high-resolution heightmap and splatmap, followed by the Toolbox to import these maps in-Editor. For the Terrain heightmap, we used the Import Heightmap tool to apply it to a 4x4 tiled Terrain in Unity at 4,000 units at scale. Using the Import Splatmap tool, we applied the splatmap to the tiled Terrain. This process was determined during the creation of our project, which provided basic roundtripping workflows from Gaea to Unity Terrain.
After the initial import to Unity, we had a very solid Terrain surface to start from, but with certain areas we wanted to manually paint over.
The Stamp Terrain brush is a great tool to quickly adapt Terrain height information for realistic results. We’ve released some ready-to-use heightmaps in the Terrain Sample Asset Pack, but you can also generate your own heightmaps from DCCs.
As you might already know, Unity’s Terrain materials are constructed by Terrain Layer assets. The Paint Texture brush enables you to select and switch material in the Scene view, whereas the Brush Mask Filters and recently improved user interface from the Terrain Tools package allow you to generate stunning results with less effort.
For instance, you can constrain the painting area by adding a Slope filter. First, apply the grassy material layer onto the side surface of the Terrain, then use a Concavity filter to constrain the soil layer to the curvatures. You can isolate one filter by disabling the others, or even combine filters when needed.
There are extra sculpting brushes in the package, like the Erosion and Noise effects, which you can also integrate into your Terrain building flow for optimal results.
Since the release of 2021.2, Unity Terrain leverages the power of your GPU to render massive amounts of foliage with the support of instanced details. This is useful for areas of foliage that require dense coverage, such as grass and bushes.
On most PC platforms, you can render millions of instanced details at well over 60 fps. In the Demo scene, for example, there are over 50 million triangles rendered in a few view angles. To enable instancing, go to the Edit Details Mesh and check the Use GPU Instancing box.
Advanced shading with instanced details
Instanced details let you use custom materials – a major benefit when working with either HDRP or URP. For the best possible experience, we recommend authoring grass materials using Shader Graph. Let’s take a closer look at the TerrainGrass.shadergraph.
With the support of Custom Interpolators, a recent addition to Shader Graph, we’re now able to get vertex manipulations done in the Vertex stage with stronger overall performance. In this project, we utilized the Vertex stage for wind animations, as well as the appearance of fading grass through color and ambient occlusion, depending on distance from the Camera. Considering the high instance count for randomization, plus the capacity to grab and position individual grass objects, you can create cool location-based effects in your shader, such as wind ripples and blending colors from the Terrain underneath.
One thing worth noting, however, is that the LOD Group component is not compatible with Terrain details, though you can still use Prefabs for details and tweak the cull distance in the Shader Graph shader or via the Detail Distance setting on the Terrain.
Empowered by SpeedTree
Naturally, trees are essential for creating believable environments. The Demo scenes contain a variety of custom trees from SpeedTree, a modeler that lets you create high-performance vegetation with procedural generators for just about any project, regardless of scale. With support from the integration of Shader Graph, you’re able to harness out-of-the-box shaders that contain all of the features from SpeedTree in Unity – think wind, hue variation, Billboard rendering, and more. Akin to the editable material instances, Shader Graph shaders are customizable, so you can save new shaders within your project and start editing freely. Look for Extract Materials under Import Settings to begin your customization.
Trees and details are typically painted using the Paint Trees and Paint Details brush respectively, much like the existing painting workflows you’re probably familiar with. You can author a custom brush thanks to the brush APIs available in Terrain Tools. Then reference the Terrain Module for your own project.
With instanced detail support and SpeedTree integration, you have the power to author Terrain foliage with advanced customization from Shader Graph. We spoke about this at Siggraph last year, covering some additional details you might be interested in.
With HDRP in Unity 2021.2, you can create convincing and dynamic skies using the new Volumetric Clouds system. In particular, the Physical Sky system in HDRP provides standard parameters for generating physically correct sky lighting.
Looking at the daytime environment we are trying to achieve in the scene, the intensity of the sun is set to a value we’d expect outside of the attenuating effect of the atmosphere – 130,000 lux – while the color temperature is set to a value approximated as a black body at 5,800 K. With post-processing, the light’s temperature can be compensated for, just as it would be in a Physical Camera.
You wouldn’t want to have short grass casting shadows when placed in a carpeting style, as that would be expensive on the rendering thread – not to mention, unrealistic and less visually appealing. That’s why we employed a few techniques for proper lighting and shadows on Terrain Detail objects, such as Contact Shadows to generate much better visuals with less cost.
Terrain Detail objects, like grass and low vegetation, all share the scene’s ambient probe in order to improve rendering performance. As these objects receive unoccluded lighting from the sky, the result can often be too bright. To rectify this, we chose to use a separate “baking sky” volume. This allowed us to reduce the exposure of the sky being used to generate the ambient probe, lowering the lighting intensity of the grass without modifying the visual appearance of the sky in the scene.
It has been our goal to demonstrate Terrain in both scriptable render pipelines, which turned out to be a great learning opportunity for the entire team.
As we’ve shown, the TerrainData assets are shareable between HDRP and URP projects. We started by constructing the Terrain in the HDRP project, and brought the TerrainData assets into the URP project following the material and foliage massout phase. By turning the Terrain tiles into a Prefab, we sped up the integration process to URP.
While Terrain scale and resolutions share the same settings for both projects, we chose the height-based material blending mode in HDRP, and the default alpha blending mode in URP, for optimal visual fidelity. Note that HDRP allows blending up to eight Terrain layers.
We crafted lighting and post-processing in both projects to maximize the latest available rendering features. In the HDRP project, we set up the Volumetric Clouds and procedural sky as mentioned previously. Then we baked the procedural sky into textures to use as an HDRI sky in the URP project.
Fog is handled differently in each case. We utilized the volumetric fog for low fog around the lake in HDRP, but made custom particle effects from the Visual Effect Graph in URP.
Here’s an overview of the features we used for comparison:
Performance is crucial when it comes to real-time 3D interactive experiences, and there are several approaches we used in this project to ameliorate it. The Render Pipeline asset available in HDRP and URP allows you to create customized settings for targeting multiple platforms. Taking the URP Terrain scene as an example, we created High Quality and Low Quality assets, where high-resolution shadow maps and HDR features are only opted in for the High Quality version. This way, you can configure settings for each target platform easily via Quality settings, in the Project Settings window. In fact, you can switch and preview various settings in your working scene right in-Editor; just swap the Render Pipeline asset from the Graphics settings.
In addition to Project Level settings for performance gain, we made a few content optimizations in Terrain. In the HDRP Terrain scene, for example, we reduced the resolution for the outer Terrain tiles in distance. However, you should only perform this resolution change after your Terrain painting process is complete. Otherwise, painting across neighboring tiles can result in inconsistencies due to the difference in resolution.
Dense details are the most common performance offenders when it comes to low-end platforms. It’s vital to keep the mesh vertex count low. In the HDRP scene, we set the detail density to 0.75, with a closer cull distance of 145 meters on the center Terrain tiles. You could try increasing or decreasing the density and cull distance parameters to see what works well together. Alternatively, you could tweak the LOD distances on trees to have them render LOD and Billboard sooner, for a reasonable gain.
If you’re using URP and building for platforms that do not support GPU instancing or have very limited hardware bandwidth, you could choose the Vertex Lit mode for rendering Terrain details. But unlike instanced details, this mode does not support shadows, double-sided rendering, or alpha clipping.
Looking to learn more? For additional performance optimization tips and tricks, be sure to check out this blog post and our Unite Now videos.
To access the new Unity Terrain Demo scenes for both HDRP and URP, go to the Asset Store and import them directly into your Unity 2021.2 project. Once you’ve had a chance to fully explore the scenes, let us know what you think on the Worldbuilding forums.
For further information on what’s to come, please visit the Unity Roadmap.
Lastly, Unity’s technical art team is hiring. You can check out the open positions on our website. We look forward to hearing from you!