使用顶点着色器计算球体的边界四边形

发布于 2024-08-30 17:40:56 字数 156 浏览 13 评论 0原文

我正在尝试从图形纸实现一种算法,该算法的一部分是将已知半径的球体渲染到缓冲区。他们说,他们通过在顶点着色器中计算位置和大小,然后在片段着色器中进行适当的着色来渲染球体。

你猜猜他们实际上是如何做到这一点的?位置和半径在世界坐标中已知,并且投影是透视的。这是否意味着球体将被投影为圆?

I'm trying to implement an algorithm from a graphics paper and part of the algorithm is rendering spheres of known radius to a buffer. They say that they render the spheres by computing the location and size in a vertex shader and then doing appropriate shading in a fragment shader.

Any guesses as to how they actually did this? The position and radius are known in world coordinates and the projection is perspective. Does that mean that the sphere will be projected as a circle?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

日久见人心 2024-09-06 17:40:56

我找到了一篇描述您需要什么的论文 - 计算边界二次函数。请参阅:

http://web4.cs。 ucl.ac.uk/staff/t.weyrich/projects/quadrics/pbg06.pdf

第 3.2 节,边界框计算。该论文还提到在顶点着色器上执行此操作,因此这可能就是您所追求的。

一些个人想法:

不过,您可以通过按半径近似球体的大小来近似边界框。将其转换为屏幕空间,您将得到一个比正确的边界框稍大的值,但不会相差那么远。当然,当相机距离该点太近或者球体太大时,这种方法就会失败。但除此之外,计算起来应该是非常理想的,因为它只是两个相似的直角三角形之间的比率。

如果您能算出弦长,那么该比率将产生精确的答案,但那就是目前有点超出我的范围。

替代文本 http://xavierho.com/temp/Sphere-Screen-Space.png< /a>

当然,这只是一个粗略的近似值,有时会出现很大的错误,但它会让事情变得快速、简单。

否则,请参阅上面链接的论文并使用正确的方法。 =]

I found a paper that describes what you need - calculating the bounding quadric. See:

http://web4.cs.ucl.ac.uk/staff/t.weyrich/projects/quadrics/pbg06.pdf

Section 3.2, Bounding Box calculation. The paper also mentions doing it on the vertex shader, so it might be what you're after.

Some personal thought:

You can approximate the bounding box by approximating the size of the sphere by its radius, though. Transform that to screen space and you'll get a slightly larger than correct bounding box, but it won't be that far off. This fails when the camera is too close to the point, or when the sphere it too large, of course. But otherwise should be quite optimal to calculate, as it would be simply a ratio between two similar, right triangles.

If you can figure out the chord length, then the ratio will yield the precise answer, but that's a little beyond me at the moment.

alt text http://xavierho.com/temp/Sphere-Screen-Space.png

Of course, that's just a rough approximation, and has a large error sometimes, but it would get things going quickly, easy.

Otherwise, see paper linked above and use the correct way. =]

强者自强 2024-09-06 17:40:56

球体将被投影为椭圆形,除非它像 Brainjam 所说的那样位于摄像机中心。

Xavier Ho 链接的文章描述了球面投影(即二次投影)的推广。这是一本非常好的读物,我也推荐它。但是,如果您只对球体投影感兴趣,更准确地说是对投影边界的四边形感兴趣,则 稳健模板阴影的机制,第 6 页:剪刀优化 详细介绍了如何执行此操作。

关于 Xavier Ho 近似值的注释

我想补充一点,Xavier Ho 所建议的近似值,正如他也指出的那样,非常近似。我实际上将它用于基于图块的前向渲染器来近似屏幕空间中的光边界。下图显示了它如何在场景中使用 400 个全向(球形边界)灯光巧妙地实现良好的性能: 基于图块渲染 - 远景。然而,就像 Xavier Ho 预测的那样,光边界的不准确会导致近距离伪像,如下图所示,放大时:Tile基于渲染 - 关闭视图。重叠的四边形无法完全限制灯光,而是剪掉边缘,露出瓷砖网格。

The sphere will be projected as an ellipse unless it's at the cameras center as brainjam says.

The article that Xavier Ho links to describes the generalization of sphere projection (That is, quadratic projection). It is a very good read and I recommend it too. However, if you are only interested in sphere projection and more precisely the quadrilateral that bounds the projection then The Mechanics of Robust Stencil Shadows, page 6: Scissor Optimization details how to do it.

A Note on Xavier Ho's Approximation

I would like to add that the approximation that Xavier Ho suggests is, as he notes too, very approximative. I actually used it for a tile-based forward renderer to approximate light bounds in screen space. The following image shows how it neatly enables good performance with 400 omni (spherically bound) lights in a scene: Tile-based Rendering - Far View. However, just like Xavier Ho predicted the inaccuracy of the light bounds causes artifacts up close as seen here when zoomed in: Tile-based Rendering - Close view. The overlapping quadrilaterals fail to bound the lights completely and instead clip the edges revealing the tile grid.

凡间太子 2024-09-06 17:40:56

一般来说,球体在透视中被视为椭圆:

替代文字
(来源:jrank.org

上图位于 这篇文章

这篇文章描述了如何获得球体投影的边界梯形。在计算机出现之前,艺术家和制图员必须手动解决这个问题。

In general, a sphere is seen as an ellipse in perspective:

alt text
(source: jrank.org)

The above image is at the bottom of this article.

Section 6 of this article describes how the bounding trapezoid of the sphere's projection is obtained. Before computers, artists and draftsmen has to figure this out by hand.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文