通过透明表面计算阴影

发布于 2024-10-09 19:53:44 字数 323 浏览 2 评论 0原文

在光线追踪中,我想计算光线照射点的阴影。我向所有光源“画”线,并检查它们是否被物体阻挡。如果它们没有被阻挡,那么我根据它们的强度以及“命中光线”和表面法线之间的程度来计算照明的强度。

但是如果光线被部分透明的表面阻挡怎么办?那么光线应该照亮这个点,但是它的强度和颜色受到它所经过的表面颜色的影响,为了计算我需要对光线经过的点进行光线追踪(实际上对于 2 个点,一个是入口,一个是出口),这将是非常昂贵的,并且可能几乎永远不会结束(我猜想,在光源和表面的正确定位中,您可以将示踪剂放入几乎无限的每次点击都循环)。

有没有一种快速且好的方法来近似颜色,或者我应该将表面的颜色作为浅色,将其透明度作为强度?

In ray tracing, I want to calculate the shading for a point where my ray hit. I "draw" lines to all light sources and check if they are blocked by objects or not. If they are not blocked then I calculate the intensity of the lighting according to their intensity and the degree between the "hit ray" and the surface normal.

But what if the light is blocked by a partially transparent surface? Then the light should come to light the point, but its intensity and color are affected by the color of the surface it passes through, and in order to calculate that I need to do ray tracing for the point of passing of the light ray (actually for the 2 points, one of entry and one of exit), and this will be very costly, as well as potentially almost never ending (I guess that in the right positioning of light sources and surfaces you could put the tracer into an almost infinite loop for every hit).

Is there a fast and good way to approximate the color, or should I just take the color of the surface as the light color and its transparency as the intensity?

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

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

发布评论

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

评论(2

追我者格杀勿论 2024-10-16 19:53:44

您不需要从入口点和出口点开始进行光线追踪。想想什么样的光照射到这些点上。以与击中目标对象不同的角度击中半透明表面的光线不会影响击中目标对象的光线的颜色。

+     *     +
 +    *    +
  +   *   +
   +  *  +
 ----------
|    +*+   |
|   + * +  |
|  +  *  + |
 ----------
 +    *    +
      *
      *
   -------

当然,这是假设材料中不存在折射。

现在,如果您想将光线追踪器扩展到更高级的功能(例如路径追踪),那么您需要考虑从半透明物体反射并撞击最终物体的光线,但对于光线追踪器,您不需要这样做担心它。

对于半透明物体,我将光强度的下降建模为距离的线性函数(大多数现实世界的物体都严格遵循这一假设)。如果您将光建模为具有 RGB 分量(物理上不现实......),那么您将按照对象内该分量值的比例减少每个分量。

如果您想真正了解光线在物体中的作用,那么您需要转向次表面散射(玻璃杯中的牛奶看起来不像白色固体的原因以及人类很难在 CGI 中建模的原因)。

编辑:你提到的光无限地来回弹跳并使用许多计算的现象就是真实光的行为。现在的高级渲染器不可能集成所有这些光分量,因此而是随机采样光分布。采集的样本越多,图像就越接近真实感,光积分也越接近其真实值。这称为蒙特卡罗渲染。路径追踪、双向路径追踪和大都市光传输都是试图完全模拟光传输的蒙特卡罗算法。如果有足够的时间,每种算法都会收敛到相同的最终图像,但是有些算法比其他算法更有效。 (参见维基百科上的路径追踪。文章底部有一张比我的图片更好的图片尝试画画)。

You don't need to do ray tracing starting at the entrance and exit points. Think about what kind of light is hitting these points. A ray of light that hits the translucent surface at an angle other than the one that hits your target object will not affect the color of the light that does hit your target object.

+     *     +
 +    *    +
  +   *   +
   +  *  +
 ----------
|    +*+   |
|   + * +  |
|  +  *  + |
 ----------
 +    *    +
      *
      *
   -------

This assumes, of course, that there is no refraction in the material.

Now if you wanted to extend your ray tracer to something a little more advanced like path tracing, then you would need to consider the light that bounces off of the translucent object and hits your final object, but for a ray tracer you do not need do worry about it.

For the translucent object, I would model the decrease in light intensity as a linear function of distance (most real world objects adhere closely to this assumption). If you are modeling light as having RGB components (not physically realistic...) then you would decrease each component in proportion to that component's value within the object.

If you want to get really advanced with what the light does while in the object, then you will need to turn to subsurface scattering (the reason milk in a glass does not look like a white solid and why humans are so hard to model in CGI).

EDIT: The phenomenon you mention of light bouncing back and forth infinitely and using many calculations is what real light behaves like. Advanced renderers nowadays can't possible integrate all of these light components and so instead randomly samples light distributions. The more samples taken, the closer the image converges to looking realistic, and the closer the light integration becomes to its true value. This is called monte carlo rendering. Path tracing, bidirectional path tracing, and metropolis light transport are all monte carlo algorithms that attempt to simulate light transport fully. Each algorithm, given enough time, will converge to the same final image, however, some are more efficient that others. (See path tracing on Wikipedia. At the bottom of the article is an image better than the one I attempted to draw).

浅黛梨妆こ 2024-10-16 19:53:44

如果您希望表面既可以进行常规着色又可以进行透明处理,最简单的方法就是忽略阴影光线的常规着色:出于照明目的,仅使用透明表面的过滤属性。这避免了您描述的潜在的无限照明计算。

请注意,有一种近似无限光线树的好方法,它的名字很有趣,“俄罗斯轮盘赌”:当树的任何分支变得太不重要时,随机选择是否修剪它。分支以概率 P 被修剪,并且对结果的贡献为零(它们是“死的”并且不需要计算)。幸存的分支(“获胜者”)的贡献乘以 1/(1-P),因此得出的近似值平均而言是正确的。

俄罗斯轮盘赌是一种蒙特卡罗技术;您可能需要研究蒙特卡罗光线追踪和其他全局照明方法。

If you want surfaces which can do both regular shading and transparency, the simplest thing is to ignore the regular shading for shadow rays: for illumination purposes, use only the filtering attributes of transparent surfaces. This avoids the potentially infinite lighting computation you described.

Note that there is a good way of approximating infinite ray trees, which goes by the colorful name,"Russian roulette": when any branch of the tree gets too unimportant, make a random choice as to whether to prune it. Branches are pruned with probability P and contribute zero to the result (they are "dead" and do not need to be computed). Surviving branches ("winners") get their contribution multiplied by 1/(1-P), so that the resulting approximation is correct on average.

Russian roulette is a Monte Carlo technique; you may want to look into Monte Carlo ray tracing and other global illumination methods.

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