Subtitles section Play video Print subtitles Hey guys welcome back to another blender 2.8 tutorial. Today I'm going to be showing you how to do some camera mapping but also how to bake in the textures from that camera projection. So I have this photo that we're going to be using for this tutorial. We have essentially what is a box and then a bunch of stuff in the background. And the main idea is we're going to do some camera mappIng. So we're going to have a camera over here. And then a box that you know pretty much matches this box. We are going to project this image from the perspective of that camera on to that box. But then the new step is we want to have this box have any custom uv map we want. So we can unwrap it however we want. And then we want to bake the textures onto that uv unwrap. So unlike the projection, here we're going to have a custom uv map and bake it on to there. So again, the first step is to do some camera mapping. And I did cover this in a previous tutorial. So I'm going to do it. But I'm going to do it very quickly. If you want the full details there is a link in the description to the full tutorial for camera mapping. But this should be pretty quick. We're going to open up fspy to get the camera in the correct perspective. Use this photo right here. And then we just need to match up our x and y axes. So I'm going to turn off dim image so we can actually see what we're doing. We can have the y axis be along here and then the x axis be along here. Which is going to be really easy to set up because of course we have this box. So y axis. I'm just going to grab this handle and hold shift to get this zoomed in perspective. So again handlebar and then hold shift to get that zoomed in mode. And then of course we need 2 of these so it makes sense to have one y axis going here and then the other one going up here. We know they're parallel because they're part of the same box. So put one here. And also put one, where is it? Let me try that again. And also put one here. And then for the x axis same thing but in this direction. Again I'm doing this very quickly because I did cover it before. But I just want to make sure these fundamentals are still here. Think it's important. Put our other x axis over here. Just like that. And then once we're happy with this we can turn on our 3d guide and set it to xy. Because you know x and y axis. xy grid floor. And then we're going to take what's going to be the world origin in blender. We're going to take it and then just move it down to the corner. Holding shift so we can see what we're doing. Ok perfect. So when we import this into blender we're going to get a scene with this background and then the world oriented correctly with this camera in the right perspective. And then the origin is going to be in this corner. So let's do file. Save as. And then I'm just going to call this projection. And we're going to import this into blender. So I'm going to open up blender and of course you also need the plugin which again is free. All this is covered in the first tutorial. We need the plugin to import fspy files. So I'm going to delete this camera. We don't need it. We don't need this light. And I'm just going to keep this cube right here. So file, import, fspy. And then just navigate to wherever you have it. Ok so it set up our background. It set up our camera. And then you know the world origin is in the corner of the box. So the first thing we're going to do is we're going to save with control s. And then desktop. And let's call this thing, let's call it bake camera projection. Because you know this is what this tutorial is about. We're going to bake the textures. I'm going to go into our camera. Go into camera parameters. Background images and make this brighter. So we can see what we're doing. And then the first thing to do is to take this box and align it so that it matches with this box. So I'm going to take the corner, which should be this corner. And put it in the corner of our main box in the image. And luckily we have this set up very nicely. So we can just g for grab. Z axis and move it up by 1. And then same thing for the x axis. So g, x, 1. All keyboard shortcuts are going to be up here. And then g, y, 1. And let's see if that did what we wanted. Ya perfect. So of course we need this to be wider longer and taller. Which shouldn't be a big deal. We'll go into edit mode with tab. Select this face. Again face selection with 3. And then we just move this until it seems right. So g and then x. And it doesn't have to be perfect. We can do a bit more aligning later. Take this face and then move it down the y axis. And then we just need to take this face and bring it up so it's using up the whole box. So g and then z. Until that looks about right. And here you see the error starting to accumulate as we go higher and higher and higher. You can see this little gap. And we can just adjust this by grabbing from this perspective. And just trying to fix that a little. So no it's not perfect. It's a bit of a slanted cube. But honestly I think it's going to be good enough. We can do a bit more correction. Something like that. So ya technically it's a slanted cube. But this should be good enough. So we are pretty much almost at the end of what was covered in the first tutorial for camera mapping. All we have to do is project the texture you know the background texture from this camera onto the mesh. So the way we're going to do that is we're going to select this. We can call it, what can we call it? We can call this thing original. So this is going to be our original cube. We can call our camera just camera. And also one other thing is our background image. Default when you export out of fspy it's going to call it something like this. So I'm just going to call it projection image. Just so we have some good naming conventions. So in shading for our original cube. What we're going to do is we don't need this bsdf. So x to delete. We're going to add an emission. And this is going to be important later. But we're going to do it with an emission. Plug this in. Plug it in like that. And then if you do not have node wrangler enabled go to edit, preferences, add-ons and type in node wrangler. And you should have this on. So make sure it's on. And then one thing it lets you do very quickly is we're going to select our emission and hit control t. And it's going to give us all these nodes. This node group we're going to move it back with g. You can do it without node wrangler it will just take some time. So we have texture coordinates set to uv. Feeding into this mapping node which we're really not going to touch. And then into this image texture. And of course for this image texture we want you know the image we're going to project. So we're going to use projection image which is already in there. And you see that none of this is looking correct but that's because we didn't do any of our projection. It's just using the uv map. So what we're going to do. Let's go into lookdev mode. What we're going to do is we're going to go into modifiers. And then do the same thing we would have done before. So originally what we would have done is done a uv project on our uv map. From the camera. And you see it's pretty much good to go. We do have a bit of distortion. Notice that the aspect ratio in this case is 1. And that's because our image if we go into properties is 3456 by 3456. So the aspect ratio is 1. If you had something a bit more common like let's say 1920 by 1080. You just divide the numbers and get your aspect ratio. So in that case it would be 1.7 repeating. And you just feed whatever number that is up here. Into your aspect. But in this case it is 1. And you do it's a bit distorted and I'll show you exactly how I know. So what we do, or what we would have done before is add in a subsurf. Put it on simple so it doesn't you know turn into a sphere. Bring up the divisions and then just bring this up. So this without and then this is with. So you see there is definitely some distortion. If we go into our camera. So with the subsurf we hide it and you see it looks perfect. Instead if we did not have this and then do a hide you see that it really is heavily distorted. So this is a necessary step. And then the issue is if we wanted to bake it. Originally the only thing we would have known to do is to apply these two modifiers. And then you see when we go into edit mode we have way too much geometry. We only want six faces. And technically yes this is baked on. It's sticking on to the mesh. But not only does this have too much geometry that's just one issue. The other issue is that if we go into our uv map. I'm just going to set this as our background image. Our uv map, it's essentially a frontal perspective projection. It's not a good unwrap. So if we had this box. What we would do is have the normal kind of unwrap. So for example I'm just going to import a cube and look at its uv map. So here you see we have this cross looking thing. And that's more so the kind of unwrap you would expect. Of course not exactly the same since these faces are longer here. It's not a perfect cube. So we want to get the texture to still be wrapped correctly. So it's still from the perspective of this camera. But we want to make sure that there's not as much geometry and also that the unwrap is better. So this is not a good approach. So we're just going to undo until we get these modifiers back. There we go. So I'm just going to close these. So that is originally what we would have done. So instead here is the trick for baking. What you do is you go into object data and then uv maps. So in our original object we're going to set a uv map and call it something like final unwrap. And what this is is it's going to be the unwrap that we would ideally want the texture to be baked into. So this is the final unwrap we want. Not this mess from the perspective projection. So let's actually set up this final unwrap. So go to uv editing. And initially we do have this cross which again is no good. It's assuming that this thing is still a default cube which it's not. It's stretched vertically. So what we're going to do is we're just going to go to edge selection. So that all the edges are selected. If they're not you can just click a and then they're all selected. And then you can right click. That's something somebody recommended in the comments. And then go to mark seam. So right clicking is you know it's faster than typing in mark seam here. Once we've marked all this seams we just do u unwrap. And you see we get what's essentially the normal unwrap. These four faces and then these two, once of which is rotated so let me just rotate it. R and then 90. And then just put it here. But this is one of the normal unwraps we would expect. You can do any unwrap, any custom unwrap that you want. So the goal is to get this texture on these six faces and not have to do a lot of subdividing to undistort the projection. So that's our goal. So what we're going to do is we have this original. And we're not going to touch it for now. So we"re just going to duplicate it. Shift d. Right click to center it. And then we're just going to call this new thing a projection. So we have our original, our projection. And let's hide the original. So we're just going to mess with the projection. So right now you see this projection also has the final unwrap because we just duplicated it. It inherited the same unwrap. So we can just add another one. And this is where we're going to have our messy projection. So we'll just call this projection unwrap. And then make sure this one is the visible one. So we're going to be messing with projection unwrap for now. And here we do the same thing we would have done. We add our uv project. And for our uv map, very important, select projection. So we don't want to touch our final which is the good one. Just our projection unwrap. From the camera's perspective. Perfect. You see it's distorted. And we know to solve that with a subsurf. Set to simple with more divisions. And then bring that up. Maybe only four divisions. Ok so that's off and that's on. Perfect. So I'm just going to apply both of these. So now again this is technically in some sense baked on. But we do not want all this extra geometry. And we also especially don't want this very bad uv map. So you can essentially see what it's doing here. We have our top face which is heavily divided. So this top face is you know the top face of this image. This one here this side is the side etc. So we want to have this not be like that but more like our original uv map. So how do we do this? Well this is with baking which is the new idea. So how do we do baking? Well what we do is we begin, oh by the way one more thing before we get into baking. The other uv map, our original. You see it's the same. You have your six faces. They're just more divided but it's the same uv map as our original. So if we bake into this and make a new image we'll be able to put it here as well. Because it's essentially the same uv map. Just wanted to say that. So now onto baking. So how do we bake? Well baking is native to cycles at least for now. So what we do is we change to cycles render. That's the first thing. Going to change this to GPU compute. And then what we're going to do is you see there is this bake tab down here. So you can scroll down here. We're going to go into shading. And you see this is our original node set up. Nothing wrong with that. But we're going to take this node, this image texture and duplicate it with shift d. Bring this down here. And then here is where we want our new image which should look like a bunch of textures on these four faces. And then two up here. And not like our original image which looks like that. You know that is not what we want. So what we're going to do is we're going to take this node and create a new texture through here. And we can call it something like bake, that's in all caps. We can call it bake final. And then you can set your resolution. This is part of the quality of your bake. So you want high resolution here and then also lots of samples when you do your bake. So I'm going to do something like 1500 by 1500. So I'm going to click ok. So what we've done is create a new blank image called bake final. It's black because we didn't do anything to it. We just defined it. We wouldn't expect there to be anything. So before we can plug this into the surface we need to make sure we actually bake something into it. So I'm going to go into this render tab. Go into bake and then a couple things. So again we're baking into this node for uv map in our projection object. I'm going to go to uv maps. So we have our projection unwrap visible as you can see. But I'm going to select our final unwrap which is the nice looking one. So make sure this is selected. And then go to the render tab. And then for the bake type I'm just going to set this to emission or emit which is the reason why we passed everything through this emission node. So that it would only bake anything that"s coming through here and not anything else. And then once all that is set up. So again you have this node. You have the final unwrap selected. And you have this set to emit. You just click bake. And it's going to take a bit. Oh by the way another way you can bump the quality like I said is to bring up your samples. I'm pretty sure that matters. So 200 click bake. And you see that it's chugging along here. It will take longer depending on the quality. But this is something you want to have high quality because you only do It once. So it's worth it. So it's just going to chug along here. And when it's done it's going to pop up here in this bake final. At least it should. And I don't think I'm going to fast-forward because I don't think it's going to take that long. But ideally if everything works we're going to have the same image but kind of chopped up and corner pinned to look like it's four pieces here and then two pieces here. So it's almost done. Perfect. So you can see what happened. I'll go to uv editing and change the image to our bake final. So you can see it took the image and chopped it up into six pieces that match our uv map. And more so it undistorted it. So let me show you what I mean. So this top area right here is our top face. So we expect this part of the box to be here. But in the original image which is this one, this one. In the original image you can see that it's very distorted. Because our camera is over here. What essentially happened is it kind of looks like the camera is up here looking straight down on this part of the box as you can see here. As you can see here. And it did this for all the faces so that's the power of baking. And really it only did this for this face, this face, and this face. Because those are the ones facing the camera. We would need to set up another photo back here to capture data of this stuff. So really we only have these three faces. But these three that you see here should be looking perfect. Ok so now how do we kind of finish this off? Well we have this projection object which has too much geometry and one of the unwraps looks bad etc. So we can just take it and delete it. We don't need it anymore. The camera, delete it. We don't need it. So now if we just have our original. Which still kind of looks messed up but that's because we didn't use our new texture. So now if we take this and go into shading. You're going to see we can take this new, we can take this new texture. This new node. And plug it into the surface. And then everything works out as you can see. If you don't want to do that we don't actually need to do that. We can just take this existing node set up with the emission. And then instead of this image we change to bake final and then everything works. Let me just emphasize what we did here. So in this object we only have the original final unwrap. Because we didn't need to add that projection unwrap. Because this is the low-res version. So this object only has six faces. We didn't need to add extra geometry. It's also connected. The texture is, I wouldn't say inside. But it's stitched or stuck. I don't know what the best word for it is. But it's on there. So we've really baked the texture onto here. And all the distortion that we needed the subsurf for. Because we baked that into the high-res thing, that is captured inside this bake. So we did all the hard work in our high-res and reaped the profits in this low-res mesh. So this is really the ideal thing. Again we would need another camera back here to get this stuff to be correct. Because again the camera couldn't see this area. So we wouldn't expect this to be perfect obviously. But there we go. So the grand idea just to review. Is we take an image set up our you know perspective, our camera, etc. Do our projection. But then instead of preceding normally what we do is we create a duplicate. Create an additional uv map which is the bad one. So we make sure we do our custom unwrap first. We then on the high-res object, we basically switch the texture from one uv map to another. So we bake between uv maps. And because the new texture you get is for the uv map that's essentially the same as this one. It's just more subdivided. It works out if we plug it in here. Instead of doing from high to high between the uv maps. You can also bake from the high-res mesh into the low-res mesh. But I do find that it doesn't work as well. So this is what I recommend. But there you go that's baking camera mapping. This is just a you know it's just a box. But it works for any geometry. Of course the more complicated the geometry, the more complicated it is the harder it is to uv unwrap and make your custom unwrap. But this technique works in general. And that's how you bake camera mapping correctly. So hopefully you enjoyed this tutorial. You learned something. Thank you guys for watching and I'll see you guys on the next one.
B1 US bake projection camera node image map Blender 2.8 Bake camera mapped projected texture tutorial 21 1 刘鹏 posted on 2019/09/15 More Share Save Report Video vocabulary