Achieving Optimal Texture Baking: Choosing Between Static and Dynamic Objects in Unity HDRP
Texture baking is an essential process in game development that enables the creation of high-quality and efficient lighting for your scenes. Within the High Definition Render Pipeline (HDRP) of Unity, it’s important to carefully consider the best approach for baking textures, choosing between static and dynamic objects. This article will guide you through the process, focusing on minimizing crashes during light baking, effectively utilizing light probes, and strategically setting objects as static to optimize the baking process in HDRP.
- The Importance of Texture Baking: Texture baking is the process of precomputing lighting information and storing it in textures. This allows for efficient real-time rendering, improved performance, and consistent lighting in your game. HDRP offers advanced baking options to achieve realistic and visually appealing results.
- Avoiding Crashes during Light Baking: Baking lights can be a computationally intensive task, and crashes may occur, particularly with complex scenes. To minimize the risk of crashes, consider the following strategies:
- Divide and Conquer: If you have a large scene, divide it into smaller sections or baking zones. Baking each zone separately reduces the overall computational load and helps avoid crashes.
- Adjust Baking Settings: HDRP provides various baking settings that allow you to balance quality and performance. Experiment with settings like resolution, indirect resolution, and distance attenuation to find the optimal balance for your scene and hardware.
- Use Progressive Lightmapper: The Progressive Lightmapper in Unity offers faster and more stable baking compared to the Enlighten Lightmapper. Consider switching to the Progressive Lightmapper to reduce the likelihood of crashes during the baking process.
3. Harnessing Light Probes: Light probes are invaluable for capturing indirect lighting and enhancing the realism of your scenes. Here’s how to effectively utilize light probes during texture baking:
- Placing Light Probes: Strategically place light probes in areas where dynamic objects or lighting changes occur. This ensures accurate and realistic indirect lighting calculations during runtime, while minimizing the need for extensive baking.
- Light Probe Proxy Volumes: Utilize Light Probe Proxy Volumes (LPPVs) to automate the placement of light probes. LPPVs define volumes in your scene where light probes are automatically placed, optimizing the distribution of probes and reducing the manual effort required.
4. Choosing Static or Dynamic Objects: Determining whether an object should be set as static or dynamic affects the baking process. Consider the following guidelines:
- Setting Objects as Static: For objects that do not move or deform during gameplay, marking them as static provides significant performance benefits during baking and runtime. Static objects are precomputed, resulting in efficient lighting calculations.
- Marking Objects as Dynamic: Dynamic objects, such as characters or physics-based objects, should be set as dynamic. These objects receive real-time lighting calculations and should be excluded from the baking process to avoid conflicting lighting information.
5. Timing the Static/Dynamic Switch: In some cases, dynamic objects may need to temporarily behave as static during the baking process to ensure consistent lighting. Here’s how to handle the switch:
- Preparation Phase: Prior to baking, temporarily mark dynamic objects as static to include them in the baking process. This ensures that their influence on the lighting is captured accurately.
- Runtime Phase: During runtime, switch dynamic objects back to their original dynamic state to receive real-time lighting calculations. This ensures proper interaction with the scene’s lighting and maintains realism.
To start, it is essential to set all the objects that won’t move in the environment as static.
Inside Lighting Settings window, we can set the Lightmapper to Progressive GPU (preview) to use the computer’s GPU for baking instead of the CPU. For equipment with GPU, this ensures best processor utilization when baking.
With a strong GPU, unity can work marvelously and utilize the Auto Generate function; this will constantly bake the scene as lights are adjusted and moved around the scene. When marked as static, if the auto generate lightmapper is enabled, unity will start baking, and the process should not last longer than 5 minutes for a small scene.
When done baking, inside the Lighting > Baked Lightmaps, unity will leave the Lightmap Index for this scene.
The static lighting sky I’m using is with a Gradient Sky inside the global volume settings. This setting adds a light film to the entire scene through rays that come from outside the room. In this case, it sets a definitive green and brighter tone to the scene compared when it is set to “none”.
None:
Gradient Sky:
The walls and the fog look a bit brighter, the sidewalk around the walls has lit up and the details are better perceivable, yet keep that darkness to the scene.
Proper Light Probe group usage will enhance light bounces in Dynamic Objects; this scene is mainly a very lit area and a dark entrance.
Achieving optimal texture baking is essential for visually appealing and performant game environments. By leveraging texture baking for static objects, you can benefit from improved lighting realism and consistent results. Dynamic objects, on the other hand, should rely on real-time lighting calculations to maintain their responsiveness and dynamic interactions. By striking the right balance and combining both approaches, you can create visually impressive scenes while ensuring smooth performance. Consider the nature of objects, performance requirements, and the desired visual fidelity to make informed choices when embarking on texture baking in Unity HDRP.