Personal tools

LightandShadowMasks

From Odwiki

Jump to: navigation, search

UNDER CONSTRUCTION



Shadow and Light Masks

Your Objectives: To learn about shadow and lighting masks in lighting a scene Experience Level: Intermediate Time Required: 1 hour New Tools Introduced: Light's shadow masks and object's light masks Tutorial Files: shadow_light_mask.hip.gz shadow_light_mask_grp.hip.gz dimmer_panel.cui light_group_panel.cui

Introduction Setup Exploring Shadow Masks Exploring Light Masks Using groups with shadow and light masks Summary

23.1 Introduction: The ABC's of Light and Shadow Masks

The purpose of this tutorial is to familiarize you with the concepts of shadow and light masks and to provide a basic example to demonstrate their uses and advantages in lighting a scene. In this tutorial, we start with 3 colored lights and one distant white light, 3 objects to cast shadows from, and a ground plane to cast the shadows upon. We will experiment with different settings for the shadow and light masks to demonstrate the various effects that can be created by manipulating these controls. In addition, we'll also explore the use of groups to control the light and shadow masks.

23.2 Setup

Since shadows are a function of lighting, controlling the shadows cast by lights involves configuring the light itself. Shadows can help add much realism to your images but often will increase rendering times, a tradeoff is often required to find a practical balance between the two extremes.

To start, bring up a fresh Houdini session and open the $HFS/demo/shadow_light_mask.hip file. Select the model desktop and examine the various panels and their settings for each light and object in the scene, including the SHOP's (SHader OPerators) for the lights and shadow shaders

You can determine which lights will cast shadows by changing the setting of the light's Light>Shadow Mask parameter. The default setting is "*", meaning the light will cast shadows on all objects it's rays strike.

Here's a view of the overall setup showing the placement of the lights and objects in the scene:


For the three colored lights, we have created a light each with different colors, red, green and blue. Here's the parameter panel for one of the lights, light1, which we've set it's color to red. Notice the Light>Shadow Mask is set to it's default setting, "*", which will have this light cast shadows on all objects illuminated by this light.

To specify the shaders for the lights and their respective shadows,we select which SHOP will used as the light's shader and it's shadow shader in the Light>Shading tab for that particular light.

Below are the SHOP's used to define the lights in our example scene. I've defined 3 VEX ASAD lights for each of our colored lights; notice I'm using a channel reference for the light color to ensure they'll be the same as that in the light's Light>Light Color parameter.

Using the expression: ch("/obj/light1/cr")*ch("/obj/light1/dimmer") will give the SHOP light it's color multiplied by the dimmer value of the light.

Below are the SHOP's defined to cast shadows for the lights. Notice I am using Filter Shadows to be able to have transparent and textured shadows. This is about the most expensive shadow casting in terms of rendering time, and may not be needed in your scenes. For more information of the types of shadows available, refer to the Houdini Users Guide and Reference Manual. The distant light, "light_dist", also uses a VEX ASAD light, but is positioned further away from the letter objects.


For this tutorial I have also created a custom panel to make it easier to interact with the intensity of the lights. This is provided as a convenience and is not necessary for using light and shadow masking but can make lighting your scenes easier than having to go to each light's Light tab to change it's intensity. With the viewer set to smooth shading or VEX shading, you can interactively adjust the intensity of each light and see the resulting colors. Make sure you place the dimmer_panel.cui file in your $HOME/houdini/custom directory (custom panels are not stored with the .hip file so you'll have to place the file there manually). Select "Custom Panel" from a viewport to use the dimmer sliders.


To understand how the custom dimmer panel is controlling the lights, notice that the sliders are "parameter linked" to the dimmer values of the three colored lights and the distant white light:


The distant light is defined as white in color and is provided to give an overall white light to scene while you experiment with various lighting settings. The intensity of it's SHOP lighting shader is also controlled by one of the sliders in the custom dimmer panel.






23.3 Exploring Shadow Masks

With all the lights defined with their default shadow masks, all lights will cast shadows on all the objects they illuminate. Here's what the shadows would look like with all lights, colored and white, on at full intensity; notice the different combinations of colors cast by the shadows.


Here's the image with just the red light illuminating the scene:


Here's the image with just the green light illuminating the scene:


Here's the image with just the blue light illuminating the scene:


By setting the shadow masks for a light, you can control which of the objects will cast a shadow from each light. Notice in the panel below that the Light>Shadow Mask for light1 is set to the object "letter_a". You may also use wildcards and object groups to specify the shadow masks, i.e. letter_?, @letters, etc. as well.



With just the red light on, and it's shadow mask set to "letter_a", the resulting image would look like this:


And of course each of the other lights are set to "letter_b" and "letter_c" for light2 and light3 respectively, the resulting images would like this. For the green light:


And for the blue light:


If more than one of the colored lights are turned on, the resulting shadows are going to be varying combinations of the lights in the scene and can produce some very interesting effects. Here's a few examples.

With just the red and blue lights on:


With just the green and blue lights on:


With just the red and green lights on:


Now with all 3 colored lights, and their respective shadow masks set to corresponding objects would result in an image like this:



23.4 Exploring Light Masks

Just as you can select which objects will have shadows cast, you can also select which lights will illuminate an object by setting the object's light mask, Shading>Light Mask, to the lights you wish the object to be lit by. As with shadow masks, you can also use object groups to specify the lights, i.e. @key_lights, @fill_lights, etc.


Note: Since the objects are being shaded by a white surface shader, all the light is reflected off the surface which makes the object appear the same color as the light. If the surface shader is some other color, it will change the appearance of the objects based on this combination of the source light(s) and surface color.

In this image, I have set the light mask for each letter to be a single light, i.e. for the letter_a, light1, letter_b, light2, and letter_c, light3. You can see that even though the objects are being lit by a single light, the shadow colors are the same as if the light masks were not changed from their defaults. The distant white light is also turned on to demonstrate it is casting a shadow but none of it's light is contributing to the color of the objects.


Here's the same image without the distant white light. Notice there's no change in the object's color but is now missing the gray shadows previously cast by the distant light.


This image is not only using light masks to assign specific lights to each object, but also has shadow masks defined for each color light and thus casts only a single shadow for each object.








23.5 Using groups with shadow and light masks By grouping your objects and lights into collections, you can control your scene's lighting and shadows with more flexibility. This is essential when your scene has many lights and objects, specifying individual elements, i.e. light1, light2, etc. can be needlessly laborious.

Open the tutorial .hip file, shadow_light_grp.hip and examine the group list in the object's network editor panel. You will find that there are a number of groups defined, left_group (the 3 leftmost lights, "red" in color), center_group (the 3 center lights, "green" in color), rt_group (the 3 rightmost lights, "blue" in color), letter_group (the 3 objects, letter_a, letter_b, letter_c), num_group (the 3 objects num_1, num_2, num_3), etc.

Note: For this part of the tutorial I have defined 3 more objects for the scene (numbers 1,2 and 3), 6 more colored lights (and positioned them together in groups of three), 3 more white distant lights, and another camera positioned above the scene to enable a better view of the more complex set of shadows created by more lights in the scene.


Here's the 3 lights in the left_group, which is more red in color, and is positioned to the left of the objects. Notice there is a shadow mask, @letter_group for each light in the left_group:


Here's the 3 lights in the center_group, which is more green in color, and is positioned to the center of the objects. Notice there are no shadow masks for each light in the center_group:

Here's the 3 lights in the rt_group, which is more blue in color, and is positioned to the right of the objects. Notice there is a shadow mask, @num_group for each light in the right_group:


Here are the letter objects defined in the letter_group, notice that there is a light mask defined, @left_group, for these three objects, thus they will be illuminated only by the leftmost set of lights. The shadows cast by these objects are defined by the shadow mask of the lights in the scene.


Here are the number objects defined in the num_group, notice that there is a light mask defined, light1, light2, light3, for these three objects, thus they will be illuminated only by single lights (which happen to belong to the left_group, the leftmost set of lights). The shadows cast by these objects are defined by the shadow mask of the lights in the scene.


Here is the custom panel created to turn off the groups of lights without having to adjust each light:



You may find that all your custom control panels will not load when launching Houdini. If so, use the cuimport command to load the custom panel's .cui file. Here's an example: cuimport -n $HOME/houdini4.9/custom/dimmer_panel.cui


Notice that each button in the light group custom panel will execute a script command set to the state of each light group's lights thus demonstrating an easy and time saving way to set parameters for groups of objects:


Now with all these groups defined we can control the lighting and shadows in even more flexible ways. For example, here's the image created with all the colored lights on, casting a number of different colored shadows, and illuminating the objects in a variety of shades of colors. The objects are all shaded with a white plastic shader, so their color has a direct relationship to the lights illuminating them. From the above_camera:


From the camera:


Here's the image when illuminated only by the left_group of lights. From the above_camera:


From the camera:


Here's the image when illuminated only by the center_group of lights. From the above_camera:


From the camera:


Here's the image when illuminated only by the right_group of lights. From the above_camera:


From the camera:


Here's the image when illuminated only by the dist_light_group of lights. From the above_camera:


From the camera:


23.6 Summary

To summarize, using shadow and lighting masks not only enables a vast area of creative options, it can reduce rendering times tremendously when judiciously used in a scene. When considering the lighting requirements for a scene, all factors must be considered to accomplish the desired image yet be efficient enough to allow for practical rendering times for complicated scenes. Considering that a scene may often contain many more lights than in this basic example, to have the renderer not waste time and resources on unnecessary shadows and specifying lights for objects can speed up otherwise unacceptable render times. In addition, often times it's better to have objects with a clearly defined shadow from a single light source and using other lights for for highlights, fills and special effects. Light and shadow is an important part of storytelling and adding realism, and even "hyper-realism" in a scene.

Checklist of important points to remember: 1) Shadows are cast from objects by lights who have those objects specified in their Light>Shadow Mask parameter. 2) Objects are illuminated by lights which are specified in their Shading>Light Mask parameter. 3) Masks can specified with wildcards and object groups.

In our next tutorial we'll explore more advanced applications of shadow and light masking within a scene including animating the masks, assignment of masks for realistic images and special effects, using masking techniques for atmospheric and environmental effects, as well as rendering optimization.