URP管线下unity_LODFade的骚操作
玩 The Illustrated Nature,发现他的植物做了Lod,并且Lod的过渡并不是硬切的,有一个渐变,如下:
跟了一下代码,发现主要的逻辑就3行:
#ifdef LOD_FADE_CROSSFADE
LODDitheringTransition( IN.clipPos.xyz, unity_LODFade.x );
#endif
上述代码里的 clipPos 即 齐次裁剪空间 的坐标,unity_LODFade 是Unity内置变量,unity_LODFade.x 表示是 当前LOD等级的权重,Unity文档对其有一个简单说明:
Unity doesn’t provide a default built-in technique to blend LOD geometries. You need to implement your own technique according to your game type and Asset production pipeline.
Unity calculates a blend factor from the GameObject’s screen size and passes it to your shader
in the unity_LODFade.x uniform variable. Depending on the Fade Mode you choose, use either the LOD_FADE_PERCENTAGE or LOD_FADE_CROSSFADE keyword for GameObjects rendered with LOD fading.
再来看一下 LODDitheringTransition 函数。因为我使用的是 URP 管线,直接下载