Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSAO的半球采样方法 #108

Open
shawn0326 opened this issue Nov 4, 2021 · 3 comments
Open

SSAO的半球采样方法 #108

shawn0326 opened this issue Nov 4, 2021 · 3 comments

Comments

@shawn0326
Copy link

var phi = halton(i + offset, 2) * (hemisphere ? 1 : 2) * Math.PI;

这里phi代表的是方位角吧,如果半球采样的话,theta 最大是 Math.PI,phi最大应该始终是2 * Math.PI。
另外,参考babylon的实现,建议处理一下theta角,避免因过于接近水平面而出现z-fight

@pissang
Copy link
Owner

pissang commented Nov 4, 2021

这里phi代表的是方位角吧,如果半球采样的话,theta 最大是 Math.PI,phi最大应该始终是2 * Math.PI。

这个半球是在 z 轴方向上的

@shawn0326
Copy link
Author

这个半球是在 z 轴方向上的

抱歉,刚刚也发现了这个问题,重新整理了下写法:

  1. 整理了xyz的上传方式,明确是在tbn空间下的xyz坐标,感觉更好理解一些。这两种写法的xyz在值域上是一样的。
  2. 引入了Babylon对theta角的优化(不过目前还没有证明该优化有效的例子)
var phi = halton(i + offset, 2) * Math.PI * 2;

// rejecting samples that are close to tangent plane to avoid z-fighting artifacts
var cosTheta = 1.0 - (halton(i + offset, 3) * 0.85 + 0.15);
var sinTheta = Math.sqrt(1.0 - cosTheta * cosTheta);

var r = Math.random();
// for tbn space
var x = Math.cos(phi) * sinTheta * r;
var y = Math.sin(phi) * sinTheta * r;
var z = cosTheta * r;

@pissang
Copy link
Owner

pissang commented Nov 4, 2021

@shawn0326 嗯一时想象不到这个效果怎么样,现在 clay-viewer 里是通过一个 bias 来控制的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants