开发者

Something with raytracing that has gone wrong

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 of开发者_如何学JAVAf. 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.


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜