float4 cookie = EvaluateCookie_Directional(lightLoopContext, lightData, lightToSurface);
// Premultiply.
lightData.color *= cookie.rgb;
lightData.diffuseScale *= cookie.a;
lightData.specularScale *= cookie.a;
lightData.diffuseColor *= cookie.rgb * cookie.a;
lightData.specularColor *= cookie.rgb * cookie.a;
}
[branch] if (illuminance > 0.0)
diffu seLighting *= illuminance * lightData.diffuseScal e;
specularLighting *= illuminance * lightData.specularScale;
diffuseLighting *= illuminance;
sp ecular Lighting *= illuminance;
}
[branch] if (bsdfData.enableTransmission)
float illuminance = Lambert() * ComputeWrappedDiffuseLighting(-NdotL, SSS_WRAP_LIGHT);
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass.
diffuseLighting += EvaluateTransmission(bsdfData, illuminance * lightData.diffuseScale , shadow);
diffuseLighting += EvaluateTransmission(bsdfData, illuminance, shadow);
// Save ALU by applying 'lightData. color' only once.
diffuseLighting *= lightData.c olor;
specularLighting *= lightData.color;
// Save ALU by applying 'color' only once.
diffuseLighting *= lightData.diffuseC olor;
specularLighting *= lightData.spe cularC olor;
lighting.directDiffuse += diffuseLighting;
lighting.directSpecular += specularLighting;
float attenuation = GetPunctualShapeAttenuation(lightData, L, distSq);
// Premultiply.
lightData.diffuseScale *= attenuation;
lightData.specularScale *= attenuation;
float colorScale = attenuation;
float3 diffuseLighting = float3(0.0, 0.0, 0.0);
float3 specularLighting = float3(0.0, 0.0, 0.0);
float volumetricShadow = Transmittance(OpticalDepthHomogeneous(preLightData.globalFogExtinction, dist));
// Premultiply.
lightData.diffuseScale *= volumetricShadow;
lightData.specularScale *= volumetricShadow;
colorScale *= volumetricShadow;
#endif
// Projector lights always have a cookies, so we can perform clipping inside the if().
// Premultiply.
lightData.color *= cookie.rgb;
lightData.diffuseScale *= cookie.a ;
lightData.specularScale *= cookie.a;
lightData.diffuseColor *= cookie.rgb;
lightData.specularColor *= cookie.rgb ;
colorScale *= cookie.a;
}
[branch] if (illuminance > 0.0)
diffuseLighting *= illuminance * lightData.diffuseScale ;
specularLighting *= illuminance * lightData.specularScale ;
diffuseLighting *= illuminance;
specularLighting *= illuminance;
}
[branch] if (bsdfData.enableTransmission)
float illuminance = Lambert() * ComputeWrappedDiffuseLighting(-NdotL, SSS_WRAP_LIGHT);
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass.
diffuseLighting += EvaluateTransmission(bsdfData, illuminance * lightData.diffuseScale , shadow);
diffuseLighting += EvaluateTransmission(bsdfData, illuminance, shadow);
// Save ALU by applying 'lightData. color' only once.
diffuseLighting *= lightData.color;
specularLighting *= lightData.color;
// Save ALU by applying 'color' only once.
diffuseLighting *= lightData.diffuseColor * colorScale ;
specularLighting *= lightData.specularColor * colorScale ;
lighting.directDiffuse += diffuseLighting;
lighting.directSpecular += specularLighting;
// Terminate if the shaded point is too far away.
if (intensity == 0.0) return;
lightData.diffuseScale *= intensity;
lightData.specularScale *= intensity;
lightData.diffuseColor *= intensity;
lightData.specularColor *= intensity;
// Translate the light s.t. the shaded point is at the origin of the coordinate system.
lightData.positionWS -= positionWS;
// Evaluate the diffuse part
{
ltcValue = LTCEvaluate(P1, P2, B, preLightData.ltcTransformDiffuse);
ltcValue *= lightData.diffuseScale;
diffuseLighting = bsdfData.diffuseColor * (preLightData.ltcMagnitudeDiffuse * ltcValue);
}
// Use the Lambertian approximation for performance reasons.
// The matrix multiplication should not generate any extra ALU on GCN.
ltcValue = LTCEvaluate(P1, P2, B, mul(flipMatrix, k_identity3x3));
ltcValue *= lightData.diffuseScale;
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass.
diffuseLighting += EvaluateTransmission(bsdfData, ltcValue, 1);
{
// TODO
// ltcValue = LTCEvaluate(P1, P2, B, preLightData.ltcXformClearCoat);
// ltcValue *= lightData.specularScale;
// specularLighting = preLightData.ltcClearCoatFresnelTerm * (ltcValue * bsdfData.coatCoverage);
}
ltcValue *= lightData.specularScale;
// Save ALU by applying 'lightData.color' only once.
diffuseLighting *= lightData.color;
specularLighting *= lightData.color;
// Save ALU by applying 'color' only once.
diffuseLighting *= lightData.diffuseColor;
specularLighting *= lightData.specularColor;
#endif // LIT_DISPLAY_REFERENCE_AREA
lighting.directDiffuse += diffuseLighting;
// Terminate if the shaded point is too far away.
if (intensity == 0.0) return;
lightData.diffuseScale *= intensity;
lightData.specularScale *= intensity;
lightData.diffuseColor *= intensity;
lightData.specularColor *= intensity;
// Translate the light s.t. the shaded point is at the origin of the coordinate system.
lightData.positionWS -= positionWS;
{
// Polygon irradiance in the transformed configuration.
ltcValue = PolygonIrradiance(mul(lightVerts, preLightData.ltcTransformDiffuse));
ltcValue *= lightData.diffuseScale;
diffuseLighting = bsdfData.diffuseColor * (preLightData.ltcMagnitudeDiffuse * ltcValue);
}
// Polygon irradiance in the transformed configuration.
ltcValue = PolygonIrradiance(mul(lightVerts, ltcTransform));
ltcValue *= lightData.diffuseScale;
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass.
diffuseLighting += EvaluateTransmission(bsdfData, ltcValue, 1);
{
// Polygon irradiance in the transformed configuration.
ltcValue = PolygonIrradiance(mul(lightVerts, preLightData.ltcTransformSpecular));
ltcValue *= lightData.specularScale;
// Save ALU by applying 'lightData.color' only once.
diffuseLighting *= lightData.color;
specularLighting *= lightData.color;
// Save ALU by applying 'color' only once.
diffuseLighting *= lightData.diffuseColor;
specularLighting *= lightData.specularColor;
#endif // LIT_DISPLAY_REFERENCE_AREA
lighting.directDiffuse += diffuseLighting;