Texture mapping
Texture mapping for triangles and spheres has been implemented. This involved adding a new abstract (interface) Texture class along with a concrete implementation in the form of an SDLTexture class which loads image files using SDL_image. Barycentric coordinates are used to compute UV texture coordinates for ray-triangle intersections. For UV for spheres I eventually found an elegant method on Wikipedia. I first tried to come up with the sphere UV maths myself and actually came somewhat close to the method described on Wikipedia. My method did manage to map the entire surface of the sphere to the desired ranges x,y in [0,1], but resulted in incorrect stretching centered along the horizontal equator.
As an unintended bonus, it turned out that the code had no problem texturing the inside of the sphere. Handy to know should I ever need to implement a "photo sphere" viewer. I'm thinking of adding a property to the sphere object for indicating whether the sphere is hollow (accepting ray intersection tests with rays that originate from inside the radius) or not (rejecting such rays).
As an unintended bonus, it turned out that the code had no problem texturing the inside of the sphere. Handy to know should I ever need to implement a "photo sphere" viewer. I'm thinking of adding a property to the sphere object for indicating whether the sphere is hollow (accepting ray intersection tests with rays that originate from inside the radius) or not (rejecting such rays).
Texture mapping demo
Photosphere demo
Comments
Post a Comment