zoukankan      html  css  js  c++  java
  • Importance sampling

    用蒙特卡洛求解积分时 (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:

    D(m)=α2π(cos2(nm)(α21)+1)2(11)(11)D(m)=α2π(cos2⁡(n⋅m)(α2−1)+1)2

    Just like above, we start out with the PDF for GGX:

    p(θ,ϕ)=α2π(cos2θ(α21)+1)2cosθsinθ(12)(12)p(θ,ϕ)=α2π(cos2⁡θ(α2−1)+1)2cos⁡θsin⁡θ

    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)

    p(θ)=2π0p(θ,ϕ)dϕ=2α2(cos2θ(α21)+1)2cosθsinθ(13)(13)p(θ)=∫02πp(θ,ϕ)dϕ=2α2(cos2⁡θ(α2−1)+1)2cos⁡θsin⁡θ

    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)

    P(sθ)=sθ0p(θ)dθ=(14)(14)P(sθ)=∫0sθp(θ)dθ=
    2α2(1(2α44α2+2)cos2sθ+2α2212α42α2)(15)(15)2α2(1(2α4−4α2+2)cos2⁡sθ+2α2−2−12α4−2α2)

    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)

    P(sθ)=ξθ(16)(16)P(sθ)=ξθ
    sθ=cos1(1ξθ(α21)ξθ+1−−−−−−−−−−−−√)(17)(17)sθ=cos−1(1−ξθ(α2−1)ξθ+1)

    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


    ================
    https://www.cnblogs.com/minggoddess/p/14645677.html
  • 相关阅读:
    预备作业03 20162308马平川
    预备作业02 20162308 马平川
    预备作业01
    采用dlopen、dlsym、dlclose加载动态链接库
    FastCGI协议分析
    Fastcgi协议定义解释与说明
    linux exec函数族
    进程通信---FIFO
    FTP协议及工作原理详解
    HTTP协议详解
  • 原文地址:https://www.cnblogs.com/minggoddess/p/6074707.html
Copyright © 2011-2022 走看看