}
// None of the outputs are premultiplied.
// Note: When doing transmission we always have only one shadow sample to do: Either front or back. We use NdotL to know on which side we are
float3 N, float3 L,
out float3 color, out float attenuation, out float attenuationNoContactShadows)
float3 N, float3 L, bool isThinModeTransmission,
out float3 color, out float attenuation)
float4 shadowData = float4(1, 1, 1, 1);
float contactShadow = 1.0;
color = lightData.color;
attenuation = 1.0; // Note: no volumetric attenuation along shadow rays for directional lights
shadow = shadowMask = (lightData.shadowMaskSelector.x >= 0.0) ? dot(bakeLightingData.bakeShadowMask, lightData.shadowMaskSelector) : 1.0;
#endif
UNITY_BRANCH if (lightData.shadowIndex >= 0)
float NdotL = dot(N, L);
// We test NdotL > 0.0 to not sample the shadow map if it is not required.
// In case of thin mode we always need to perform the fetch as we reuse it for back and front lighting
UNITY_BRANCH if (lightData.shadowIndex >= 0 && (isThinModeTransmission || NdotL >= 0.0))
shadow = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, positionWS, N, lightData.shadowIndex, L, posInput.positionSS);
shadow = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, positionWS, NdotL > 0.0 ? N : -N, lightData.shadowIndex, L, posInput.positionSS);
#endif
#ifdef SHADOWS_SHADOWMASK
// Note: There is no shadowDimmer when there is no shadow mask
#endif
// Volumetric don't use screenspace shadow. Transparent neither (as we don't have the depth information)
contactShadow = GetContactShadow(lightLoopContext, lightData.contactShadowIndex);
// Don't apply shadow contact on transmismission
shadow = isThinModeTransmission ? shadow : min(shadow, GetContactShadow(lightLoopContext, lightData.contactShadowIndex));
attenuationNoContactShadows = shadow * attenuation;
attenuation *= min(shadow, contactShadow);
attenuation *= shadow;
}
//-----------------------------------------------------------------------------
// None of the outputs are premultiplied.
// distances = {d, d^2, 1/d, d_proj}, where d_proj = dot(lightToSample, lightData.forward).
// Note: When doing transmission we always have only one shadow sample to do: Either front or back. We use NdotL to know on which side we are
float3 N, float3 L, float3 lightToSample, float4 distances,
out float3 color, out float attenuation, out float attenuationNoContactShadows)
float3 N, float3 L, float3 lightToSample, float4 distances, bool isThinModeTransmission,
out float3 color, out float attenuation)
float contactShadow = 1.0;
color = lightData.color;
attenuation = SmoothPunctualLightAttenuation(distances, lightData.invSqrAttenuationRadius,
shadow = shadowMask = (lightData.shadowMaskSelector.x >= 0.0) ? dot(bakeLightingData.bakeShadowMask, lightData.shadowMaskSelector) : 1.0;
#endif
UNITY_BRANCH if (lightData.shadowIndex >= 0)
float NdotL = dot(N, L);
// We test NdotL > 0.0 to not sample the shadow map if it is not required.
// In case of thin mode we always need to perform the fetch as we reuse it for back and front lighting
UNITY_BRANCH if (lightData.shadowIndex >= 0 && (isThinModeTransmission || NdotL >= 0.0))
shadow = GetPunctualShadowAttenuation(lightLoopContext.shadowContext, positionWS, N, lightData.shadowIndex, L, distances.x, posInput.positionSS);
// Note:the case of NdotL < 0 can appear with isThinModeTransmission, in this case we need to flip the shadow bias
shadow = GetPunctualShadowAttenuation(lightLoopContext.shadowContext, positionWS, NdotL > 0.0 ? N : -N, lightData.shadowIndex, L, distances.x, posInput.positionSS);
#ifdef SHADOWS_SHADOWMASK
// Note: Legacy Unity have two shadow mask mode. ShadowMask (ShadowMask contain static objects shadow and ShadowMap contain only dynamic objects shadow, final result is the minimun of both value)
shadow = lerp(1.0, shadow, lightData.shadowDimmer);
#endif
// Volumetric don't use screenspace shadow. Transparent neither (as we don't have the depth information)
contactShadow = GetContactShadow(lightLoopContext, lightData.contactShadowIndex);
// Don't apply shadow contact on transmismission
shadow = isThinModeTransmission ? shadow : min(shadow, GetContactShadow(lightLoopContext, lightData.contactShadowIndex));
attenuationNoContactShadows = shadow * attenuation;
attenuation *= min(shadow, contactShadow);
attenuation *= shadow;
}
// Environment map share function