Ray Tracing: UV Mapping (Spheres)
While I found the guide on 1000 Forms of Bunnies to be pretty helpful, I actually found that the UV computations Victor used simply didn't work for me. I had to mess around with the math myself, and ended up using the Wikipedia formulas.
However, there is an important caveat with those formulas. Specifically, you can't just use your hit point as your vector d. You have to do || sphere.center - hitPoint || -- yes, that's a norm. If you don't, everything will be all screwed up. I also found that for the particular way in which my coordinate system is oriented, I had to manually add 0.5 to my U coordinates, because it was rendering the globe backwards. It's possible that I should've done || hitPoint - sphere.center || instead; I'll have to look into that later.
It's all very weird but you can get it working if you keep drilling deeper into the fundamental aspects of what's going on.
This is how I used STBImage.
I had to do a deep copy of the buffer every time I rendered a new point on the textured sphere, which was slow as hell. I used this because my knowledge of how to work with buffers in Java is almost nil at this point and time.I coded this in Java, not C++. However, the JPG parser in the STBImage class worked just as well in Java as it did in C++. I made sure to download ALL the jars, just to be safe. I will link my GitHub once more so you can see what I did specifically, though I'm sure there's a lot of places in which the code could be improved.
And of course, I used the UV computation to get the diffuse color and continued with the rest of my Phong lighting algorithm in order to get my spheres looking like they actually belonged in the scene.
And finally, the actual UV computation:
REPO
Results: (Yes, they don't look as good as they should, but I'll have something better by the time I finish the last lab. I think my choice of color there is a bit strong.)
Comments
Post a Comment