From the course: NUKE NUGGETS

082 Preventing distortion of a spherical texture map - Nuke Tutorial

From the course: NUKE NUGGETS

082 Preventing distortion of a spherical texture map

- Hi, this is Steve Wright, welcoming you to this week's Nuke Nugget. When photographing a texture map from inside a sphere, you have to be very careful, to avoid distorting the image. Here, we'll see why it'll get distorted, and a quick and easy way to get it perfect, every time. Now, here's our setup. My image, here, actually has an Aspect Ratio of 2.41. Over here, I have a checkerboard that's exactly the same size. I'm just comping them together, so that we can use the checkerboard to confirm we're not distorting the image. So, let's start by seeing why it gets distorted. I'll come down here, to my sphere, and we look at it in 3D. My camera's inside the sphere, by the way, and you can see, if I whip around to the side where the center of the texture map is, you can see that I do not have nice, square squares anymore. The reason is that the texture map that wraps around a sphere, always has an aspect ratio of two to one, because it's going to map it from pole to pole, 180 degrees, and all the way around the equator, which is 360 degrees. So, the perfect texture map for the sphere has an aspect ratio of two to one. Anything that is off from that is going to get either squeezed or stretched, depending on whether it's larger or smaller. Now, the aspect ratio of an image is simply its width, divided by its height. So, like I said, this particular image had an aspect ratio of 2.4 to one, it's wider than that two to one, so it will get squeezed. So, I'm going to turn off my checkerboard, here. The first thing we want to do is do a mirror, set to flop. We need to flop the image, because we're going to be seeing it from inside the sphere, and the texture map is designed to be seen from the outside. So, flop it, make sure it's seen correctly. Next, we're going to pack it inside of a reformat node that is set to exactly a two to one aspect ratio. Now, what these numbers are, are not critical. I could have made this 3000 by 1500, or 2400 by 1200. As long as this rectangle is exactly two to one, and this guy is nestled inside, it will not be distorted. Key points: be sure to set the resize type to none, so that it doesn't, you know, do something bad like that, and have it centered, because if you don't, it'll be down here in the corner and things will be a little clumsier to work with in a minute, so always have it centered, and always turn on your black outside to avoid the streakies. Okay, so, we got things all set up. Now, let's take a look at how that looks on our sphere. We'll go to the 3D side, here, and there's our camera, and there is our beautiful little city thing. So, clearly, it's too large. Well, that's what this transform note is about. Watch this. (imitates shrinking sound) Now, the beautiful part about this is, I am absolutely guaranteed, no matter how I scale this, that I am going to keep the image undistorted. So, let's take a look at it through the camera, so we'll select our camera, lock the viewfinder, and as I bring it down, I'll just bring it down really small, so way inside my camera aperture. There we go, okay? So, watch what happens, now, if I size it up just to fit exactly top and bottom. You can see, there's a little bit of a gap here and here. That's the spherical distortion, because it's being wrapped around a sphere. Now, this is the important point about this process. The focal length of the camera affects the spherical distortion, so, see how much spherical distortion I have, here? My camera is at the default 50 millimeter focal length. Let's say I turn that to a 20 millimeter, kind of a fish eye, okay? Now I can compensate for the change by going to my transform node, and we can put both of these up there at the same time, and now I can change my scale factor to put it back where it belongs. Keep in mind, none of this is going to degrade the pixel quality, because Nuke concatenates all these transformations into one, but here's the punchline. Look at this. With the 20 millimeter focal length, I have much greater spherical distortion. Let's go the other way. We'll take our focal length up to 90, a longer lens, and now I'm going to back out and snuggle in, carefully and slowly. There, you can see I have almost no spherical distortion now, okay? So that's the relationship between the focal length and the spherical distortion when photographing inside the sphere, so let's restore the focal length to default, with a command, or click on the slider bar, and then go back and correct our scale to get a nice fit, top to bottom, making sure we've got picture everywhere. Okay, let's switch our view to 2D. I'm going to bring back my note graph, here, hook my viewer up to the Scanline Render node, and then hit the Tab key, to switch to my 2D view. So, this is going to be my render, so let's put in just a little bit of a camera pan animation, just for the fun of it. Playhead is on Frame One, so let's get our camera, up here, in the property bin, go to the camera tab, and let's add a key frame to rotate Y. We'll do just a little camera pan on this thing, okay? So, I'm going to sit here and just walk over to left edge. Whoops, okay, and then walk back a little bit ... There, let's call that good. Then, I'll jump to the last frame in the timeline, and just put a negative number in front of that. All right. Okay, now, I'll set the timeline to play once, and stop, and click play. Okay, so we're now rendering it in 2D, and the camera is slowly panning across. Now, this is going to give us a very slight spherical distortion, but it'll be very minor, and I think in most cases, it'll be fine, but now you know what to do if you want to almost eliminate it, just put on a longer focal length. So, there you have it. How to texture map the inside of a sphere without distorting the image. If you'd like to see all my Nuke Nugget courses on LinkedIn's lynda.com, just do a search on my name, Steve Wright. Be sure to check in next week, so you don't miss out on my next Nuke Nugget.

Contents