如何计算入射角?
我正在为一个大型业余项目开发光线追踪器,目标是生成逼真的渲染,而无需担心 CPU 时间。 基本上是预渲染,所以我追求的是准确性而不是速度。
我在理解光照方面的一些更高级的数学时遇到了一些困难。 基本上,我的观点是有道理的。 假设没有距离衰减,我应该能够使用我找到的多边形上的点,并将该点的法线与光线的入射角进行比较,以确定我的照明值。 因此,给定平面上的一个点、该平面的法线和点光源,我将如何计算出该角度?
我问的原因是我似乎找不到任何关于寻找入射角的参考。 我可以找到很多参考资料,详细说明获得它后该怎么做,但没有任何内容告诉我如何首先获得它。 我想这很简单,但我就是无法逻辑清楚。
谢谢
I'm working on a raytracer for a large side project, with the goal being to produce realistic renders without worrying about CPU time. Basically pre-rendering, so I'm going for accuracy over speed.
I'm having some trouble wrapping my head around some of the more advanced math going on in the lighting aspects of things. Basically, I have a point for my light. Assuming no distance falloff, I should be able to use the point on the polygon I've found, and compare the normal at that point to the angle of incidence on the light to figure out my illumination value. So given a point on a plane, the normal for that plane, and the point light, how would I go about figuring out that angle?
The reason I ask is that I can't seem to find any reference on finding the angle of incidence. I can find lots of references detailing what to do once you've got it, but nothing telling me how to get it in the first place. I imagine it's something simple, but I just can't logic it out.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
表面法线向量与入射光向量的点积如果你已经标准化了你的向量,会给你入射角的余弦。
The dot product of the surface normal vector and the incident light vector will give you the cosine of the angle of incidence, if you've normalised your vectors.
在我看来,您正在尝试计算漫射照明。 假设您有 Surface Point http://www.yourequations。 com/eq.latex?%5Cinline%20%5Coverrightarrow%7Bp_o%7D 曲面上的点,浅位置 http://www.yourequations.com/eq.latex?%5Cinline%20%5Coverrightarrow%7Bp_L%7D,以及 法向量 http://www.yourequations.com/eq.latex?% 5Cinline%20%5Coverrightarrow%7Bn%7D 法向量。 您可以这样计算漫反射照明:
漫反射照明 http://www.yourequations.com/eq.latex?%5Coverrightarrow%7BL%7D%3D%5Coverrightarrow%7Bp_L%7D -%5Coverrightarrow%7Bp_o%7D%5C%5C%0AI_d%3Dk%2a%5Cfrac%7B%5Coverrightarrow%7BL%7D%5Ccdot%5Coverrightarrow%7Bn%7D%7D%7B%5C%7C%5Coverrightarrow%7BL%7D% 5C%7C%2a%5C%7C%5Coverrightarrow%7Bn%7D%5C%7C%7D
从技术上讲,您不需要计算实际的入射角,因为您只需要 点积方便地为您提供。
It sounds to me like you are trying to calculate diffuse illumination. Assuming you have Surface Point http://www.yourequations.com/eq.latex?%5Cinline%20%5Coverrightarrow%7Bp_o%7D the point on the surface, Light Position http://www.yourequations.com/eq.latex?%5Cinline%20%5Coverrightarrow%7Bp_L%7D, and the Normal Vector http://www.yourequations.com/eq.latex?%5Cinline%20%5Coverrightarrow%7Bn%7D normal vector. You can calculate diffuse illumination like this:
Diffuse Illumination http://www.yourequations.com/eq.latex?%5Coverrightarrow%7BL%7D%3D%5Coverrightarrow%7Bp_L%7D-%5Coverrightarrow%7Bp_o%7D%5C%5C%0AI_d%3Dk%2a%5Cfrac%7B%5Coverrightarrow%7BL%7D%5Ccdot%5Coverrightarrow%7Bn%7D%7D%7B%5C%7C%5Coverrightarrow%7BL%7D%5C%7C%2a%5C%7C%5Coverrightarrow%7Bn%7D%5C%7C%7D
You technically don't need to calculate the actual angle of incident because you only need the cosine of that which the dot product conveniently gives you.
注意:从我现在所在的位置来看,我无法为您上传图片。 不过,我会尽力用语言向您说明。
您可以这样想象这个过程:
定义 替代文本 http://www. yourequations.com/eq.latex?%5Chat%7Bn%7D 作为归一化法线(从平面多边形出来的垂直向量,具有单位长度,使数学更容易)。
定义替代文本http://www.yourequations.com/eq.latex?p_0作为你的眼球点。
定义替代文本http://www.yourequations.com/eq.latex?p_1作为“眼球射线”在多边形上的撞击点。
定义 替代文本 http://www.yourequations.com/eq.latex? %5Chat%7Bv%7D 作为从 替代文本 http:// 指向的标准化向量www.yourequations.com/eq.latex?p_1 返回替代文本 http:// /www.yourequations.com/eq.latex?p_0。 您可以这样写:
替代文本 http://www.yourequations.com/eq.latex?%5Chat%7Bv% 7D%20=%20%5Cfrac%7B%5Coverrightarrow%7B(p_0%20-%20p_1)%7D%7D%7B||p_0%20-%20p_1||%7D
因此,您创建了一个指向 alt 文本 http://www.yourequations.com/eq.latex?p_1< 的向量/a> 到 替代文本 http://www.yourequations.com/eq.latex?p_0< /a> 然后将该向量除以它自己的长度,得到一个长度为 1 的向量,该向量指向 替代文本 http://www.yourequations.com/eq.latex?p_1 到 alt text http://www.yourequations.com/eq.latex?p_0
我们费尽心思的原因是我们真的很喜欢这个角度替代文本 http://www.yourequations.com/eq.latex?%5Ctheta 这是法线 替代文本 http://www.yourequations.com/eq.latex?%5Chat%7Bn %7D 和向量 替代文本 http://www. yourequations.com/eq.latex?%5Chat%7Bv%7D 您刚刚创建的。 theta 的另一个词是入射角。
计算该入射角的一个简单方法是使用点积。 使用上面定义的术语,您可以获取每个单位长度向量的 x、y 和 z 分量,将它们相乘并将总和相加以获得点积。
替代文本 http://www.yourequations.com/eq.latex ?%5Chat%7Bn%7D%20%5Ccdot%20%5Chat%7Bv%7D%20=%20%5Ccos%7B%5Ctheta%7D%20=%20n_x%20%20v_x%20+%20n_y%20%20v_y %20+%20n_z%20%20v_z
计算替代文本 http:// www.yourequations.com/eq.latex?%5Ctheta,因此,您只需在点积上使用反余弦:
替代文本 http://www.yourequations.com/ eq.latex?%5Ctheta%20=%20%5Carccos%28%5Chat%7Bn%7D%20%5Ccdot%20%5Chat%7Bv%7D%29
编辑:修改以上内容以添加 yourequations.com 格式。
NOTE: From where I'm sitting right now, I can't upload a picture for you. I'll try to lay it out for you in words, though.
Here's how you can imagine this process:
Define alt text http://www.yourequations.com/eq.latex?%5Chat%7Bn%7D as your normalized normal (the vertical vector that comes out of your planar polygon and is of unit length, making the math easier).
Define alt text http://www.yourequations.com/eq.latex?p_0 as your eyeball point.
Define alt text http://www.yourequations.com/eq.latex?p_1 as the impact point of your "eyeball ray" on the polygon.
Define alt text http://www.yourequations.com/eq.latex?%5Chat%7Bv%7D as the normalized vector pointing from alt text http://www.yourequations.com/eq.latex?p_1 back to alt text http://www.yourequations.com/eq.latex?p_0. You can write this like so:
alt text http://www.yourequations.com/eq.latex?%5Chat%7Bv%7D%20=%20%5Cfrac%7B%5Coverrightarrow%7B(p_0%20-%20p_1)%7D%7D%7B||p_0%20-%20p_1||%7D
So, you have created a vector that points from alt text http://www.yourequations.com/eq.latex?p_1 to alt text http://www.yourequations.com/eq.latex?p_0 and then divided that vector by its own length, giving you a vector of length 1 that points from alt text http://www.yourequations.com/eq.latex?p_1 to alt text http://www.yourequations.com/eq.latex?p_0
The reason that we went to all this trouble is that we would really like the angle alt text http://www.yourequations.com/eq.latex?%5Ctheta which is the angle between the normal alt text http://www.yourequations.com/eq.latex?%5Chat%7Bn%7D and that vector alt text http://www.yourequations.com/eq.latex?%5Chat%7Bv%7D that you just created. Another word for theta is the angle of incidence.
An easy way to calculate this angle of incidence is to use the dot product. Using the terms defined above, you take the x, y and z components of each of those unit length vectors, multiply them together and add the sums to get the dot product.
alt text http://www.yourequations.com/eq.latex?%5Chat%7Bn%7D%20%5Ccdot%20%5Chat%7Bv%7D%20=%20%5Ccos%7B%5Ctheta%7D%20=%20n_x%20%20v_x%20+%20n_y%20%20v_y%20+%20n_z%20%20v_z
To calculate alt text http://www.yourequations.com/eq.latex?%5Ctheta, therefore, you simple use the inverse cosine on the dot product:
alt text http://www.yourequations.com/eq.latex?%5Ctheta%20=%20%5Carccos%28%5Chat%7Bn%7D%20%5Ccdot%20%5Chat%7Bv%7D%29
Edit: modified the above to add yourequations.com formatting.