光线追踪 - 软阴影 [英] Ray tracing - soft shadow

查看:41
本文介绍了光线追踪 - 软阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将自己的光线追踪器实现为学校项目的 iPad 应用.目前结果如下:

I'm implementing my own ray tracer as an iPad app for a school project. At the moment this is the result:

我需要添加最后一个要求,软阴影,但我在任何地方都找不到完整的参考.如果我理解得很好,要实现此功能,我必须从交点向 mt 光源发射许多光线.这个必须是区域灯.假设我使用一个球体,我的问题是:

I need to add the last requirement, soft shadows, but I can't find a complete reference anywhere. If I understood well, to implement this feature I have to shoot many ray from an intersection point to mt light source. This one must be an area light. Suppose I use a sphere, my questions are:

  • 我必须使用球体上的哪个点来计算阴影射线?
  • 如何平均结果?

推荐答案

你站在局部表面法线为 N 的点 P 处,需要找出中心 C 悬在地平线上方的球面光源 L 到达的光照,在可见频率上均匀而愉快地辐射能量.要获得柔和的阴影,您需要向 L 上的不同点发送多个遮挡检测器光线(shadowfeelers),但让我们做的不仅仅是这些.

You are standing at a point P with local surface normal N, and need to find out the illumination arriving from spherical light source L with center C hanging above the horizon, uniformly and happily radiating energy on visible frequencies. To get soft shadows you will need to send multiple occlusion detector rays (shadowfeelers) towards different points on L, but let's do more than just that.

这张图片很清楚,直射光只能从半球 HF 到达 P,所以它是你必须采样的球体的唯一部分 - 发送 shadowfeelers 到 - 为了准确评估 L 对 P 处照明的贡献.然而,虽然在球体上生成点很简单,但这里我们只有一个不一定与任何世界坐标轴对齐的半球,这使数学复杂化.但真正的问题在别处——如果我们对 HF 进行均匀采样,我们将对它面向 P 的部分和几乎侧向的部分给予同等对待.这是一种浪费,最好将我们的计算集中在向 P 发送更多能量的区域.

The picture makes it pretty clear that direct light can only arrive at P from hemisphere HF, so it is the only part of the sphere you have to sample - send shadowfeelers to - in order to accurately assess L's contribution to illumination at P. However, while generating points on a sphere is simple, here we have just a hemisphere that isn't necessarily aligned with any of the world coordinate axes, complicating the math. But the real problem is elsewhere - if we sampled HF uniformly, we would give equal treatment to its parts that face P head on, and to those that are nearly sideways. This is a waste, and it's better to focus our computation on areas that send more energy towards P.

我们快速观察到,所有这些探影者实际上都瞄准与 L 共享中心的圆盘 D(即 L 的大圆),并且与连接 P 和 C 的线正交.

We make a quick observation that all these shadowfeelers are actually aimed towards disc D that shares the center with L (i.e. is great circle of L) and is orthogonal to a line connecting P and C.

这意味着不是在 HF 上生成点,我们可以在 D 盘上生成它们,这不仅更简单,而且 - 假设 D 上的点分布均匀 - 保证 shadowfeelerHF 上的密度将与该区域的潜在贡献局部成正比,很好地解决了我们上面的问题.

This means that rather than generate points on HF, we can generate them on disc D, which is not only simpler to do, but also - assuming uniform point distribution on D - guarantees that shadowfeeler density on HF will be locally proportional to the area's potential contribution, nicely solving the problem we had above.

另一种看待这个问题的方法是,您需要在以 P 为顶点、以 D 为底的锥体内生成光线.

Another way of looking at this is that you need to generate rays within a cone that has P as an apex and D as a base.

总结一下:

  1. 假设从 L 到达 P 的总光量 E.您可以根据 L 和 P 之间的距离、L 在 P 上的角度扩展或更复杂的东西来确定.
  2. 从 P 向圆盘 D 生成一组 M 条随机、均匀的阴影光线.
  3. 如果射线 R 在到达 L 之前与任何物体相交,则沿着这条路径没有能量转移.
  4. 否则:
    • 将 E/M 乘以 P 处的法向量 N 和(归一化的)R 的点积,
    • 将结果添加到目前传输的光中.

TO DO: 优化(检测 L 是否完全/部分在局部范围内,根据 L 在 P 上的角度扩展改变 M,使用分层和/或自适应采样,缓存遮挡器命中等)

TO DO: optimizations (detect if L is fully/partially under local horizon, vary M with angular spread of L over P, use stratification and/or adaptive sampling, cache occluder hits, etc.)

附注.以上做了大量的假设和简化,在光度学上并不正确,但对于 iPad 光线追踪器来说应该是正确的.

PS. The above makes a ton of assumptions and simplifications, and is not correct photometrically, but should do for an iPad ray tracer.

这篇关于光线追踪 - 软阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆