|
|
|
|
|
|
float3 L = lightData.direction; |
|
|
|
float illuminance = saturate(dot(bsdfData.normalWS, L)); |
|
|
|
|
|
|
|
diffuseLighting = float3(0.0, 0.0, 0.0); |
|
|
|
specularLighting = float3(0.0, 0.0, 0.0); |
|
|
|
diffuseLighting = float3(0.0, 0.0, 0.0); |
|
|
|
specularLighting = float3(0.0, 0.0, 0.0); |
|
|
|
float3 cookieColor = float3(1.0, 1.0, 1.0); |
|
|
|
|
|
|
|
[branch] if (lightData.shadowIndex >= 0 && illuminance > 0.0f) |
|
|
|
{ |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
[branch] if (lightData.cookieIndex != INT_MIN && illuminance > 0.0) |
|
|
|
{ |
|
|
|
float4 cookie; |
|
|
|
|
|
|
|
[branch] if (lightData.cookieIndex >= 0) |
|
|
|
{ |
|
|
|
// The cookie is a 2D texture. |
|
|
|
float3 unL = positionWS - lightData.positionWS; |
|
|
|
|
|
|
|
// Project 'unL' onto the light's axes. |
|
|
|
float3 right = cross(lightData.up, lightData.direction); |
|
|
|
float2 coord = float2(dot(unL, right), dot(unL, lightData.up)); |
|
|
|
|
|
|
|
// Rescale the texture. |
|
|
|
coord.x *= lightData.invScaleX; |
|
|
|
coord.y *= lightData.invScaleY; |
|
|
|
|
|
|
|
// Remap the texture coordinates from [-1, 1]^2 to [0, 1]^2. |
|
|
|
coord = coord * 0.5 + 0.5; |
|
|
|
|
|
|
|
// Tile the texture via wrapping. TODO: the sampler should do this for us. |
|
|
|
cookie = SampleCookie2D(lightLoopContext, frac(coord), lightData.cookieIndex); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// The cookie is a cubemap. We flip the bits to get the real index. |
|
|
|
lightData.cookieIndex = ~lightData.cookieIndex; |
|
|
|
|
|
|
|
cookie = SampleCookieCube(lightLoopContext, L, lightData.cookieIndex); |
|
|
|
} |
|
|
|
|
|
|
|
cookieColor = cookie.rgb; |
|
|
|
illuminance *= cookie.a; |
|
|
|
} |
|
|
|
|
|
|
|
[branch] if (illuminance > 0.0f) |
|
|
|