Virtual back lighting method test

Purpose of implementations.

  • Avoiding increasing draw-call.
这是手机游戏预览的真实预览。
#if USE_SECOND_DIRECTIONAL_LIGHT
    half2 RoL = max(0, half2(dot(ReflectionVector, DirectionalLightDirection), dot(ReflectionVector, _WorldSpaceLightPos1.xyz)));
    half2 PhongSpecular = PhongApprox(Roughness, RoL);
	half3 Directional = (Shadow * NoL) * DirectionalLightColor * (DiffuseColor + SpecularColor * PhongSpecular.x);
    
    half NoL2 = max(0, dot(normalWorld, _WorldSpaceLightPos1.xyz));
	Directional += NoL2 * _LightColor1 * (DiffuseColor + SpecularColor * PhongSpecular.y);
#else
    half3 halfDir = normalize(DirectionalLightDirection + s.viewdir);
    half RoL = max(0, dot(ReflectionVector, DirectionalLightDirection));
    half RoLDual = max(0, dot(ReflectionVector , -s.viewdir * halfDir));
    
    half3 Directional = (Shadow * NoL) * DirectionalLightColor * (DiffuseColor + SpecularColor * (PhongApprox(Roughness,RoL)));
    #if defined(USE_BACKLIGHT_SPECUAR)
        Directional = (Shadow * NoL) * DirectionalLightColor * (DiffuseColor + SpecularColor * (PhongApprox(Roughness,RoL) + (PhongApprox(Roughness, RoLDual))));
    #endif
#endif

Categories: shader

Tagged as: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s