用蒙特卡洛求解积分时 (Monte Carlo 随机采样对目标积分函数做近似)
importance sampling func p(x)
p(x)值大的地方,Monte Carlo多采几次
值小的地方,少采样一些。
一起贡献MC的积分值
http://blog.sina.com.cn/s/blog_4e5740460100cw5b.html
link1
http://statweb.stanford.edu/~owen/mc/
对 GGX的importance的理解
ImportanceSampleGGX(float2 Xi, float Roughness, float3 N)
{
float a = Roughness * Roughness;
float Phi = 2 * PI * Xi.x;
float CosTheta = sqrt( (1 - Xi.y) / ( 1 + (a*a - 1) * Xi.y ) );
float SinTheta = sqrt( 1 - CosTheta * CosTheta );
float3 H;
H.x = SinTheta * cos( Phi );
H.y = SinTheta * sin( Phi );
H.z = CosTheta;
float3 UpVector = abs(N.z) < 0.999 ? float3(0,0,1) : float3(1,0,0);
float3 TangentX = normalize( cross( UpVector, N ) );
float3 TangentY = cross( N, TangentX );
// Tangent to world space
return TangentX * H.x + TangentY * H.y + N * H.z;
}
http://blog.tobias-franke.eu/2014/03/30/notes_on_importance_sampling.html
link2
链接里的代码,算得是极坐标下的p
我这段代码算得三维的H 换到xyz下面
但为什么p的值就变成H了呢 看着像微表面normal或者 半角向量
因为D就是这个定义 D就是微表面normal的分布函数
而微表面的normal朝各个方向 只有朝向l, v表征的h方向的有贡献,所以是h
整体看importanceSampleGGX的含义就是求解ggx了 公式 link2有提供
感觉,就是用个函数 积个PDF再弄个什么CDF不知道是什么 然后就求出来了 中间出现了P()
The NDF itself is defined as:
Just like above, we start out with the PDF for GGX:
As in the case of Phong, we create two functions for θθ and ϕϕ. First let’s create p(θ)p(θ):
integrate((a^2cos(t)sin(t))/(%pi((a^2−1)cos(t)^2+1)^2), p, 0, 2*%pi)
The integration for ϕϕ is the same as above, so we skip it and instead now create the CDF for p(θ)p(θ):
integrate((2a^2cos(t)sin(t))/((a^2−1)cos(t)^2+1)^2, t, 0, s)
Setting the CDF to a random variable and solving for ss yields:
solve(2a^2(1/((2a^4−4a^2+2)cos(s)^2+2a^2−2)−1/(2a^4−2a^2)) = x, s)
A simple GLSL function to generate important directions looks like this:
vec2 importance_sample_ggx(vec2 xi) { float phi = 2.0f * PI * xi.x; float theta = acos(sqrt((1.0f - xi.y)/ ((a*a - 1.0f) * xi.y + 1.0f) )); return vec2(phi, theta); }
===========
http://www.cnblogs.com/xbinworld/p/4266146.html