|
|
|
|
|
|
// EvaluateBSDF_Directional |
|
|
|
//----------------------------------------------------------------------------- |
|
|
|
|
|
|
|
float4 EvaluateCookie_Directional(LightLoopContext lightLoopContext, DirectionalLightData lightData, |
|
|
|
float3 EvaluateCookie_Directional(LightLoopContext lightLoopContext, DirectionalLightData lightData, |
|
|
|
float3 lighToSample) |
|
|
|
{ |
|
|
|
// Compute the CS position (in [-1, 1]^2) by projecting 'positionWS' onto the near plane. |
|
|
|
|
|
|
positionNDC = lightData.tileCookie ? frac(positionNDC) : positionNDC; |
|
|
|
|
|
|
|
// We let the sampler handle clamping to border. |
|
|
|
float4 cookie = SampleCookie2D(lightLoopContext, positionNDC, lightData.cookieIndex); |
|
|
|
|
|
|
|
return cookie; |
|
|
|
return SampleCookie2D(lightLoopContext, positionNDC, lightData.cookieIndex); |
|
|
|
} |
|
|
|
|
|
|
|
// None of the outputs are premultiplied. |
|
|
|
|
|
|
[branch] if (lightData.cookieIndex >= 0) |
|
|
|
{ |
|
|
|
float3 lightToSample = positionWS - lightData.positionWS; |
|
|
|
float4 cookie = EvaluateCookie_Directional(lightLoopContext, lightData, lightToSample); |
|
|
|
float3 cookie = EvaluateCookie_Directional(lightLoopContext, lightData, lightToSample); |
|
|
|
color *= cookie.rgb; |
|
|
|
attenuation *= cookie.a; |
|
|
|
color *= cookie; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[branch] if (lightType == GPULIGHTTYPE_POINT) |
|
|
|
{ |
|
|
|
cookie = SampleCookieCube(lightLoopContext, positionLS, lightData.cookieIndex); |
|
|
|
cookie.rgb = SampleCookieCube(lightLoopContext, positionLS, lightData.cookieIndex); |
|
|
|
cookie.a = 1; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
float2 positionNDC = positionCS * 0.5 + 0.5; |
|
|
|
|
|
|
|
// Manually clamp to border (black). |
|
|
|
cookie = SampleCookie2D(lightLoopContext, positionNDC, lightData.cookieIndex); |
|
|
|
cookie.a = isInBounds ? cookie.a : 0; |
|
|
|
cookie.rgb = SampleCookie2D(lightLoopContext, positionNDC, lightData.cookieIndex); |
|
|
|
cookie.a = isInBounds ? 1 : 0; |
|
|
|
} |
|
|
|
|
|
|
|
return cookie; |
|
|
|