Almost there

Published February 15, 2006
Advertisement
Put in a good day today on my raytracer, and here are the results:

Rather than bore you with all the images I made throughout making this thing, here are a couple of the better ones:



This one I made to put everything together and make sure it would work with a complex scene. Good thing too, I found an interesting bug when rendering that blue cube (the one on the left). See, when at it's current angle everything worked fine, but if I oriented it so that it was facing directly towards the camera (but still below) it would sit there rendering for a while and then seg fault... I narrowed it down to the transparency being the problem, the only thing I could really think of is that for some reason a ray was getting inside there and just bouncing around forever (which it really shouldn't for transparency since it SHOULD go straight through, and reflection only goes a limited number of bounces).

Now, that box is constructed from six squares (each with two triangles, but that's not important), each square has it's normal facing outwards from the center of the box. Now, I figured what was happening is that if a refracted ray hits the back of a triangle, it is refracted backwards, so once inside the box, always inside the box. What I don't understand is that if this is the case, why does it only happen when the box is oriented a certain way? I suppose now that I think about it that one or more sides could actually have their normals facing inwards, and at an angle the rays would eventually hit all 6 sides, but not when straight on... I'll have to look into that.

BUT, that would of course just make the problem worse anyway, so here's what I did: Whenever a refracted ray hits an object whose normal is facing the wrong way... it just reverses the normal! Problem solved. Hack? I really don't know, as I don't see any other way around this problem, even if I limited the number times a ray could be refracted it would still never get through the box. But as you can see, what I'm doing seems to look fine.


Next:

Pay no attention to the stems...

Now last time I was talking about how much of a pain it is to put in triangles by hand, so clearly from this picture you can see I must have done something about that! No, nothing as cool as milkshape models (yet), instead, since I can define a bunch of triangles in a file, why not make a file with a bunch of triangles defined, and then just use it a bunch of times! Ok, nothing really amazing, and in fact the file loader that loads the objects is identicle to the regular loader, it just doesn't check for camera and light information. This of course means that the objects can define spheres and triangle positions, and of course, other objects! So those flowers are a file with a sphere, a stem, and 8 petal objects. The petals and stems are just triangles. In fact, the blue box is made up of 6 bluesquare objects. Like I said, nothing ground breaking but it does make my life easier and allows me to make some kinda cool scenes. The problem right now is that objects, other than size and orientation, are defined at their lowest level, meaning if I wanted say a green box, I would have to make an entirely new object. This is pretty much necessary for colors, but I may make it so I can override the shininess and transparentness of an object. Shrug, if I have time, less than a week left :).

Oh yeah, one more thing, notice how the first image doesn't have a window border? That's because my program saved it itself this time, no screenshot :). I'm using Qt, so it was as easy as image->save(filename, "PNG"); . Awesome.

Previous Entry More Raytracer
Next Entry The result
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Spicy Curse

1169 views

Missile Command

1131 views

I wanna make games

1125 views

A letter

1192 views

End of Days

1261 views

Workin' Hard.

1001 views

Not much new...

1016 views
Advertisement