Chapter 15: Invalid texel artifacts
Figure 35. Scene containing a one-sided curtain mesh which causes invalid texel artifacts to appear after baking (left). Texel Validity scene view mode highlights invalid texels in red (right). Notice how saturated invalid texels are around the curtain area.
15.1 Why does this happen?
Sometimes, invalid texels can be the cause of blocky artifacts in a lightmap.
Unity can mark Lightmap texels as invalid under the following circumstances:
- When a given texel has not received any illumination via direct, indirect, or environment samples.
- Rays originating from a texel have intersected back-facing surfaces.
Lightmap filtering and denoising can make this issue worse by spreading invalid texels to neighboring texels. That is why it is important to address this issue early on without relying on post processing.
15.2 How to fix it?
Note: to make the process of debugging easier, consider using Texel Validity scene view draw mode.
15.2.1 Adjust mesh normals
Figure 36. Cube in the center has all its vertex normals facing outwards, resulting in a seamless and correctly shaded mesh. Blue polygons in the cube on the left are flipped. Orange polygons in the cube on the right are flipped. Cubes on the left and right will both exhibit invalid texel artifacts after baking, whereas the one in the center will not.
Vertex normal direction determines which side of the polygon appears as the front (visible) side. Flipping the direction of the normal will render the face invisible unless you are using double-sided shaders. Always ensure that the polygons, which you want to be visible, have their normals pointing outwards.
Most 3D modeling applications generate correct normals automatically. There are times when you would need to adjust mesh normals manually. To do so, please refer to 3ds Max, Maya, Blender, or other 3D modeling package documentation of your choice.
15.2.2 Avoid open faces
In some cases, adjusting normals might not be enough. For more complex meshes, make sure that they are watertight before exporting:
- Cap all open faces.
- Weld all overlapping vertices.
- Avoid line and point geometry.
- Avoid floating geometry unless your use case requires it.
Ignoring the above-stated suggestions might result in invalid texel artifacts when baking. In 3ds Max, try using xView to help identify mesh issues. Refer to documentation articles on how to do this in other 3D modeling applications.
15.2.3 Enable the Double-Sided Global Illumination material property
Figure 37. We have enabled Double Sided Global Illumination for the curtain mesh which before caused invalid texels to appear (left). Texel Validity view no longer shows any invalid texels in red around the curtains (right). Notice that not only the artifacts are gone, but the light also bounces off curtains.
Figure 38. Material inspector in different render pipelines. Built-in render pipeline (left), URP (center), and HDRP (right). We have highlighted the properties related to Double Sided Global Illumination in blue.
Foliage, decals, and other thin one-sided meshes often do not benefit from the steps outlined above. In such cases, the easiest way to fix texel validity artifacts is by enabling Double Sided Global Illumination material property. Once enabled, the lightmapper treats back-facing polygons as front-facing polygons during lightmap baking.
To make use of double-sided GI, follow these steps:
- In the Built-in render pipeline, enable Double Sided Global Illumination checkbox in the Material Inspector. Same steps apply to custom ShaderGraph materials as well.
- In URP, set the Render Face dropdown to Both. You can find this property under the Surface category in the Lit Shader.
- In HDRP, two properties located under the Surface category in the Lit Shader control the double-sided GI behavior:
- Double-Sided. Enable this checkbox to disable backface culling. This also enables double-sided GI.
- Double-Sided GI. This dropdown contains three options: Auto, On, and Off. When Auto is selected, double-sided GI is enabled if Double-Sided property is also enabled. On and Off options allow to override double-sided GI behavior without making material appear double-sided.
- You can also control double-sided GI material property via the API.
15.2.4 Why not always enable Double-Sided Global Illumination property?
Figure 39. Double Sided Global Illumination disabled (left) and enabled (right). Notice dark artifacts where the meshes intersect in the image on the right. In such cases, disable Double Sided Global Illumination to achieve correct output.
Lightmapper marks texels as invalid when they receive no illumination or intersect backfaces. This allows the dilation filter to push lighting data from valid surrounding texels into partially covered texels. Doing so helps to remove dark artifacts at geometry junctions.
Enabling double sided GI by default for all materials, would result in a darkening effect where meshes intersect or overlap.
Please use this setting at your own discretion where it makes sense.
15.2.5 Adjust the Backface Tolerance property
You can access the Backface Tolerance property via the Lightmap Parameters Asset. Create a new lightmap parameters asset and assign it via the Mesh Renderer component, under the Lightmapping section.
This property controls the percentage of rays that must hit front-facing geometry to consider the texel valid:
- Increasing the value increases the likelihood the lightmapper marks a texel as invalid when it sees backfaces.
- Lowering this value will reduce the number of invalidated texels.
Note that low values might result in a loss of occlusion and/or bounce lighting, thus changing the look of the scene.
15.2.6 Move meshes closer to the world origin
Note: we are planning on addressing this issue in the future by implementing 64-bit floating-point precision support for the unified lightmapping backend.
Limitations imposed by the 32-bit floating-point precision format can be the cause of invalid texels. It happens when placing lightmapped meshes far away from the world origin (0,0,0), or if they have a massive scale. This issue is not limited to lightmapped meshes; objects and animations will lose precision the farther away they are from world origin.
To resolve this issue, move meshes closer to the 0,0,0 world coordinate. Or, try adjusting the Push off value in the Lightmap Parameters Asset.
For more information, please refer to the excellent article on floating-point arithmetic by Alan Zucconi.