光线追踪阴影问题

发布于 2024-08-14 18:03:57 字数 904 浏览 8 评论 0原文

我的光线追踪器中的阴影光线出现问题。

请看下面两张

3D sMax 图片:

alt text http://neo.cycovery.com/ Shadow_problem.gif

我的光线追踪器:

替代文本 http://neo.cycovery.com/shadow_problem2。 jpg

场景被非常明亮的光线照亮,从后面照射过来。它是如此明亮,以至于阴影中没有渐变,只有白色或黑色(由于曝光过度)。

两个图像都是使用 3DStudioMax 渲染的,并且都使用完全相同的几何图形,只是在一种情况下,法线是在三角形上插值的。

现在考虑表面上的红点。对于未平滑的版本,它位于黑暗区域。这意味着从这个三角形看不到光源,因为它背对着三角形。 然而,在平滑版本中,它位于照亮区域,因为插值法线表明,光在该点是可见的(尽管三角形的实际几何形状背向光源)。

我现在的问题是当光线追踪阴影出现时。如果将阴影光线从红点射入场景中,以测试光源是否可见(以确定阴影),则阴影光线将返回一个交集,与是否对法线进行插值(因为相交仅取决于几何形状)。因此,像素将变暗。

3dsamx 正确处理这种情况 - 渲染图像是在打开光线追踪阴影的情况下生成的。然而,当我打开光线追踪阴影时,我自己的光线追踪器恰好遇到了这个问题(在我的光线追踪器中,在两种情况下该点都是暗的,因为光线追踪阴影确定了位于阴影中的点),并且我不知道如何解决它。

我希望有人知道这个问题以及如何处理它..

谢谢!

I've got a problem with shadowrays in my raytracer.

Please have a look at the following two pictures

3D sMax:

alt text http://neo.cycovery.com/shadow_problem.gif

My Raytracer:

alt text http://neo.cycovery.com/shadow_problem2.jpg

The scene is lit by a very bright light, shining from the back. It's so bright that there is no gradient in the shading, just either white or dark (due to the overexposure).

both images were rendered using 3DStudioMax and both use the exact same geometry, just in one case the normals are interpolated across the triangles.

Now consider the red dot on the surface. In the case of the unsmoothed version, it lies in a dark area. this means that the light source is not visible from this triangle, since it's facing away from it.
In the smoothed version however, it lies in the lit area, because the interpolated normal would suggest, that the light would be visible at that point (although the actual geometry of the triangle is facing away from the lightsource).

My problem now is when raytraced shadows come in. if a shadowray is shot into the scene, from the red dot, to test whether the light-source is visible or not (to determine shadowing), the shadowray will return an intersection, independent of whether normals are interpolated or not (because intersections only depend on the geometry). Therefore the pixel would be shaded dark.

3dsamx is handling the case correctly - the rendered image was generated with Raytraced shadows turned on. However, my own Raytracer runs exactly into this problem when i turn on raytraced shadows (in my raytracer, the point is dark in both cases, because raytraced shadows determine the point lying in the shadow), and i don't know how to solve it.

I hope someone knows this problem and how to deal with it..

thanks!

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

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

发布评论

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

评论(6

烟花易冷人易散 2024-08-21 18:03:57

“正确”的解决方案是对三角形进行细分,或者求解三角形所属表面的方程。我只看到了镶嵌。曲面细分为您提供可控的精度等等...
否则,您应该在该点测试法线(我相信“3DStudio”会这样做),并且在法线不面向光线的情况下,只需将该点设置为不亮即可。它与“自阴影”无关。这个问题只能通过曲面细分轻松解决。祝你好运!

The 'correct' solutions are either to tesselate triangles, or to solve the equation of the surface the triangle belongs to. I have seen only the tessellation. Tessellation gives you the controllable precision and so on...
Otherwise, you should test normal in the point (what I believe '3DStudio' does) and in the case the normal is not facing the light, just set the point as not lit. It has nothing to do with 'self-shading'. Easily this problem can be solved only with tessellation. Good luck!

挽容 2024-08-21 18:03:57

我不确定我是否正确理解了你的问题。
很难知道您通过哪种方法获得了哪个版本/结果以及什么结果
认为正确。

当您需要威胁阴影射线与其上的三角形相交时,不是这种情况吗?
红点;-)属于特例。
你不需要像任何其他三角形那样进行几何交集,
但仅在插值法线和阴影光线之间进行方向检查。

或者从更一般的意义上来说,当以下情况时,您会说阴影光线停止在三角形(任何三角形)处:
a) 它们相交并且
b) 交点处三角形插值法线的方向与阴影射线相反。

I'm not sure if I understood your problem correctly.
It's kind of hard to get which version/result is obtained by which method and what result you
consider correct.

Isn't it the case when you need to threat intersection of shadowray with the triangle on which
The Red Point ;-) lies as special case.
You don't do geometry intersection, as with any other triangle,
but only direction check between interpolated normal and shadowray.

Or in more general sense, you say that shadowray stops at a triangle, any triangle, when:
a) they intersect and
b) interpolated normal of a triangle at intersection point has direction opposite to shadowray.

心头的小情儿 2024-08-21 18:03:57

如何做到这一点:
如果该点处的插值法线面向光线,则该表面可能面向光线。如果背对着你,你就处于阴影之中。

在第一种情况下,引起阴影的两个因素是其他物体,如果你是凹面物体,那就是你自己。在另一个对象中这很容易。

现在就您自己而言,当您将光线投射到光源时,如果您确实是“内凸点”,那么您在进入时会击中自己两次,然后离开物体,从而处于阴影中。

如果你击中自己一次,那么你一定位于光线照射的边缘,但正如我们所知,此时我们面对光线(通过平滑的法线),这意味着我们没有被阴影。

How you can do it:
If the interpolated normal at the point is facing towards the light then the surface is potentially facing the light. If facing away you are in shadow.

In the first case, the two things that would cause a shadow are other objects, and yourself if you are concave object. In the other object that is easy.

Now in the case of yourself, when you cast your ray at the light source, if you are truly 'convex inside point' you will hit yourself twice as you enter then leave the object, thus in shadow.

If you hit yourself a single time, then you must be on the edge of where the light is striking, but as we know at that point we are facing the light (via the smoothed normals) it means we are not shadowed.

清泪尽 2024-08-21 18:03:57

垫子,我相信你的问题可能是你的阴影光线击中了它起源的同一个三角形,因为它非常接近切向(请注意,它发生在光影过渡的边界上)。有两种方法可以解决这个问题:一种方法是使用“偏差”来测试距射线原点的距离,但我认为更好的解决方案是存储对带有射线的原始三角形的引用。如果您对这个三角形进行测试,请忽略它。

如果您碰巧使用像 BVH 这样的空间索引,那么您可以在进行任何相交测试之前尝试跳出包含三角形的“盒子”,但这不像前面提到的方法那么简单,必须更加小心。

Mat, I believe your problem could be that your shadow ray hits the same triangle that it originates from because it is so close to being tangential (note that it happens right on the border of the light-shadow transition). There are two ways of solving this problem: One approach is to use a "bias" that tests the distance from the ray origin, but I think a better solution is to store a reference to the originating triangle with the ray. If you do a test against this triangle, simply ignore it.

If you happen to be using a spatial index like a BVH, then you could try stepping out of the "box" containing the triangle before doing any intersection tests, but this is less simple than before-mentioned approach and must be approached with more care.

稚然 2024-08-21 18:03:57

发射阴影光线时,交叉点向光源方向移动少量是正常的。

即shadowRay.dir = ShadowRay.dir * 0.0001

这可以避免阴影光线与主光线/反射光线/折射光线一样与同一图元相交。

也许你的问题是因为你没有这样做?

It's normal to shift an intersection by a small amount in the direction of the light source when firing shadow rays.

I.e. shadowRay.dir = shadowRay.dir * 0.0001

This avoids the shadow ray intersecting the same primitive as the primary / reflective / refractive ray did.

Perhaps your problem is because you did not do this?

晒暮凉 2024-08-21 18:03:57

我遇到了同样的问题,在我的例子中,如果光线方向和法线的点刺为正,则有一个 if 语句,就可以解决问题。

伪代码是:

bool shadow_hit(light, shader_ctx){
   ....
   if(dot(light.dir, shader_ctx.normal) > 0) return false
   ...
   return true;
}

I had the same issue and in my case an if statement where if the dot prod of the light direction and the normal is positive, did the trick.

the pseudocode is:

bool shadow_hit(light, shader_ctx){
   ....
   if(dot(light.dir, shader_ctx.normal) > 0) return false
   ...
   return true;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文