光线追踪出了问题
我正在尝试用 C#(从 python 移植)进行简单的光线追踪分配。 我已经设法使示例代码显示正确的图片,但是当我尝试将其适应我的作业时,出现了问题。
如果我知道出了什么问题,我会发布一些我认为可能有帮助的代码,但我不知道从哪里开始。
基本上我的作业输出如下:
http://i56.tinypic.com/2vcdobq.png
打开镜面高亮,并且
http://i53.tinypic.com/2e1r38o.png
将其关闭。 它应该看起来像:
http://i56.tinypic.com/2m7sxlh.png
我的Phong 照明公式如下所示:
Colour I = diffuse_colour;
Vector L = light.vector;
Vector N = normal; //FIXME!
Colour Is = diffuse_colour * light.intensity;
Colour Ia = new Colour(1,1,1) * light.ambient;
Colour Kd = specular_colour;
Colour Ka = Kd;
double Ks = sharpness ?? 0.4;
Vector H = Vector.unit(view + L);
//Phong Illumination
//I = KaIa + KdIs max(0,L.N) + KsIs (H.N)^n
I = Ka * Ia
+ Kd * Is * Math.Max(0, L.dot(N))
+ Ks * Is * Math.Pow(H.dot(N),200); //FIXME?
我从工作示例代码中复制了它,所以我知道它有效。
任何想法都会很棒,因为我被难住了。
I'm trying to do a simple ray tracing assignment, in c# (ported from python).
I've managed to make the sample code show the correct picture, but when I try and adapt it to my assignment something goes wrong.
If I knew what was going wrong I would post some code that I thought might help, but I have no idea where to start.
Basically my assignment outputs something like this:
http://i56.tinypic.com/2vcdobq.png
With specular highlighting on, and
http://i53.tinypic.com/2e1r38o.png
With it off.
It's suppose to look something like:
http://i56.tinypic.com/2m7sxlh.png
My Phong lighting formula looks like:
Colour I = diffuse_colour;
Vector L = light.vector;
Vector N = normal; //FIXME!
Colour Is = diffuse_colour * light.intensity;
Colour Ia = new Colour(1,1,1) * light.ambient;
Colour Kd = specular_colour;
Colour Ka = Kd;
double Ks = sharpness ?? 0.4;
Vector H = Vector.unit(view + L);
//Phong Illumination
//I = KaIa + KdIs max(0,L.N) + KsIs (H.N)^n
I = Ka * Ia
+ Kd * Is * Math.Max(0, L.dot(N))
+ Ks * Is * Math.Pow(H.dot(N),200); //FIXME?
And I copied it from the working sample code, so I know it works.
Any thoughts would be great, because I'm stumped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您有同一算法的两种实现。您声称它们会产生不同的结果。查找错误似乎很简单:同时在各自的调试器中逐步运行两种算法。仔细观察两个程序的状态。当它们产生不同的程序状态时,就会出现错误。
You have two implementations of the same algorithm. You claim that they produce different results. Finding the mistake seems straightforward: run both algorithms step by step in their respective debuggers, simultaneously. Watch the state of both programs carefully. The moment they produce different program states, there's your bug.
它并不那么简单,因为一个实现是用 python 实现的,另一个实现是用 c# 实现的。
结果发现有两件事错了。
首先,在我的点类中,我的一个重载运算符是错误的。 (运算符 - 在两点上,我让它返回 Vector (p1.x - p2.x, p1.y - p2.y, p1.x - p2.x) ...最后一对应该是 pz 我犯的另一个错误是当我保存位图图像时,我将 x 和 y 的列和
行混淆了(Col = x,Row = y)
希望这可以帮助遇到随机问题的其他人。像我一样:P
It wasnt quite as simple as that, as one implementation was in python, and the other in c#.
Turns out there were 2 things wrong.
First, In my point class one of my overload operators was wrong. (the operator - on 2 points, i had it returning Vector (p1.x - p2.x, p1.y - p2.y, p1.x - p2.x) ... where that last pair should have been p.z instead.
The other mistake i made was when i was saving the bitmap image, i got the columns and rows mixed up, in terms of x and y. (Col = x, Row = y)
Hope this helps anyone else that runs into random problems like me :P
在编写光线追踪器时,我研究了这篇文章,以便更好地了解 Phong 照明。
所以看看这里,我相信你会有一个想法:
www.gamedev.net/page/resources/ _/technical/graphics-programming-and-theory/phong-illustration-explained-r667
While I was writing my ray tracer, I have studied this article to get a good understanding about Phong Illumination.
So have a look at here, I am sure you will get an idea:
www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/phong-illumination-explained-r667