用蒙特卡洛求解积分时 (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. CSU-1908 The Big Escape

    CSU-1908 The Big Escape Description There is a tree-like prison. Expect the root node, each node has ...

  2. csu-2018年11月月赛Round2-div2题解

    csu-2018年11月月赛Round2-div2题解 A(2193):昆虫繁殖 Description 科学家在热带森林中发现了一种特殊的昆虫,这种昆虫的繁殖能力很强.每对成虫过x个月产y对卵,每对 ...

  3. Java 语言概述与开发环境(2)

    目录: 一.JDK配置容易出现的问题 二.HelloWorld程序编译常见问题 三.文档注释 四.Java 标识符 五.转义符 六.运算符之算术运算符   ********************** ...

  4. [oldboy-django][2深入django]浏览器同源策略 + JSONP + cros

    浏览器的同源策略: - 同源: 同方法,同域名,同端口 http://www.baidu.com:8000 http: 方法 www.baidu.com: 域名 8000: 端口 - 定义 网上解析非 ...

  5. springdata jpa

    (转自:http://www.cnblogs.com/ityouknow/p/5891443.html) 首先了解JPA是什么? JPA(Java Persistence API)是Sun官方提出的J ...

  6. hihoCoder [Offer收割]编程练习赛83 D 生成树问题

    题目 从 Kruskal 算法的角度来思考这个问题. 考虑 $n$ 个点的"空图"(即没有边的图). 先将 $m_2$ 条无权值的边加到图中,得到一个森林. 按边权从小到大的顺序枚 ...

  7. [canvas入坑0] Jquery + HTML5 做最简易的画板

    查看效果请到 http://philippica.github.io/  点击paint 嗯,心血来潮想做个东西的一部分 html部分不用多说了,重点就是一个canvas <!DOCTYPE h ...

  8. java简易DVD影片管理系统—面向对象

    public class DvdSet { String name [] =new String[15]; // DVD电影名称 String date [] =new String[15]; //D ...

  9. HashMap实现原理及源码分析(jdk1.8)

    HashMap底层由数组+链表+红黑树组成,可接受null值,非线程安全 1.基本属性 transient Node<K,V>[] table; //hashmap数组 static fi ...

  10. g2o初始化一些

    今天看了一下智能指针的东西,发现更简单的思路: 就是Block和solver构造时,需要传递unique_ptr,那我们将普通指针转换成unique_ptr不就可以了么: // 初始化g2o //第一 ...