Square Enix © Goodbye Kansas

Table of Contents

This page provides a guide on using the Maya Sampler Info node with additional V-Ray Attributes to control what items receive shadows.

Overview


In this tutorial, we discuss how to use the Maya Sampler Info node to control which items receive shadows and which don't. With the use of each object's ObjectID setting, a shadow-casting object can cast shadows on some other objects but not others. Accomplishing this will require some extra attributes from V-Ray to give the standard Maya node these additional abilities.

While for simple scenes it is possible to use a copy of the light (or lights) to illuminate different objects in different ways (by using shadow linking), for more complex scenes this method becomes unwieldy and overly complex. It is also prone to problems such as shadow Z-fighting unless one of the lights is moved slightly away from its copy. But using the samplerInfo node, with the V-Ray Additional outputs, it is possible to control which geometry casts shadows on other geometry within a scene. With this method, you control the casting and receiving of shadows via the VRaySwitchMtl material and Object IDs with a straightforward setup.

The Sampler Info node is a Maya utility node that provides various scene information that can be used in shading networks at render time. V-Ray Extra Attributes can be applied to the node to increase the node's output options. For more information, see the Additional Outputs section of the Texture Attributes page.

How it Works


Using the methodology in this tutorial, you can use Object IDs to determine which objects will receive shadows. 

The diagrams below show how Object IDs relate to the shadows being received. Note that only the Object IDs of objects receiving shadows matter in this setup. The Object ID of an object casting shadows does not make a difference. 

 


Shadows as they appear normally.
The sphere casts shadows on both the table and floor,
and the table casts a shadow on the floor. 

 

 


No sphere or table shadow on floor (Object ID = 0).
Sphere shadow appears on table (Object ID = 1).  

 


Sphere and table shadows appear on floor (Object ID = 1).
No sphere shadow on table (Object ID = 0).

 

 

 

Tutorial Steps


In this tutorial, we will show how to adjust the shadows in the egg scene shown above. The shadow cast by the topmost egg will be limited to falling on certain objects. At this point, all the eggs have the same material applied to them:

 


 

In this tutorial, the main shadow-casting object is considered to be the topmost egg. All other objects in the scene can potentially receive shadows from the main shadow-casting object.

Set up Object IDs

The first step is to set up Object IDs for objects that will receive shadows, which includes the grass and all eggs except the topmost egg. Before you can do this, you must add the V-Ray Object ID attribute to these objects. 

1. Select the objects that our main object will cast shadows upon, under normal circumstances where no special parameters are set. Whether the shadows are cast upon objects depends on the current lighting setup. Select these shadow-receiving objects one at a time, and add a V-Ray Object ID attribute to each (Attributes > VRay > Object ID). 

 

 

 

2.  For any object that is to receive shadows from the main shadow-casting object, set the Object ID to 1.

 

 

 

3.  For any that you don't want to receive shadows from the main shadow-casting object, set the Object ID to 0.

 

 

For objects that could potentially receive shadows from the shadow-casting object in the scene, assign an Object ID of 1 to geometry objects that you want to receive shadows, and an Object ID of 0 to geometry objects that you do not want to receive shadows. No special material is required for these objects. If you don't change the Object ID for an object, it will behave normally, receiving shadows if shadows are cast upon it.

 

Set up Shadow Material Override

The samplerInfo node, with additional V-Ray outputs, makes it possible to control which geometry casts shadows on other geometry within a scene. With this method, you control the casting and receiving of shadows via the VRaySwitchMtl material and Object IDs for the various objects.

1. Open Hypershade and create a samplerInfo node.

 

 

2. With the SamplerInfo node selected, add VRay Attributes in the attribute editor: Attributes > VRay > Additional outputs.

 

 

 

3. The shadow-casting object must have its own shader which is not be shared with other objects in the scene. Create a new VRayMtl material for the main shadow-casting object, and with this material selected choose Attributes > VRay > V-Ray material override.

 

 

 

4. Since we will be using the Shadow Material override, make sure that Enable Shadow Material Override is enabled.

 

 

Set up VRaySwitchMtl

1. In the Hypershade create a VRaySwitchMtl material and name it ShadowControl.

 

 

 

2. In the material 0 slot, add a VRayMtl material named Transparent and make both the Diffuse Color and Opacity Map slots are black in color.

 

 

 

3. Duplicate the Egg_Whites_Mtl material and then connect the output of the Egg_Whites_Mtl to the Material 1 slot. This will provide the shadowed textures. Note Opacity must be set to a white color in order for this to work properly.

 

 

 

4.  In the Hypershade, navigate to the Utilities tab and drag the SamplerInfo node we created earlier into your graph area. We will use this along with Object IDs to drive the VRaySwitchMtl.

 

5. Connect the V-Ray Parent Object ID Tex output of the SamplerInfo node to the Materials Switch input of the Switch Material. This can be done by left-clicking on the white circle on the right-hand side of the SamplerInfo node, selecting VRay Parent Obj IDTex, and connecting the wire to the Materials Switch channel. You can also select the vrayParentObjIDTex output and the materialsSwitch input in the Connection Editor window.

 


The V-Ray Switch material set up for shadow control is assigned to the topmost egg

 

 

6. Middle-click-drag the VRaySwitchMtl material into the Shadow Material slot for the VRayMtl of the main shadow casting object.

 

 

Render the Result

The images below show the render result of our setup. The image on the left shows a render before the Switch Material is used with the Sampler Info node to control the shadows, to help you visualize the difference between the renders. The second image shows the result of our Sampler Info and Switch Material setup, where the egg on the top of the pile is casting shadows on the grass but not the other eggs. The last image shows the egg on the top casting shadows on the other eggs but not on the grass.

 


No Switch Material used.
Topmost egg casts shadows on other eggs and grass. 

 


Eggs in grass have Object ID of 0, grass has Object ID of 1.
Topmost egg casts shadows on the grass but not on the other eggs. 

 


Eggs in grass have Object ID of 1, grass has Object ID of 0.
Topmost egg casts shadows on other eggs but not on the grass.