用蒙特卡洛求解積分時 (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