• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Prozak

Ray Tracing: Texture Map a Sphere

9 posts in this topic

I've been looking for this, does someone here know the equations to texture map a sphere, that has a polar north vector, and a rotation arround that vector?

Something along those lines at least, so I can extrapolate.

Thank you!
0

Share this post


Link to post
Share on other sites
The closes I seem to find is this article:
http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_6_Textures_Cameras_and_Speed.shtml

...but the code isn't very well kept, and the discription of the algorithm contradicts the code in places.

Any tips?
0

Share this post


Link to post
Share on other sites
Do you mean your sphere has a rotation attribute defined by an azimuth and inclination angles? If so, then it's relatively easy if you already know how to texture-map a sphere using spherical coordinates, you can just offset your UV angles according to your sphere's rotation. What format are your sphere textures in? The circular type or the rectangular ones?
1

Share this post


Link to post
Share on other sites
You can use [url="http://en.wikipedia.org/wiki/Cube_mapping"]cube mapping[/url] to texture a sphere, the normal would be the texture coord. Edited by Ashaman73
1

Share this post


Link to post
Share on other sites
Bacterius: Thanks for your reply. Offsetting my U coordinates allows me to rotate the sphere along the equator. The same does not work with the V register, as it puts the south pole along the equator, stretching it. My current textures are classic earth, moon, mars textures.

I have a screen shot here: http://www.positronicdreams.com/stuff/fup/_fileup/raytracing001.png

Everything seems perfect in that image, but it isn't. I can mess with the U coordinate, but I can't rotate the sphere or anything. In the link I provide as source, it seems that the equations take a north vector, a right vector, and a 3rd vector (cross-product of the first 2), so this would give us 3 axis to manipulate the sphere, but alas, whenever I mess with those, the resulting image has flaws, most common is texture mirroring along some axis on the sphere...

Ashaman73: Thanks for replying. I'm really set on doing classic texture mapping, onto a sphere. All I want is a good pointer where I can read up on this and get it right, or at least copy some code. I really don't want to do cube mapping at this time.
0

Share this post


Link to post
Share on other sites
Can you show your texture mapping code? There is a "perfect" mapping method that involves converting the position on the sphere to spherical coordinates and sampling your texture this way, but it is rather compute-intensive (a couple inverse trigonometric functions, so quite undesirable) and from your description my guess is you are using the tangent/bitangent/normal technique to texture your sphere, which - iirc - has a few gotchas to keep in mind, and I think one of them, is that you must modify your "up" vector in your cross products to be the sphere's polar vector instead of just using a constant up vector if you want to "wrap" the texture differently, are you doing that?
1

Share this post


Link to post
Share on other sites
Bacterius, thank you for your continued interest. I'll write a reply later when I get home with the code I'm using. Again, thank you.
0

Share this post


Link to post
Share on other sites
Bacterius: Ah, solved it! Also added matrix operations, and a rotation procedure, and was able to tilt the sphere by 30º, and saw that the texturing was all correct. No mirroring at the poles.

Can I bother you with a few questions?

1) Regarding colors, as I trace a ray through the scene, through reflections, textures, etc, for each step of the way how do I handle the computation of the final color?

I'm, for now, going with:

rgb_final = (rgb1 + rgb2) /2;
...basically averaging colors for each ray collision...

I've heard something about color multiplication, like so:
rgb_final = rgb1 * rgb2;

2) If I hit a reflective surface, should I follow the surface's Normal vector, or should I calculate the reflection as below?
R = 2(AP . N) x N - N

AP - Vector from view to Intersected Point, normalized
N - Normal Vector of the surface, normalized

3) Any online resources you advise?

Thank you! :D
0

Share this post


Link to post
Share on other sites
[quote name='Prozak' timestamp='1349706237' post='4987999']
Bacterius: Ah, solved it! Also added matrix operations, and a rotation procedure, and was able to tilt the sphere by 30º, and saw that the texturing was all correct. No mirroring at the poles.
[/quote]
Glad you solved it!

[quote name='Prozak' timestamp='1349706237' post='4987999']
1) Regarding colors, as I trace a ray through the scene, through reflections, textures, etc, for each step of the way how do I handle the computation of the final color?

I'm, for now, going with:

rgb_final = (rgb1 + rgb2) /2;
...basically averaging colors for each ray collision...

I've heard something about color multiplication, like so:
rgb_final = rgb1 * rgb2;
[/quote]
Well, this is a tricky question, but in theory you multiply bounces. This is because in real life, light comes from light sources, and bounces into your eye. So say a light ray starts with energy E, then hits a reflective surface like a mirror. It'll bounce in the reflected direction, but might lose, say, 4% of its energy. Then, it hits a diffuse surface, and loses another 10% of its energy. Then it enters your eye. So in total, its new energy is E * 0.96 * 0.90. If you do this backwards (which is allowed because of reciprocity), it becomes 0.90 (reflectance at first bounce) * 0.96 (reflectance at second bounce) * E (emittance at light source). It's a bit more complicated if your surfaces both emit and reflect light (it becomes a recursive multiplication of emittance + reflectance).

It's the same with RGB, except instead of raw "energy" you directly work with RGB channels (which are, by the way, simply measures of energy for three wavelengths: red, green and blue). So, yes, colors at each bounce must be multiplied component-wise, and your ray should also start at values (1.0, 1.0, 1.0) by definition of the empty product.

Note this also means your light RGB values will typically be greater than 1, that's ok and completely expected (and if you get final RGB values which are bigger than 1 and you have to clamp them, you should look into tone-mapping)

[quote]2) If I hit a reflective surface, should I follow the surface's Normal vector, or should I calculate the reflection as below?
R = 2(AP . N) x N - N[/quote]
The formula above is wrong, I think, it's actually R = I - 2 * N * dot(I, N) where I is the incident vector (your AP) and N the normal. You must always follow this new reflected vector for perfectly mirror surfaces, anything else will look very wrong. However, not all reflective surfaces work like that. Most actually reflect light over a small "cone" focused on the reflection vector, so that the reflected image looks kind of blurred. Others (diffuse surfaces) reflect any incident light randomly in any direction. It's a fairly complex topic, but in general, if you hit an ideal mirror, you always use the equation above. This comes from the principle of least time, which states that when bouncing off a surface, light will take the shortest path from point A to point B - which happens to be described by the equation above.

[quote]3) Any online resources you advise?[/quote]
Many. If you ever need physics information about whether what you're doing is right, Wikipedia and Hyperphysics are the place to go. Also, Physically Based Rendering (book) covers a lot of ground when it comes to raytracing. You can also have a look at [url="http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_1_Introduction.shtml"]this in-depth tutorial[/url] about ray tracing, or perhaps [url="http://www.codermind.com/articles/Raytracer-in-C++-Introduction-What-is-ray-tracing.html"]this one[/url] both of which I found useful to work out some concepts, particularly regarding cameras.
1

Share this post


Link to post
Share on other sites
[img]http://upload.wikimedia.org/math/e/9/6/e967228d6f4a80a55220a7c4b70ebcba.png[/img]
[img]http://upload.wikimedia.org/math/a/d/4/ad415e568bc911ec29c8233d7c26bef2.png[/img]

dx, dy, dz - Normal of the sphere.
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0