Blender Cycles:Materials and Textures Cookbook(Third Edition)
上QQ阅读APP看书,第一时间看更新

Creating a mesh-light material

In this recipe, we will see how to create a mesh-light material to be assigned to any mesh object and used as a source to light the scene.

Getting ready

Until now, we have used the default Lamp (a Point light) already present in the scene to light the scene. By enabling the node system for the Lamp, we have seen that it uses a material created by connecting an Emission node to the Lamp Output node.

The good news is that just because it's a material node, we can assign an Emission shader to a mesh, for example, to a Plane conveniently located, scaled, and rotated to point to the scene that is the center of interest. Such a light-emitting mesh is called a mesh-light. Being a mesh, the Emission shader node output must be connected to the Surface (or the Volume) input socket of a Material Output node instead of the Lamp Output node.

Light emission coming from a surface and not from a point is a lot more diffused and softer than the light from a Lamp. A mesh-light can be any mesh of any shape, so it can be used as an object taking part in the scene and be the real light source of the rendering at the same time, for example, a table lamp, or a neon sign, or a television screen. As a pure light-emitting Plane, it's usually used as a sort of photographic diffuser. Two or three strategically placed mesh-lights can realistically simulate a photo studio situation. To replace the Lamp with a mesh-light, Plane perform the following steps:

  1. Call the Blender User Preferences panel (Ctrl + Alt + U), navigate to the Addons tab, and click on 3D View under Categories on the left. Check the Copy Attributes Menu box to the right-hand side of the 3D View option, and click on the Save User Settings button in the bottom-left corner of the panel. Then close the panel.
  2. Starting from the start_07.blend file, click on the eye icon of Lamp in the Outliner to enable its visibility again.
  3. Right-click on the Lamp in the 3D view and press Shift + S to bring up the Snap menu. Click on the Cursor to Selected item.
  4. Press Shift + A with the mouse pointer in the 3D view and add a Plane to the scene at the 3D Cursor's location.
  5. Press Shift and select the Lamp. Now you have both the recently added Plane and the Lamp selected, and the latter is the active object.
  6. Press Ctrl + C to open the Copy Attributes menu and select the Copy Rotation item.
  7. Rename this Plane as Emitter.
  8. Right-click on the Lamp in the 3D view and press X to delete it.
  9. Put the mouse pointer on the 3D view and press 0 from the numeric keypad to go to Camera view.
  10. From the Viewport Shading menu in the window's header, select the Rendered mode (or put the mouse cursor on the Camera view and press Shift + Z):
    Getting ready

    A Plane set as a mesh-light to replace the Lamp, and the previous HDR image as the background

  11. Save the file as start_09.blend.

How to do it...

Now let's create the emission material and also take a look at the setup for the softness of the projected shadows:

  1. Select the Emitter plane and click on the little cube icon on the header of the Node Editor window.
  2. Click on the New button in the header and rename the material as Emitter.
  3. In the Properties panel, go to the Material window, and under the Surface tab, click on the Surface button to switch the Diffuse BSDF shader with an Emission shader. Leave the default color unchanged (RGB 0.800) and set the Strength slider to 25.000.
  4. Save the file.

    The situation so far is as follows:

    How to do it...

    The mesh-light emission material with increased strength

  5. In the 3D view, scale the Emitter plane five times bigger (press S, then enter 5, and press Enter), and then set the Strength slider to 2.500.
  6. Save the file as start_10.blend. Now look at the softer shadow, as shown in the following screenshot:
    How to do it...

    Scaling the mesh-light bigger and decreasing the emission strength to have softer shadows

  7. Now let's scale the Emitter plane a lot smaller (press S, then type 0.05, and press Enter) and set the Strength slider to 450.000.
  8. Save the file as start_11.blend. Look at the crisper shadow in the Rendered preview, as shown in this screenshot:
    How to do it...

    Scaling the mesh-light smaller and increasing the emission strength to have crisper shadows

How it works...

From steps 5 to 7, we saw how a mesh-light can be scaled bigger or smaller to obtain a softer (in the first case) or a sharper (in the second case) shadow, respectively. The Strength value must be adjusted for the light intensity to remain consistent, or the mesh-light must be moved closer or more distant from the scene.

Scaling the mesh-light is basically the same as setting the size value for a Lamp. For Lamps, the softness of shadows can be set by the Size value to the left of the Cast Shadow option in the Lamp window, under the Properties panel (by default, the Size value is set to 1.000). At a value of 0.000, the shadow is at its maximum crispness, or sharpness. If the Size value is increased, the softness of the shadow increases too.

Unlike the mesh-light, varying the Size value of a Lamp doesn't require us to adjust the Strength value to keep the same light intensity.

There's more...

In several cases, you might not want the emitters to appear in your rendering. There are node arrangements to accomplish this (such as using the Light Path node in a way quite similar to the Setting the World material recipe we have seen before), but the easiest way to do this is as follows:

  1. Start with the last saved blend (start_11.blend) and put the mouse cursor on the orthogonal 3D view to the left of the screen. Press the 3 key to navigate to the Side view. Then press Shift + Z to go in the Rendered mode to also see the Emitter plane rendered (be warned that if your computer can't easily render two windows at the same time, you must temporarily turn off the rendering for the Camera view).
  2. With the Emitter plane still selected, navigate to the Object window under the Properties panel.
  3. Look at the Ray Visibility tab (usually at the bottom of the Properties panel), where there are five items: Camera, Diffuse, Glossy, Transmission and Shadows, with the corresponding checked boxes.
  4. Uncheck the Camera item and watch the Emitter plane disappear in the rendered 3D window, but the scene still lit by it, as shown in the following screenshot:
    There's more...

    Disabling the Camera item in the Ray Visibility subpanel to hide the mesh-light Plane from the rendering

    When you disable any one of the items, the corresponding property won't take part in the rendering. In our case, when the Camera box is unchecked, the mesh-light won't be rendered but it will still emit light. Be careful that the Emitter plane is not renderable at this moment, but because all the other items in the tab are still checked, it can be reflected and could cast its own shadow on other objects.

  5. Now reselect the Spheroid (remember that unless you have renamed it, its name in the Outliner remains as Cube). Next, from the Ray Visibility tab in the Object window under the Properties panel, uncheck the Camera item.

    Now the Spheroid has disappeared, but it's still casting its shadow on the floor Plane, as shown in this screenshot:

    There's more...

    Disabling the Camera item to hide the Spheroid object from the rendering (but keeping the shadows on the floor)

  6. Now check the Camera item again and uncheck the Shadow box. In this case, the Spheroid is visible again but doesn't cast a shadow, as shown in the following screenshot:
    There's more...

    Disabling the Shadow item to have the Spheroid object rendered but without the shadows on the floor Plane

  7. Save the file as start_12.blend. Let's try tweaking this a little.
  8. Check the Shadow box for the Spheroid again, and select the floor Plane. Go to the Material window under the Properties panel, and click on the New button to assign a new material (Material.001).
  9. Still in the Material window under the Properties panel, switch the Diffuse BSDF shader with a Glossy BSDF shader. The floor Plane is now acting as a perfect mirror, reflecting the Spheroid and the HDR image we formerly set in the World material.
  10. Go back to the Object window and reselect the Spheroid. In the Ray Visibility tab, uncheck the Glossy item and watch the Spheroid, which is still rendered but not reflected by the mirror floor Plane, as shown in the following screenshot:
    There's more...

    By disabling the Glossy item, we have the Spheroid object not mirrored by the glossy floor Plane

  11. Save the file as start_13.blend.

Of course, the Ray Visibility trick we've just seen is not needed for Lamps because a Lamp cannot be rendered at all. At the moment, only Point, Spot, Area, and Sun lamps are supported inside Cycles. Hemi lamps are rendered as Sun lamps.

Both Lamps and mesh-lights can use textures too, for example, project colored lights on the scene, but only a mesh-light can be unwrapped and UV-mapped with an image map.

One advantage Lamps have over mesh-lights is that they can be made unidirectional easily, that is, apart from Point lamps, they cast light in only one direction. The following screenshot shows the casting of light with a Spot Lamp:

There's more...

A Spot Lamp allows light to point in just one direction

In the preceding screenshot, you can see that only the Plane and the Spheroid in front of the Spot lamp receive light. With a mesh-light plane replacing the Spot lamp, objects in both the front and the back (the half-cylindrical Wall and the second Spheroid) receive light.

There's more...

A mesh-light emitter illuminates the region backward and forward by default

What if we want to light the object in only one direction (Plane and Spheroid in front) with a mesh-light? Is there a way to make a light-emitting plane emit light only from one side and not the opposite side? Yes, there is; follow these steps:

  1. Open the 01_meshlight.blend file, which has prepared the scene used for the preceding screenshots, and be sure to enable only the first and the seventh layer.
  2. Put the mouse cursor on the left vertical 3D view, and press Shift + Z to navigate in Rendered view mode.
  3. Click on the Emitter item in the Outliner to select it (if not already selected), and put the mouse pointer in the Node Editor window. Add a Mix Shader node (press Shift + A and navigate to Shader | Mix Shader) and move it to the link connecting the Emission node to the Material Output node to paste it in between them.
  4. Add a Geometry node (press Shift + A and navigate to Input | Geometry) and connect its Backfacing output to the Fac input socket of the Mix Shader node.
  5. Switch the Emission node output from the first Shader input socket of the Mix Shader node to the second node, as shown in the following screenshot:
    There's more...

    Thanks to the Backfacing output of a Geometry node as Factor, a mesh-light can illuminate in only one direction

  6. Save the file as 01_meshlight_final.blend.

We have already seen that in a Mix Shader node, the first (upper) green Shader input socket is considered equal to a 0 value, while the second socket is considered equal to a 1 value. So, the Backfacing output of the Geometry node is telling Cycles to make the mesh-light plane emit light only in the face-normal direction, and to keep the opposite back-facing side of the plane black and non-emitting (just like a blank shader).

By switching the Emission node connection to the first Mix Shader input socket, it's obviously possible to invert the direction of the light emission.