AUTHOR: JPLEE
JP Lee is creating Game | Patreon
MicroShadow_GeometricalSpecular.mp4
<aside> 💡 Purpose:
AO handling of shaders When you guys usually using URP or basic mobile hardware is very simple. When using HDRP, more sophisticated specular shielding and environment reflection shielding are performed using the AO calculation formula using bent normal. A similar effect is to create a Micro Shadow with AO effect to be used on mobile hardware using the simple formula used in Uncharted2.
着色器的 AO 处理当你们通常使用 URP 或基本移动硬件时非常简单。 使用 HDRP 时,使用弯曲法线的 AO 计算公式执行更复杂的镜面反射屏蔽和环境反射屏蔽。 类似的效果是使用 Uncharted2 中使用的简单公式创建一个带有 AO 效果的微阴影,用于移动硬件。
</aside>
RS Lit.shader
[Header(__ SHADE PARAM __)]
[Gamma] _Metallic ("Metallic", Range(0, 1)) = 0
_Smoothness ("Smoothness", Range(0, 1)) = 0.5
_OcclusionStrength("Occlusion", Range(0,1)) = 0.75
_MicroShadowStrength("MicroShadow", Range(0,1)) = 0.8
[Space(10)]
RS Lit.shader
uniform half _MicroShadowStrength;
//RS_Lit.shader
//Fragment shader
half occlusion = RS_Occlusion(OcclusionMap , ndotl , _MicroShadowStrength );
RsCommon.cginc
// THis code motivated from Uncharted3 Alexander Maximove Micro Shadow occlusion function.
half RS_Occlusion( half occlusionTex , half NdotL, half Strength )
{
#if (SHADER_TARGET < 30)
return occlusionTex; // SM20: instruction count limitation
#else
half occ = occlusionTex;
occ = LerpOneTo (occ, _OcclusionStrength);
float aperture = 2.0 * occ * occ;
float microshadow = saturate(NdotL + aperture - 1.0);
return lerp(1.0, microshadow, Strength);
#endif
}