|
|
|
|
|
|
// we need to push the shading position back to avoid self-shadowing problems. |
|
|
|
float3 ComputeThicknessDisplacement(BSDFData bsdfData, float3 L, float NdotL) |
|
|
|
{ |
|
|
|
// Compute the thickness in world units along the normal. |
|
|
|
float thicknessInMeters = bsdfData.thickness * METERS_PER_MILLIMETER; |
|
|
|
float thicknessInUnits = thicknessInMeters * _WorldScales[bsdfData.subsurfaceProfile].y; |
|
|
|
float displacement = 0; |
|
|
|
|
|
|
|
[flatten] if (bsdfData.useThickObjectMode && NdotL < 0) |
|
|
|
{ |
|
|
|
// Compute the thickness in world units along the normal. |
|
|
|
float thicknessInMeters = bsdfData.thickness * METERS_PER_MILLIMETER; |
|
|
|
float thicknessInUnits = thicknessInMeters * _WorldScales[bsdfData.subsurfaceProfile].y; |
|
|
|
// Compute the thickness in world units along the light vector. |
|
|
|
float unprojectedThickness = thicknessInUnits / -NdotL; |
|
|
|
// Compute the thickness in world units along the light vector. |
|
|
|
displacement = thicknessInUnits / -NdotL; |
|
|
|
} |
|
|
|
return unprojectedThickness * L; |
|
|
|
return displacement * L; |
|
|
|
} |
|
|
|
|
|
|
|
// Currently, we only model diffuse transmission. Specular transmission is not yet supported. |
|
|
|
|
|
|
float3 L = -lightData.forward; // Lights point backward in Unity |
|
|
|
float NdotL = dot(N, L); |
|
|
|
|
|
|
|
[flatten] if (bsdfData.useThickObjectMode && NdotL < 0) |
|
|
|
{ |
|
|
|
posInput.positionWS += ComputeThicknessDisplacement(bsdfData, L, NdotL); |
|
|
|
} |
|
|
|
posInput.positionWS += ComputeThicknessDisplacement(bsdfData, L, NdotL); |
|
|
|
|
|
|
|
float3 color; float attenuation; |
|
|
|
EvaluateLight_Directional(lightLoopContext, posInput, lightData, bakeLightingData, N, L, |
|
|
|
|
|
|
|
|
|
|
[branch] if (intensity > 0.0) |
|
|
|
[branch] if (intensity > 0) |
|
|
|
{ |
|
|
|
BSDF(V, L, posInput.positionWS, preLightData, bsdfData, lighting.diffuse, lighting.specular); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[flatten] if (bsdfData.enableTransmission) |
|
|
|
[branch] if (bsdfData.enableTransmission) |
|
|
|
{ |
|
|
|
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass. |
|
|
|
lighting.diffuse += EvaluateTransmission(bsdfData, NdotL, preLightData.NdotV, attenuation * lightData.diffuseScale); |
|
|
|
|
|
|
float3 L = unL * distRcp; |
|
|
|
float NdotL = dot(N, L); |
|
|
|
|
|
|
|
[flatten] if (bsdfData.useThickObjectMode && NdotL < 0) |
|
|
|
{ |
|
|
|
posInput.positionWS += ComputeThicknessDisplacement(bsdfData, L, NdotL); |
|
|
|
} |
|
|
|
posInput.positionWS += ComputeThicknessDisplacement(bsdfData, L, NdotL); |
|
|
|
|
|
|
|
float3 color; float attenuation; |
|
|
|
EvaluateLight_Punctual(lightLoopContext, posInput, lightData, bakeLightingData, N, L, dist, distSq, |
|
|
|
|
|
|
|
|
|
|
[branch] if (intensity > 0.0) |
|
|
|
[branch] if (intensity > 0) |
|
|
|
{ |
|
|
|
// Simulate a sphere light with this hack. |
|
|
|
bsdfData.roughnessT = max(bsdfData.roughnessT, lightData.minRoughness); |
|
|
|
|
|
|
lighting.specular *= intensity * lightData.specularScale; |
|
|
|
} |
|
|
|
|
|
|
|
[flatten] if (bsdfData.enableTransmission) |
|
|
|
[branch] if (bsdfData.enableTransmission) |
|
|
|
{ |
|
|
|
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass. |
|
|
|
lighting.diffuse += EvaluateTransmission(bsdfData, NdotL, preLightData.NdotV, attenuation * lightData.diffuseScale); |
|
|
|