You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[HDRP] Fix Terrains with 4 layers or less displaying checker texture when using debug views
This PR fixes an issue where a checker texture would appear on Terrains with 4 layers or less when using, for example, the "Unlit Draw Mode".
| Before | After |
| :---: | :---: |
| <img src="https://media.github.cds.internal.unity3d.com/user/3541/files/31f50cb2-4a40-49bb-b568-f586056a98d3" width="100%" height="100%"> | <img src="https://media.github.cds.internal.unity3d.com/user/3541/files/919c1beb-7d07-4dac-98aa-da7215e5e8f2" width="100%" height="100%"> |
The issue was caused by https://github.cds.internal.unity3d.com/unity/unity/pull/38619, where we started force-enabling the `_TERRAIN_8_LAYERS` shader keyword whenever `DEBUG_DISPLAY` was defined.
- For the mipmap debug views, no issue would ever appear since we only display debug information for 1 specific Terrain layer at a time. Because we forced `_TERRAIN_8_LAYERS`, debugging layers 4 to 7 on a 4-layered Terrain would thus display debug information for the default texture set by the Terrain system. (checker texture **_in editor_**, tiny white texture in player)
- For all other debug views, the checker texture bug would appear on 4-layered Terrain because force-enabling `_TERRAIN_8_LAYERS` also means that the Terrain uses a second Control texture, but the Terrain system obviously has none to provide so a default grey texture was used instead → layers 4 / 5 / 6 / 7 thus suddenly appeared at half opacity on top of other layers.
Of course, we could somehow ensure that the default texture used for the second Control texture is always fully black (feels quite sloppy though?), but I do feel like force-enabling the `_TERRAIN_8_LAYERS` shader keyword when debugging wasn't the best approach in the first place.
- Forcefully enabling the keyword essentially means that 4 extra layers appear out of thin air. When debugging individual layers with the mipmap debug views, it is thus impossible to differentiate 4-layered Terrain vs 8-layered Terrain and might even give users the impression that HDRP Terrains are always 8-layered behind-the-scenes.
- By reworking the code a little, we can still display appropriate mipmap debug information even if we have no layer texture available, so there is in fact no need to forcefully enable the keyword just to get a layer texture to sample / obtain mipcount from / ...
I've thus simply reworked the mipmap debug views code (see 23f28b58b6ff61699def6be1ac64b0265d1fee9f) so that it displays "invalid" / "missing" information when debugging layers 4 / 5 / 6 / 7 on a 4-layered Terrain (we use white as "texture colour").
When using, for example, the `Mip Count` view to debug the 5th layer of a 4-layered Terrain, the result now looks like this:
| Before | After |
| :---: | :---: |
| <img src="https://media.github.cds.internal.unity3d.com/user/3541/files/1ce3209f-dd83-4c6d-a313-0633fddb6800" width="100%" height="100%"> | <img src="https://media.github.cds.internal.unity3d.com/user/3541/files/058117fb-38b1-48ad-88ec-16cd5f47fbe1" width="100%" height="100%"> |
0 commit comments