Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional light shadow support to Toon lighting model #445

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion UOP1_Project/Assets/Shaders/CustomHLSL/CustomLighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,36 @@ void DirectSpecular_float(float Smoothness, float3 Direction, float3 WorldNormal
#endif
}

half4 GetShadowMask()
{
// TODO: not sure if/how we can access inputData.shadowMask here.
// Should only be relevant for lightmapped surfaces receiving additional light shadows
// #if defined(SHADOWS_SHADOWMASK) && defined(LIGHTMAP_ON)
// half4 shadowMask = inputData.shadowMask;
// #elif !defined (LIGHTMAP_ON)
#if !defined (LIGHTMAP_ON)
half4 shadowMask = unity_ProbesOcclusion;
#else
half4 shadowMask = half4(1, 1, 1, 1);
#endif
return shadowMask;
}

void AdditionalLights_float(float Smoothness, float3 WorldPosition, float3 WorldNormal, float3 WorldView, out float3 Diffuse, out float3 Specular)
{
float3 diffuseColor = 0;
float3 specularColor = 0;
float4 White = 1;

#if !defined(SHADERGRAPH_PREVIEW)
half4 shadowMask = GetShadowMask();
Smoothness = exp2(10 * Smoothness + 1);
WorldNormal = normalize(WorldNormal);
WorldView = SafeNormalize(WorldView);
int pixelLightCount = GetAdditionalLightsCount();
for (int i = 0; i < pixelLightCount; ++i)
{
Light light = GetAdditionalLight(i, WorldPosition);
Light light = GetAdditionalLight(i, WorldPosition, shadowMask);
half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
diffuseColor += LightingLambert(attenuatedLightColor, light.direction, WorldNormal);
specularColor += LightingSpecular(attenuatedLightColor, light.direction, WorldNormal, WorldView, White, Smoothness);
Expand Down