用蒙特卡洛求解积分时 (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. pc和移动端获取滚动条的位置

    移动端获取滚动条:document.body.scrollTop pc端获取滚动条:document.documentElement.scrollTop

  2. C++指针详解 (转)

    C++指针详解 指针的概念 指针是一个特殊的变量,它里面存储的数值被解释成为内存里的一个地址.要搞清一个指针需要搞清指针的四方面的内容:指针的类型,指针所指向的类型,指针的值或者叫指针所指向的内存区, ...

  3. DFS排列组合问题

    这四个使用DFS来求解所有组合和排列的例子很有代表性,这里做一个总结: 1.不带重复元素的子集问题 public ArrayList<ArrayList<Integer>> s ...

  4. [oldboy-django][1初识django]创建虚拟(干净)的Python环境

    如果应用A需要jinja 2.7,而应用B需要jinja 2.6怎么办?此时可以针对不同应用创建不同的虚拟环境. 这种情况下,每个应用可能需要各自拥有一套“独立”的Python运行环境.virtual ...

  5. 来自知乎的pthread_cond_wait为什么总是带着mutex

       来自https://www.zhihu.com/question/24116967?q=linux%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%20%E8%99%9A%E5%81 ...

  6. 【bzoj4999】This Problem Is Too Simple! 树链剖分+动态开点线段树

    题目描述 给您一颗树,每个节点有个初始值. 现在支持以下两种操作: 1. C i x(0<=x<2^31) 表示将i节点的值改为x. 2. Q i j x(0<=x<2^31) ...

  7. [HNOI2004][bzoj1212] L语言 [Trie+dp]

    题面 传送门 思路 无后效性 显然,不管某个前缀的理解方式是怎么样的,如果它能被理解,那么前面的决策对于后面的决策而言都是等价的 因此这题可以DP DP方程 令$dp[i]$表示前缀i是否能被理解 那 ...

  8. 二进制包部署Kubernetes集群

    今天这篇文章教给大家如何快速部署一套Kubernetes集群.K8S集群部署有几种方式:kubeadm.minikube和二进制包.前两者属于自动部署,简化部署操作,我们这里强烈推荐初学者使用二进制包 ...

  9. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] D 数学+(前缀 后缀 预处理)

    D. "Or" Game time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  10. 卷积神经网络用语句子分类---Convolutional Neural Networks for Sentence Classification 学习笔记

    读了一篇文章,用到卷积神经网络的方法来进行文本分类,故写下一点自己的学习笔记: 本文在事先进行单词向量的学习的基础上,利用卷积神经网络(CNN)进行句子分类,然后通过微调学习任务特定的向量,提高性能. ...