用蒙特卡洛求解积分时 (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(n⋅m)(α2−1)+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θ(α2−1)+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θ(α2−1)+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α4−4α2+2)cos2sθ+2α2−2−12α4−2α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θ=cos−1(1−ξθ(α2−1)ξθ+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

Importance sampling的更多相关文章

  1. 蒙特卡洛法计算定积分—Importance Sampling

    如上图所示,计算区间[a  b]上f(x)的积分即求曲线与X轴围成红色区域的面积.下面使用蒙特卡洛法计算区间[2  3]上的定积分:∫(x2+4*x*sin(x))dx # -*- coding: u ...

  2. Implemented the “Importance Sampling of Reflections from Hair Fibers”

      Just the indirect specular pass by importance sampling. With all layers. Manually traced by 3D Ham ...

  3. [Bayes] Hist & line: Reject Sampling and Importance Sampling

    吻合度蛮高,但不光滑. > L= > K=/ > x=runif(L) > *x*(-x)^/K)) > hist(x[ind],probability=T, + xla ...

  4. Not All Samples Are Created Equal: Deep Learning with Importance Sampling

    目录 概 主要内容 "代码" Katharopoulos A, Fleuret F. Not All Samples Are Created Equal: Deep Learnin ...

  5. 转 如何理解 重要性采样(importance sampling)

    分类: 我叫学术帖2011-03-25 13:22 3232人阅读 评论(4) 收藏 举报 图形 重要性采样是非常有意 思的一个方法.我们首先需要明确,这个方法是基于采样的,也就是基于所谓的蒙特卡洛法 ...

  6. PRML读书会第十一章 Sampling Methods(MCMC, Markov Chain Monte Carlo,细致平稳条件,Metropolis-Hastings,Gibbs Sampling,Slice Sampling,Hamiltonian MCMC)

    主讲人 网络上的尼采 (新浪微博: @Nietzsche_复杂网络机器学习) 网络上的尼采(813394698) 9:05:00  今天的主要内容:Markov Chain Monte Carlo,M ...

  7. 随机采样方法整理与讲解(MCMC、Gibbs Sampling等)

    本文是对参考资料中多篇关于sampling的内容进行总结+搬运,方便以后自己翻阅.其实参考资料中的资料写的比我好,大家可以看一下!好东西多分享!PRML的第11章也是sampling,有时间后面写到P ...

  8. [Bayes] runif: Inversion Sampling

    runifum Inversion Sampling 看样子就是个路人甲. Ref: [Bayes] Hist & line: Reject Sampling and Importance S ...

  9. [Bayes] What is Sampling

    Ref: http://blog.csdn.net/xianlingmao/article/details/7768833 通常,我们会遇到很多问题无法用分析的方法来求得精确解,例如由于式子特别,真的 ...

随机推荐

  1. kickstart配置文件详解和system-config-kickstart

    kickstart是什么         许多系统管理员宁愿使用自动化的安装方法来安装红帽企业 Linux.为了满足这种需要,红帽创建了kickstart安装方法.使用kickstart,系统管理员可 ...

  2. manjaro安装anaconda出错

    出错信息: ==> Creating package "anaconda"...  -> Generating .PKGINFO file...  -> Gene ...

  3. UVALive 5987

    求第n个数,该数满足至少由3个不同的素数的乘机组成 #include #include #include #include #include using namespace std; int prim ...

  4. Log4j官方文档翻译(九、输出到数据库)

    log4j提供了org.apache.log4j.JDBCAppender对象,可以把日志输出到特定的数据库. 常用的属性: bufferSize 设置buffer的大小,默认是1 driver 设置 ...

  5. iframe+json

    import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.serializer.PropertyFilter; impor ...

  6. Web系统从Oracle迁移至MySQL

    前两天领导给了个活,数据库迁移,原来的系统是用的Oracle数据库,现在要改成MySql,当时没多想就接下来了,原来的系统用的框架式SSI,于是大概想了下需要作调整无非以下几点 第一 数据库迁移 第二 ...

  7. HDOJ Important Sisters

    Important Sisters Time Limit: 7000/7000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  8. @RequestMapping定义不同的处理器映射规则

    通过@RequestMapping注解可以定义不同的处理器映射规则. 1. URL路径映射 @RequestMapping(value="item")或@RequestMappin ...

  9. Android蓝牙介绍

    1. 介绍 自从Android 4.2开始,Android开始使用自己的蓝牙协议栈BlueDroid,而不是bluez BlueDroid可分为两层: - BTE: Bluetooth Embedde ...

  10. 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---10

    以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下: