Showing posts with label CG2. Show all posts
Showing posts with label CG2. Show all posts

Friday, May 2, 2008

Of Intersection Tests and Floating Point Error

XNA's Ray-Sphere Intersection test returns true with a distance of zero if the Ray originates inside the sphere.

This is great for games. Very fast. Avoids all the lengthy distance calculations and just kicks out an indication of collision.

This is not good for ray-tracers. The transmitted ray specifically looks at what happens when a ray travels through a translucent object. The requires us to spawn a ray within a spherical boundary and find the intersection on the other side.

I've tried writing a new sphere intersection test. There are a couple that I've found that I really like, and are very slick. The problem? C#'s floating point numbers aren't accurate enough to support them. Whatever XNA's BoundingSphere is doing, it's accurate enough for these calculations, whereas I can't figure out how to make mine accurate enough.

So I'm going to try to fake it. I'm going to use the XNA sphere test for external intersections, and my own for internal calculations. Once I know that I'm inside from the other one, hopefully I'll be accurate enough on my own.

Using XNA's vector class may have been a mistake here. Probably should've rolled our own using double precision numbers.

Friday, March 28, 2008

What colors?

I went back and updated my home page so that it wasn't using the default colors from the style sheet I obtained.

I used the Web Color Wheel to help me pick colors. I think they came out alright.

In other class news, my neural net for my AI class only sort of works. It nails a few of the mouse gestures it's supposed to recognize, gets s a few completely wrong, and gets a few backwards. It will, for instance, identify a down-right corner as a left-up corner, which is close but not correct. (Technically, they are the same image, but the order the segments are drawn does matter in this case.)

On the other side of things, my ray-tracer project in CG2 is going perfectly. I've implemented a new finite plane allows us to test against arbitrary polygons in a way that's less risky than the cheap triangle mesh I had previously written. For instance, the seam between the two triangles in our checkpoint 2 images does not appear under the new implementation. A side effect of this was identifying the cause of some wacky planar behavior, mostly that our planes were appearing reflected opposite the origin of where they were supposed to be.

In addition, I worked in generalized super sampling. I wrote a really quick and dirty super sampler for checkpoint 2, and rendered an image with it for the bonus grade. I have now gone back and taken the very specific case that was used to make that image, and generalized it. Now, when super sampling, you specify the number of samples you want and a radius around the camera origin, and it calculates the ray origins regardless of camera direction. It works no matter what. This is much better than the last one we had, which was locked to 4 samples, and only worked properly when looking up or down the z-axis.