浏览代码

Optimize the computation of 'NdotL' during importance sampling

/main
Evgenii Golubev 8 年前
当前提交
0a562a91
共有 1 个文件被更改,包括 18 次插入18 次删除
  1. 36
      Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl

36
Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl


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;

正在加载...
取消
保存