Skip to content

Instantly share code, notes, and snippets.

@leegoonz
Created January 12, 2023 14:46
Show Gist options
  • Save leegoonz/aa2e92920dec78072f77535ef0df8324 to your computer and use it in GitHub Desktop.
Save leegoonz/aa2e92920dec78072f77535ef0df8324 to your computer and use it in GitHub Desktop.
#if _USESUBLIGHT
static bool _UseSubLight = true;
#else
static bool _UseSubLight = false;
#endif
uniform half _SubLightScale;
#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);
half3 invhalfDir = -(normalize(DirectionalLightDirection + s.viewdir));
half RoL = max(0, dot(ReflectionVector, DirectionalLightDirection));
half RoLDual = max(0, dot(ReflectionVector , -s.viewdir * invhalfDir)) * _SubLightScale;
half LoH = max(0, dot(DirectionalLightDirection, halfDir));
half normalizationTerm = (Roughness + 0.5) * 4.0;
#if DUALLOBE
half specularTermBeckMann = (2.0 * PhongApprox(RoughnessBeckMan, RoL) / (max(0.1h, LoH) * normalizationTerm));
half specularTerm = (PhongApprox(Roughness, RoL) / 2 + specularTermBeckMann) ;
#else
half specularTerm = PhongApprox(Roughness, RoL);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment