Mask material transparency in 2D camera space.
- [Instructor] In a previous movie in this weekly series, we saw how to use the camera map modifier to project UVs onto an object from the point of view of a camera. In that situation, the camera doing the projecting and the camera actually rendering the shot were two different cameras. We're going to explore a different use case, here, in which the camera map modifier is projecting you these from the renderable camera, allowing us to build a shader network that incorporates in-camera compositing.
In other words, we can mask or otherwise shade an object or objects in 2D screen space, rather than 3D X, Y, Z space. I've got a scene set up to illustrate that. It's a product shot of this task chair and what I want is for the background to seamlessly blend into a pure white, and even though I've done my best to light the studio and the cyclorama within that studio to get an even illumination on that back wall, it's easier just to do it in compositing.
And we can set this up so that an environment background can show through, replacing this cyclorama based upon an opacity map, which is a gradient ramp operating in screen space with the camera map modifier. In the perspective and physical camera views, I've set it up so that we can see the environment background in the viewport. From the views menu, viewport background, I chosen environment background and I've set up an environment, already.
And it's displayed in the perspective and physical camera views. We want to mask this backdrop or cyclorama in screen space, so select that cyclorama and in the modify panel, add the camera map modifier. Camera map. Then click the pick camera button and click the camera in the perspective view. And it's listed here, PhysCamera001.
Now the UV coordinate space of the cyclorama is being determined by the position, rotation, and field of view of the renderable camera. And we can create a shader network that utilizes the screen space, specifically a gradient running top to bottom in the V space of the shader network. Let's open up the material editor, take a look what I've got in there. I've got a color map, which is applied as the environment background and a cyclorama physical material already assigned to the backdrop object, and I'm displaying shaded materials in viewport on that physical material node.
In the material map browser, in the maps section, in the category general, we can add a gradient ramp. Drag that over into the view and double click it. Rename it cutout. Let's connect it to the cutout map input on the physical material. With that connection made, we see some transparency effect on the cyclorama object. If we tumble around in the perspective view, we can see that it's got some weird diagonals to it.
This isn't necessarily going to render like this. It's probably an artifact of the viewport. We're not terribly concerned by that at the moment because we're going to change the coordinate space, anyway. In the coordinates roll out for the gradient ramp, switch it over from UV to VW, and now we see some gradients oriented correctly, the way that we want, and it's going in screen space, here, and the bottom of the screen corresponds to the left side of the gradient ramp, and the top of the screen corresponds to the right side of the gradient ramp.
We want this to be opaque at the bottom and transparent at the top, and so we want to start with a white flag, here, in flag position one. Double click that flag and set its value to maximum of 255. Let's create another flag, just click anywhere. Also set its value to 255. For those first two flags, they're pure white. For the third flag, set it to a value of zero and finally, for that fourth flag, select it and set its value to zero, as well.
We can drag the second and third flags around in order to preview the transparency effect we're creating. Let's set the second flag to a position of 52 and the third flag to a position of 54. We can read that out, here, in the gradient ramp parameters and now we've got a pretty sudden, sharp transition, here. We can soften that up a little bit by setting the interpolation mode to ease out.
Okay, that's all there is to it. We've created a mask or garbage mask and masked off the geometry in screen space. We can close the color selector and see what this looks like in the Arnold renderer. I've got that set up, already. I'll just click on the active shade button. And we can see the background showing through, here. Back in the material editor, we can double click on the environment color map node and set the solid color to saturation of zero.
Click okay and now we have a perfectly white background, here, with some nice, subtle shadows in the foreground. We've just made the cyclorama invisible and allow that white backdrop to show through. If you want to do the compositing in post and put that color or image in the background later, then you don't need to use the environment backdrop. In fact, we can do that too. In the rendering menu, choose environment and we can simply disable the environment map.
Turn use map off and now we have an alpha channel, there. We can check that by displaying the alpha channel in the active shade window, and so if we wish, we can composite this in post. I'll switch that back to RGB mode. That's how to use the camera map modifier to build a shader network that operates in the 2D space of the camera or screen. This has a lot more applications. We've just barely scratched the surface. Just imagine what you can do, knowing that it's possible to create a shader network that operates in camera space.