|
|
|
|
|
|
|
|
|
|
[branch] if (lightData.cookieIndex >= 0 && illuminance > 0.0) |
|
|
|
{ |
|
|
|
float3 unL = positionWS - lightData.positionWS; |
|
|
|
float3 lightToSurface = positionWS - lightData.positionWS; |
|
|
|
// Project 'unL' onto the light's axes. |
|
|
|
float2 coord = float2(dot(unL, lightData.right), dot(unL, lightData.up)); |
|
|
|
// Project 'lightToSurface' onto the light's axes. |
|
|
|
float2 coord = float2(dot(lightToSurface, lightData.right), dot(lightToSurface, lightData.up)); |
|
|
|
|
|
|
|
// Compute the NDC coordinates (in [-1, 1]^2). |
|
|
|
coord.x *= lightData.invScaleX; |
|
|
|
|
|
|
float len = lightData.size.x; |
|
|
|
float3 T = lightData.right; |
|
|
|
|
|
|
|
float3 unL = positionWS - lightData.positionWS; |
|
|
|
float3 unL = lightData.positionWS - positionWS; |
|
|
|
|
|
|
|
// Pick the major axis of the ellipsoid. |
|
|
|
float3 axis = lightData.right; |
|
|
|
|
|
|
float2 u = Hammersley2d(i, sampleCount); |
|
|
|
u = frac(u + randNum); |
|
|
|
|
|
|
|
float4x4 localToWorld = float4x4(float4(lightData.right, 0.0), float4(lightData.up, 0.0), float4(lightData.forward, 0.0), float4(lightData.positionWS, 1.0)); |
|
|
|
// Lights in Unity point backward. |
|
|
|
float4x4 localToWorld = float4x4(float4(lightData.right, 0.0), float4(lightData.up, 0.0), float4(-lightData.forward, 0.0), float4(lightData.positionWS, 1.0)); |
|
|
|
|
|
|
|
switch (lightData.lightType) |
|
|
|
{ |
|
|
|
|
|
|
float halfWidth = lightData.size.x * 0.5; |
|
|
|
float halfHeight = lightData.size.y * 0.5; |
|
|
|
|
|
|
|
float3 unL = positionWS - lightData.positionWS; |
|
|
|
float3 unL = lightData.positionWS - positionWS; |
|
|
|
float3x3 lightToWorld = float3x3(lightData.right, lightData.up, lightData.forward); |
|
|
|
float3x3 lightToWorld = float3x3(lightData.right, lightData.up, -lightData.forward); |
|
|
|
unL = mul(unL, transpose(lightToWorld)); |
|
|
|
|
|
|
|
// Define the dimensions of the attenuation volume. |
|
|
|
|
|
|
lightData.specularScale *= intensity; |
|
|
|
|
|
|
|
// TODO: store 4 points and save 12 cycles (24x MADs - 12x MOVs). |
|
|
|
float3 p0 = lightData.positionWS + lightData.right * -halfWidth + lightData.up * halfHeight; |
|
|
|
float3 p1 = lightData.positionWS + lightData.right * -halfWidth + lightData.up * -halfHeight; |
|
|
|
float3 p2 = lightData.positionWS + lightData.right * halfWidth + lightData.up * -halfHeight; |
|
|
|
float3 p3 = lightData.positionWS + lightData.right * halfWidth + lightData.up * halfHeight; |
|
|
|
float3 p0 = lightData.positionWS + lightData.right * halfWidth + lightData.up * halfHeight; |
|
|
|
float3 p1 = lightData.positionWS + lightData.right * halfWidth + lightData.up * -halfHeight; |
|
|
|
float3 p2 = lightData.positionWS + lightData.right * -halfWidth + lightData.up * -halfHeight; |
|
|
|
float3 p3 = lightData.positionWS + lightData.right * -halfWidth + lightData.up * halfHeight; |
|
|
|
|
|
|
|
float4x3 matL = float4x3(p0, p1, p2, p3) - float4x3(positionWS, positionWS, positionWS, positionWS); |
|
|
|
|
|
|
|