光线追踪 - 软阴影光线、阴影

2023-09-07 23:47:22 作者:清酒话桑麻

我实现我自己的光线跟踪器作为一个iPad应用程序为学校项目。目前,这是结果:

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

我需要添加的最后一个要求,软阴影,但我找不到一个完整的参考的任何地方。如果我深知,要实现这个功能,我必须从一个交点,以吨光源拍摄许多射线。这必须是一个区域的光。假设我用一个球体,我的问题是:

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:

在这点上的球,我必须用它来计算阴影射线? 如何平均的结果?

推荐答案

您正站在一个点P与局部表面法线N,并且需要找出从球形光源L与中心C挂在地平线以上到达照明,均匀并愉快地在可见的频率辐射能量。为了获得柔和阴影,你将需要发送多个遮挡探测器射线(shadowfeelers)争取在L个不同点,但我们不是只是做多。

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.

图片使得它pretty的明显,直接的光只能到达以P从半球^ h F ,所以你不得不品尝球体的一部分 - 发送shadowfeelers到 - 为了准确地评估L的贡献的照射在P。然而,虽然在球体上产生点是简单,下面只是一个半球即不必对准任何世界坐标轴,数学运算复杂化。但真正的问题是在其他地方 - 如果我们采样的^ h F 均匀,我们会平等对待其面临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.

我们做一个快速的观察,所有这些shadowfeelers实际上是旨在实现共享中心以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.

这意味着,而不是产生于^ h F 点,我们就可以生成它们在盘D上,这不仅是简单的事,但也 - 假设D上均匀的点分布 - 保证shadowfeeler密度^ h F 将在本地的面积成正比的潜在贡献,很好地解决了我们上面的问题。

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.

要概括起来:

在假定的光E由L到达到P.一些总量您可以基于它L和P,L的用P角US $ p $垫,或一些更复杂的之间的距离。 生成一组m个随机,均匀的阴影光线从对向盘D。 如果光线 - [R相交击球前l什么,还有就是沿着这条道路没有能量传输。 否则: 在乘E / M通过正常的向量N为P点积和(标准化)R, 的结果添加到迄今为止传输的光。 Assume some total amount of light E arriving from L to P. You may base it on distance between L and P, angular spread of L over P, or something even more complicated. Generate a set of M random, uniform shadow rays from P towards disc D. If a ray R intersects anything before hitting L, there is no energy transfer along this path. Otherwise: multiply E/M by a dot product of normal vector N at P and (normalized) R, add the result to the light transferred so far.

做:优化(检测,如果L是完全/部分在当地的地平线上,因人而异米,升角US $ p $垫用P,采用分层和/或自适应采样,缓存封堵命中,等等。)

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.)

PS。上述使一吨的假设和简化,并且是不正确的光度,而应做为一个iPad射线示踪

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