浏览代码

Optimize SampleHemisphereCosine() to not require a tangent frame

/main
Evgenii Golubev 7 年前
当前提交
8db6f218
共有 2 个文件被更改,包括 22 次插入7 次删除
  1. 7
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/ImageBasedLighting.hlsl
  2. 22
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Sampling/Sampling.hlsl

7
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/ImageBasedLighting.hlsl


out real NdotL,
out real weightOverPdf)
{
#if 0
#else
real3 N = localToWorld[2];
L = SampleHemisphereCosine(u.x, u.y, N);
NdotL = saturate(dot(N, L));
#endif
// Importance sampling weight for each sample
// pdf = N.L / PI

22
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Sampling/Sampling.hlsl


return r * real2(cosPhi, sinPhi);
}
real3 SampleSphereUniform(real u1, real u2)
{
real phi = TWO_PI * u2;
real cosTheta = 1.0 - 2.0 * u1;
return SphericalToCartesian(phi, cosTheta);
}
// Performs cosine-weighted sampling of the hemisphere.
// Ref: PBRT v3, p. 780.
real3 SampleHemisphereCosine(real u1, real u2)

return localL;
}
real3 SampleHemisphereUniform(real u1, real u2)
// Cosine-weighted sampling without the tangent frame.
// Ref: http://www.amietia.com/lambertnotangent.html
real3 SampleHemisphereCosine(real u1, real u2, real3 normal)
real phi = TWO_PI * u2;
real cosTheta = 1.0 - u1;
return SphericalToCartesian(phi, cosTheta);
real3 pointOnSphere = SampleSphereUniform(u1, u2);
return normalize(normal + pointOnSphere);
real3 SampleSphereUniform(real u1, real u2)
real3 SampleHemisphereUniform(real u1, real u2)
real cosTheta = 1.0 - 2.0 * u1;
real cosTheta = 1.0 - u1;
return SphericalToCartesian(phi, cosTheta);
}

正在加载...
取消
保存