简体   繁体   English

在Three.js中更正透视裁剪

[英]Correcting for perspective clipping in Three.js

I have a plane inside of a sphere in Three.js that I am rendering a shader to so that I can get effects on the sphere. 我在Three.js的球体内部有一个平面,我正在将着色器渲染到该平面上,以便可以在球体上获得效果。 I also use lookAt to align the plane with the camera. 我还使用lookAt将平面与相机对齐。 The issue I am experiencing is that if the camera gets too close to the sphere the plane seems to shrink into the sphere. 我遇到的问题是,如果相机离球体太近,则平面似乎会收缩到球体中。 I have determined the problem to be from the perspective nature of the camera as when the camera gets too close to the sphere its rays don't align with the edge of the plane anymore. 我已确定问题出在相机的角度上,因为当相机离球体太近时,其光线不再与平面边缘对齐。

Here is a picture visualizing this: Perspective clipping 这是可视化的图片: 透视图裁剪

Also here is a JSFiddle that demonstrates this: https://jsfiddle.net/k8tc8ex6/1/ 另外,这里还有一个JSFiddle演示了这一点: https ://jsfiddle.net/k8tc8ex6/1/

I know why this issue occurs, what I want to know is some possible solutions, what I am trying to achieve is that the edge of the plane will always appear to touch the edge of the sphere after the render. 我知道为什么会发生此问题,我想知道是一些可能的解决方案,我要实现的目标是,渲染 ,平面的边缘将始终看起来像接触球体的边缘。

Thanks so much in advance! 非常感谢!

if I am right you are trying to "perfectly" fit mid section of a sphere into frustum of a perspective camera. 如果我是对的,那么您正在尝试将球体的中间部分“完美地”安装到透视相机的视锥中。 What you are trying to achieve is impossible with a perspective view. 透视图无法实现您想要实现的目标。 As you said (demonstrated) the plane will exceed the bounds of the screen or there will be gaps with the edges of the plane and the screen. 如您所说(已演示),该平面将超出屏幕的边界,或者该平面和屏幕的边缘之间会有间隙。

If you badly want to "perfectly" fit the midsection of a sphere into the screen, you have 2 options: 如果您非常想“完美”地将球体的中间部分放入屏幕中,则有两种选择:

1-) switch to orthographic camera 2-) stick to perspective camera, make your FOV very close to 0, give a huge distance to far plane so that your perspective camera will actually act as an orthographic camera. 1-)切换到正交摄影机2-)坚持使用透视摄影机,使您的FOV非常接近0,与远平面保持较大距离,这样您的透视摄影机实际上就可以充当正交摄影机。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM