I had to sit here and play with this for over an hour and it’s a bit difficult to map an image like this but it can be done. The result is a fairly advanced masking technique that works like a charm.
Anyway, I had to create 3 render layers to accomplish this task. The first thing that you need to understand when compositing with Blender is the type of information contained in the different render passes. e.g. There are only 3 passes which contain alpha channel information (Combined, Color, and UV). You can find all of the necessary information in the following link but don’t expect to understand all of it right off the bat. I had to reference this section for six months before all of it began making sense to me:
http://www.blender.org/development/release-logs/blender-243/render-passes/
Even the wiki does not contain information as useful as that when it comes to composite nodes and render passes. It will really help you in your future compositing endeavors.
First you’ll need to duplicate the Earth two times and put a copy of it on layer 1,layer 2, and layer 3. If you add an IPO to any one of these Earths make sure that that each Earth copy shares the IPO. Next make each coppie’s material single user. Now delete the textures form the coppies on layer 2 and 3. Make the copy on layer 3 Shadeless. Now you need to uv map the city lights to the Earth copy on layer 3. For this technique to work the image needs to contain an alpha channel that only allows the lights themselves to be visible. The reason for this will become obvious when it’s time to composite the render layers in the nodes compositor. Place your light source on layer 4.
Now it’s time to create your render layers. Render layers are quite different from scene layers in that they can contain objects from any combination of scene layers or from all or no scene layers. We will be reusing the light source on scene layer 4 in this fashion. If we did not place the light on it’s own layer then we would need to duplicate it for each scene layer which would just make the scene bloated and messy once it began to become complex.
First render layer(Atmosphere). The Earth with it’s uv mapped atmosphere on scene layer 1 and it’s light on scene layer 4. Disable all buttons on the Render Layer tab for this render layer except for Solid, Sky and Combined.
Second render layer (Diffuse). A diffuse only pass of the earth with NO textures on scene layer 2 and the light on scene layer 4.Disable all buttons on the Render Layer tab for this render layer except for Solid and Diff. This is important because we need the diffuse shading to help create a diffuse shading inverted mask which will casue the lights to vanish as the Earth rotates into the sunlight. If any texture information is included in the diffuse pass then this mask will not work.
Third render layer (City Lights). A color only pass of the earth with UV mapped lights via an RGBA texture on scene layer 3, set to Shadeless on the Material tab. With the Shadeless button set there is no need to use any lighting. Disable all buttons on the Render Layer tab for this render layer except for Solid and Col.
Now it’s time to set up the composite nodes. Add 2 render layers to the composite nodes default setup. Select each render layer to contain one each of the 3 render layers. Before setting up the composite nodes render the scene. This will fill the render layers with image information that you need to be able to see while working. Next add a Color Ramp node and reverse it’s color bands. Now plug the Color Pass from the City Lights Render layer into the this Color Ramp. This will create a grayscale inversion of the city lights image. This mask will be subtracted from the mask that we create in the next step in order to create an alpha channel that will ultimately hide the city lights whenever they encounter day light while revealing them on the dark side of the Earth. Plug te result of this Color Ramp into a Viewer Node. You should see a bunch of black holes where the lights would be and white everywhere else.
Now add another Color Ramp and plug the Diffuse pass from the Diffuse Only render layer into this ramp. Plug the result into a viewer node. You’ll notice that you now have a grayscale representation of the diffuse pass. Add a mix node to this Color Ramp, set it to Subtract and set the Value to 1.0. Now plug the Alpha socket of the Atmosphere render layer into the top image socket this Mix Node making sure that the Diffuse render layer Color Ramp is plugged into the bottom image socket. Plug the result of this mix node into a viewer node. What we are trying to do here is to create and inverted grayscale image that directly corresponds with the diffuse shading in the day to night transition. When looking at the result in the viewer node it is obvious that our current result doesn’t have nearly enough contrast. Start sliding the white color band of this second Color Ramp to the left until the viewer node reveals a fairly close yet inverted representation of the day to night transition. The final result should look like a crescent moon in the viewer node. I had to move the slider about 95% to the left to get the result I was looking for.
OK, were getting close now. Select the mix node and SHIFT+D to duplicate it. Plug the Diffuse pass’s Color Ramp result into the top image socket, the City Light’s Color Ramp into the bottom socket, and the result into a Viewer node. What you should be seeing now is white dots only in the area of the Earth’s dark side and black everywhere else. This is the final mask (alpha channel for the city lights) that we’ve been working toward. Add a Set Alpha node and Plug this mask into the alpha socket, then plug the Color pass from the City Lights render layer into the image socket. Add an Alpha Over node and plug the result of the Set Alpha node into it’s bottom image socket and the Image pass of the Atmosphere render layer into it’s top socket. Leave the value at 1.0. Finally plug the result of this node into the image socket of the Composite node. If your lights don’t fade quite at the right place then just tweek the Diffuse renderlayer’s Color Ramp (via the white color band) untill you get exactly what you’re looking for.
I hope I didn’t leave anything out. Just ask if any of this is unclear.
Attachments