Optimizing Lighting in Unity: Lightmapping, Light Probes, and Custom Shaders
Developing indie projects with open areas inevitably runs into rendering limitations. While the industry is actively migrating to HDRP and hardware ray tracing, Unity's Built-in Render Pipeline (Built-in RP) remains a viable tool for teams prioritizing predictable performance and full control over the pipeline. The key to a stable frame rate without visual compromises lies in properly separating static and dynamic lighting, as well as targeted optimization of draw calls.
Hybrid Approach: Lightmaps vs Light Probes
Efficient scene lighting is built on a clear separation of geometry by priorities. Large architecture, landscapes, and static props are rendered using baked lightmaps. For this process, third-party lightmappers like Bakery are optimal, providing fast Global Illumination pre-baking and proper reflection handling without overburdening the editor.
Baking small objects with complex topology is impractical: it leads to atlas fragmentation and increased video memory usage. Instead, the Light Probes system is used. Probes interpolate environment lighting, passing color reflections and basic shadowing to dynamic or small static meshes. To optimize batching for identical props in the same zone, you can force-assign the coordinates of the same probe. This reduces the number of unique render states and eases the CPU load during frame preparation.
An important aspect of hybrid rendering is excluding distant geometry from real-time lighting calculations. Directional Light and cascaded shadows quickly become a bottleneck if the engine tries to compute them for objects on the horizon. Disabling real-time influence for the distant background and fully switching those areas to lightmaps or probes drastically reduces Draw Calls.
Manual Control of Texel Density and Culling Light Sources
Automatic generation of the second UV unwrap for lightmaps often yields suboptimal results. Manual UV2 layout allows precise Texel Density distribution based on the gameplay camera and significance. Building facades, corridors, and active interaction areas get high texel density, while roofs, back sides of walls, and inaccessible areas are compressed to a minimum. This saves space in light atlases and prevents compression artifacts in the foreground.
To balance quality and performance in Unity, Distance Shadowmask mode is used. At 50–80 meters from the camera, the engine renders dynamic shadows and overlays baked GI. Beyond this radius, only static shadows from lightmaps are rendered. The transition is seamless, and the GPU load stabilizes.
However, the Built-in Render Pipeline lacks a native mechanism for distance culling of point and spotlight sources. Lamps in distant rooms continue to be computed, wasting resources. The solution is a custom manager: the script maintains a pool of active sources, periodically (every 2–3 seconds) checks distance to the camera, and toggles the enabled state. Asynchronous checking prevents micro-stutters and ensures only visually relevant sources are active in the frame.
Terrain Lighting Projection via Custom Shader
Terrain decor (snowdrifts, rocks, vegetation) poses a serious problem for standard lightmapping. Baking every small object takes too long, and using Light Probes for thousands of instances generates extra draw calls and breaks static batching.
An effective workaround is writing a shader that projects the terrain lightmap onto overlaid geometry from top to bottom. The lightmap must contain only landscape data. The shader reads world coordinates of decor vertices, transforms them into terrain UV space, and samples the corresponding texel of baked light. The result simulates ambient occlusion and basic lighting without probe dependency.
Additionally, vertex blending is integrated into the shader. When the mesh's lower part contacts the terrain surface, albedo, normals, and roughness masks blend smoothly. This eliminates hard seams, creates snow accumulation effects at object bases, and visually merges scattered props with the landscape into unified geometry. The method completely removes intersection seams and works much faster than post-processing or complex voxel blending systems.
Modifying Cascaded Shadows and Programmatic Blurring
Standard Directional Light shadows in Unity suffer from two extremes: either overly sharp and stepped, or blurry with noticeable flickering when Shadow Map resolution is reduced. In real conditions, shadow softness depends on distance to the occluder and light source angular size. The shadow at the object base is always sharp, but the penumbra expands with distance.
To simulate physically correct behavior without heavy pipelines, a contact shadowing algorithm with progressive cascade blurring is applied. Third-party solutions modify the standard shadow pipeline, adding depth- and camera-distance-based filtering. This maintains high Shadow Map Resolution for near zones and smoothly blurs distant cascades, eliminating aliasing and reducing fill rate demands. Unlike HDRP built-ins, this avoids ray tracing computations or heavy post-effects, ensuring mid-range hardware compatibility.
Key Points
• Hybrid rendering requires clear geometry separation: lightmaps for large statics, Light Probes for small decor and dynamic objects.
• Manual UV2 and Texel Density tuning saves video memory and boosts lighting detail in gameplay-critical zones.
• Custom terrain lightmap projection shaders eliminate probe needs for thousands of small objects, reducing Draw Calls and improving batching.
• Distance culling of point lights via pool manager compensates for missing native features in Built-in RP.
• Progressive cascaded shadow blurring by distance solves aliasing and flickering without performance hits.
— Editorial Team
No comments yet.