|
|
|
|
|
|
// Static branch. |
|
|
|
if (lightType == GPULIGHTTYPE_PROJECTOR_BOX) |
|
|
|
{ |
|
|
|
// bool isInBounds = max(abs(positionNDC.x), abs(positionNDC.y)) <= 1 && positionLS.z >= 0; |
|
|
|
// float clipFactor = isInBounds ? 1 : 0; |
|
|
|
// This version is slightly more efficient: |
|
|
|
float clipFactor = saturate(FLT_MAX - FLT_MAX * Max3(abs(positionNDC.x), abs(positionNDC.y), positionLS.z >= 0 ? 0 : 1)); |
|
|
|
bool isInBounds = Max3(abs(positionNDC.x), abs(positionNDC.y), 1 - positionLS.z) <= 1; |
|
|
|
clipFactor = isInBounds ? 1 : 0; |
|
|
|
} |
|
|
|
|
|
|
|
float attenuation = clipFactor; |
|
|
|
|
|
|
{ |
|
|
|
// Compute the NDC position (in [-1, 1]^2) by projecting 'positionWS' onto the plane at 1m distance. |
|
|
|
// Box projector lights require no perspective division. |
|
|
|
float perspectiveZ = (lightType != GPULIGHTTYPE_PROJECTOR_BOX) ? positionLS.z : 1; |
|
|
|
float2 positionNDC = positionLS.xy / perspectiveZ; |
|
|
|
// bool isInBounds = max(abs(positionNDC.x), abs(positionNDC.y)) <= 1 && positionLS.z >= 0; |
|
|
|
// float clipFactor = isInBounds ? 1 : 0; |
|
|
|
// This version is slightly more efficient: |
|
|
|
float clipFactor = saturate(FLT_MAX - FLT_MAX * Max3(abs(positionNDC.x), abs(positionNDC.y), positionLS.z >= 0 ? 0 : 1)); |
|
|
|
float perspectiveZ = (lightType != GPULIGHTTYPE_PROJECTOR_BOX) ? positionLS.z : 1; |
|
|
|
float2 positionNDC = positionLS.xy / perspectiveZ; |
|
|
|
bool isInBounds = Max3(abs(positionNDC.x), abs(positionNDC.y), 1 - positionLS.z) <= 1; |
|
|
|
float clipFactor = isInBounds ? 1 : 0; |
|
|
|
|
|
|
|
// Remap the texture coordinates from [-1, 1]^2 to [0, 1]^2. |
|
|
|
float2 coord = positionNDC * 0.5 + 0.5; |
|
|
|