Archived

This topic is now archived and is closed to further replies.

Ray Tracer Woes [part 2] (images included)

This topic is 5583 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

After spending ~40 hours trying to add refraction to my ray tracer, with only a little progress, I'm feeling pretty dumb. I'm completely out of ideas, and I've looked at a ton of tutorials but I just can't get it to work. Here's what mine looks like: Here's what it's supposed to look like: (index of refraction for the sphere = 1.999, for the air=1.0) If anyone here's willing to take a hack at it, the source (MSVC++6 with GLUT) is here: mp1.zip [122 KB] The refraction code is in RayEngine.cpp. I kept things fairly clean/simple (I think :/ ). Thanks -Ben [edit: screwed up the image links (probably fatigue related )] [edit: screwed up the file link too] [edited by - atreyu on February 9, 2003 3:13:12 AM] [edited by - atreyu on February 9, 2003 3:16:32 AM]

Share on other sites
How did you get the second image?

********

A Problem Worthy of Attack
Proves It''s Worth by Fighting Back

Share on other sites
Walkingcarcass : it''s obviously from another raytracer

Share on other sites
Had a look at some of your code, and this is not strictly related to the problem, but you sure are going to get a lot of memory leaks, I think. You seem to be allocating memory everywhere, yet there is only two places where you delete it (you delete two arrays). You also need to set the pointer to zero after you delete it, too.

Share on other sites
Perhaps I was a bit zealous with your memory problem. You don''t free the Sphere''s you make in the main file, that''s all.

Share on other sites
walkingcarcass: It''s just another tracer.

MDI: I know, I know. :/ I usually take care of memory deallocation first thing. It''s been a long couple of days. Other than the scene initialization I think there are no other leaks. Thanks for taking a look though.

-Ben

Share on other sites
I finally got it. To anyone that made an attempt, I appreciate it. This was by far the most complex bug I've ever run into and I don't think anyone could have seen it just by looking at the code. The fix looks nearly the same, and I still have no idea how it managed to interfere with my normals without causing artifacts on the screen (other than the refraction ones )

In case anyone's interested, I found a really strange artifact that was happening to my normals during recursion (for some reason dot(N,I) was always > 0), and I couldn't locate the source of it at all. I went to a really early backup of my code and found the artifacts weren't there, so I tried my original refraction code there and it worked. Then I went piece by piece, replacing my old backup's code with the new code till the bug finally reappeared (It didn't appear till the very last function was copied over either, arggggg). It's in the Sphere::ComputeIntersection() code:

(the bug is the commented out part)

  int Sphere::ComputeIntersection(float *t, Ray *ray){	    float a = 0, b = 0, c = 0;    float d = 0, t1 = 0, t2 = 0;    a = 1.0f;    b = 2 * ((ray->P * ray->D) - (ray->D * Center));    c = (ray->P * ray->P) - (ray->P * Center)         * 2 + (Center * Center) - (Radius * Radius);	    d = (b * b) - (4 * c);    if(d <= 0) return 0;		    d = (float)sqrt(d);    t1 = 0.5f * (-b + d);	//(2 * a);    t2 = 0.5f * (-b - d);	//(2 * a);/*    //This code has been left in memory of the +30 //hours of pain it caused me   if(t1 > 0)   {       if(t1 < t2) *t = t1;   }   if(t2 > 0)   {       if(t2 < t1) *t = t2;   }   if(*t > 0) return 1;   return 0;*/    //////////yaaaaaay//////////////////    if((t1 <= 0) && (t2 <= 0)) return 0;    if(t1 <= 0) t1 = t2;    if(t2 <= 0) t2 = t1;    if(t1 < t2)    {        *t = t1;    }    else    {        *t = t2;    }    return 1;    /////////////////////////////////}

I never thought I'd say this, but I definitely didn't enjoy coding today. :/

--Ben

[edit: mixed up the code tag with the source one again]

[edited by - atreyu on February 10, 2003 3:58:51 AM]

Share on other sites
I forgot to mention getting hit by a cop car while riding my bike back (food run) didn''t help things much either.

This has been a really strange day.

--Ben

Share on other sites
[OT]
alan parsons had a progressive rock ''project'' in the seventies and eighties. There was a joke in one of those Austin Powers films about a scientist called Alan Parsons who would help the character Doctor Evil to do something devious. Evil said he was going to call it the Alan Parsons Project. And that''s how it re-entered popular (albeit irrelevant) culture.
[/OT]

Share on other sites
petewood: Thanks for the tidbit. I knew it had something to do with music from my friend who named our final project, but that gives a bit more depth to the name. (Of course the name doesn't fit our project at all, hehe)

Here's a shot I did around 5 am in case anyone is interested in how things look with more than 2 boring spheres on the screen

--Ben

[edit: holy crap, I can not seem to do links right anymore]

[edited by - atreyu on February 10, 2003 3:52:51 PM]

• 12
• 9
• 13
• 41
• 15