|
|
|
|
|
|
|
|
|
|
void ImportanceSampleCosDir(float2 u, |
|
|
|
float3x3 localToWorld, |
|
|
|
out float3 L) |
|
|
|
out float3 L, |
|
|
|
out float NdotL) |
|
|
|
{ |
|
|
|
// Cosine sampling - ref: http://www.rorydriscoll.com/2009/01/07/better-sampling/ |
|
|
|
float cosTheta = sqrt(saturate(1.0 - u.x)); |
|
|
|
|
|
|
L = SphericalToCartesian(phi, sinTheta, cosTheta); |
|
|
|
L = mul(L, localToWorld); |
|
|
|
float3 localL = SphericalToCartesian(phi, sinTheta, cosTheta); |
|
|
|
|
|
|
|
NdotL = localL.z; |
|
|
|
|
|
|
|
L = mul(localL, localToWorld); |
|
|
|
} |
|
|
|
|
|
|
|
void ImportanceSampleGGXDir(float2 u, |
|
|
|
|
|
|
out float3 L, |
|
|
|
out float NdotL, |
|
|
|
out float NdotH, |
|
|
|
out float VdotH, |
|
|
|
bool VeqN = false) |
|
|
|
|
|
|
VdotH = saturate(dot(localV, localH)); |
|
|
|
} |
|
|
|
|
|
|
|
// Compute { L = reflect(-localV, localH) } |
|
|
|
L = -localV + 2.0 * VdotH * localH; |
|
|
|
// Compute { localL = reflect(-localV, localH) } |
|
|
|
float3 localL = -localV + 2.0 * VdotH * localH; |
|
|
|
L = mul(L, localToWorld); |
|
|
|
NdotL = localL.z; |
|
|
|
|
|
|
|
L = mul(localL, localToWorld); |
|
|
|
} |
|
|
|
|
|
|
|
// ref: http://blog.selfshadow.com/publications/s2012-shading-course/burley/s2012_pbs_disney_brdf_notes_v3.pdf p26 |
|
|
|
|
|
|
out float NdotL, |
|
|
|
out float weightOverPdf) |
|
|
|
{ |
|
|
|
ImportanceSampleCosDir(u, localToWorld, L); |
|
|
|
|
|
|
|
NdotL = saturate(dot(localToWorld[2], L)); |
|
|
|
ImportanceSampleCosDir(u, localToWorld, L, NdotL); |
|
|
|
|
|
|
|
// Importance sampling weight for each sample |
|
|
|
// pdf = N.L / PI |
|
|
|
|
|
|
out float NdotL, |
|
|
|
out float weightOverPdf) |
|
|
|
{ |
|
|
|
float3 H; |
|
|
|
float NdotH; |
|
|
|
ImportanceSampleGGXDir(u, V, localToWorld, roughness, L, NdotH, VdotH); |
|
|
|
|
|
|
|
NdotL = saturate(dot(localToWorld[2], L)); |
|
|
|
float NdotH; |
|
|
|
ImportanceSampleGGXDir(u, V, localToWorld, roughness, L, NdotL, NdotH, VdotH); |
|
|
|
|
|
|
|
// Importance sampling weight for each sample |
|
|
|
// pdf = D(H) * (N.H) / (4 * (L.H)) |
|
|
|
|
|
|
u.x = lerp(u.x, 0.0, bias); |
|
|
|
|
|
|
|
float3 L; |
|
|
|
float NdotH, VdotH; |
|
|
|
ImportanceSampleGGXDir(u, V, localToWorld, roughness, L, NdotH, VdotH, true); |
|
|
|
|
|
|
|
float NdotL = saturate(dot(N, L)); |
|
|
|
float NdotL, NdotH, VdotH; |
|
|
|
ImportanceSampleGGXDir(u, V, localToWorld, roughness, L, NdotL, NdotH, VdotH, true); |
|
|
|
|
|
|
|
float mipLevel; |
|
|
|
|
|
|
|