Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

like image 284
Meeces2911 Avatar asked Apr 07 '26 02:04

Meeces2911


1 Answers

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.

like image 98
Eric Lippert Avatar answered Apr 08 '26 16:04

Eric Lippert