光线追踪照明
我正在尝试为简单的球体光线追踪应用程序实现镜面反射和漫射照明,但我的矢量遇到问题。
我试图使用以下内容来更新灯光,但生成的图像看起来完全相同,所以我知道我做错了什么。我认为我以某种方式弄乱了向量。 Hit 是已被击中的球体,mindis 是到该球体点的距离。 Pir、pig、pib 是颜色的 rgb。
P3D intersection = ray.position.add(ray.direction).scale(mindis);
P3D l = intersection.sub(light).normalize();
P3D n = hit.center.sub(intersection).normalize();
double dot = l.dot(n);
P3D f = l.add(n).scale(-2.0 * dot);
double dot2 = f.dot(ray.direction);
pir += dot2 * 20;
pig += dot2 * 20;
pib += dot2 * 20;
I am trying to implement specular and diffuse lighting for a simple sphere ray tracing application, but I am having problems with my vectors.
I am trying to use the following to update the light, but the generated image looks exactly the same, so I know I am doing something wrong. I assume I am messing up the vectors in some way. Hit is the sphere that has been hit and mindis is the distance to this spheres point. Pir, pig, pib are the rgb for the color.
P3D intersection = ray.position.add(ray.direction).scale(mindis);
P3D l = intersection.sub(light).normalize();
P3D n = hit.center.sub(intersection).normalize();
double dot = l.dot(n);
P3D f = l.add(n).scale(-2.0 * dot);
double dot2 = f.dot(ray.direction);
pir += dot2 * 20;
pig += dot2 * 20;
pib += dot2 * 20;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许第一行应该是:
此外,
f 似乎是光从球体反射的方向。这通常是光线的相反方向,所以你可能想要
Perhaps the first line should be:
Also
f appears to be the direction that the light bounces off the sphere. This would typically be the opposite direction of the ray, so you probably want