This page provides a tutorial on rendering an animation with moving objects using the VRaySphereFade and compositing.


Page Contents



In this tutorial, we will render an animation with moving objects and GI with V-Ray. The goal is to make the process as efficient as possible. We can always use a high-quality GI solution to render an animation without any special tricks; however, this often takes a very long time to render. We would like to optimize this process as much as possible.

Typically, we have a small number of moving objects (for example, a few characters) in a complex environment that doesn't move. Our main optimization idea uses this fact: we can split the animation into a background part and an animation part.

Since the background does not move, we can render it using a walk-through animation method, as described in the Rendering a Walk-Through Animation tutorial. Then we can render out the moving objects, and composite these for the final animation.

This tutorial will use two scenes. The first is a simple static scene with a teapot that will be used to demonstrate compositing basics. Afterwards, we will adapt the basic workflow to the more complex scene that has multiple animated characters.


Note: the scene used for this tutorial was based on the Sponza Atrium scene, modeled by Marco Dabrovic ( ) and was one of the models for the CGTechniques Radiosity competition.




Tutorial Assets

To download the scenes used in this tutorial, click the buttons below.


Scene 1: Teapot


Scene 2: Sponza Atrium



Compositing Basics

Before we go into the details of rendering animation, we will cover some compositing basics.

Our task is this: given an object in a 3D scene, we would like to composite the object over a given background, taking into account as many effects as possible (shadows, reflections, GI etc).

This is typically done with the help of two layers with the 3D object that are later composited over the background. One layer is the mask layer, and it determines which parts of the background are altered by the 3D object and which parts remain the same. The mask layer is multiplied by the background. We will call the second layer the object layer, and it determines what color must be added to the masked background in order to get the final image. The object layer is added to the masked background.

In general, the compositing formula is this: 

final_image = background_layer * mask_layer + object_layer 

Our background layer is provided, and we don't have to worry about it. It might be a photograph, live footage, or a pre-rendered image. We must determine only the mask layer and the object layer. We will compute these using three separate renderings of the 3D object:

  1. A render without the object; we will call this "pure" render.
  2. A render with the object, but with a perfectly black material applied to the object; we will call this "black" render.
  3. A render with the object with a normal material; we will call this "normal" render.

Given these three renders, we can compute the mask layer and the object layer using the following: 

mask_layer = black / pure
object_layer = normal - black

Finally, we can use the mask and object layers to composite the final image.



Part 1: Compositing in 3ds Max

Now, let us apply the above theory in practice. We will use 3ds Max for compositing, but this can be done in any compositing program that supports the necessary image operators (addition, difference, multiplication, and division) - for example, Digital Fusion.

Unfortunately, 3ds Max does not have the necessary compositing operators built-in, so we are going to use a V-Ray texture, VRayCompTex.

Below is the background plate we will use. We will add a teapot in the middle of the rendering.



Create the normal render

  1. Open the starting scene. The scene is not exactly the same as the above background plate, but it is close enough for the composition. In general, you should try to match the plate as best as possible. If the background plate is a rendered 3D scene, then it would be best to use the same scene.
  2. Render the scene and save it as normal.png with 48 bits per pixel. This will provide increased precision during the compositing later on.




Create the black render

  1. Open the Material Editor, create a new VRayLightMtl, and assign a pure black color to the material. Alternatively, you can use the included black mtl material.
  2. Apply the material to the teapot in the scene.
  3. Render the scene and save it as black.png with 48 bits per pixel for increased precision.




Create the pure render

  1. Hide the teapot.
  2. Render the scene and save it as pure.png with 48 bits per pixel.




Set up the compositing scene

At this point, we have finished our work with the provided 3D scene. Now we will set up a new scene for compositing the final result.

  1. Open 3ds Max with an empty scene.
  2. Open the Material Editor and put the four images (normal.png, black.png, pure.png and the background) into four separate Bitmap textures.
  3. In bitmap parameters, under the Coordinates section, switch from Texture to Environ. Set the Mapping to Screen


Calculate the object layer

We will use the normal and black renders to create the object layer.

  1. Create a VRayCompTex and name it object.
  2. Drag the normal bitmap onto the Source A bitmap slot in the VRayCompTex and choose the Instance method when prompted.
  3. Drag the black bitmap onto the Source B bitmap slot in the VRayCompTex and again, choose the Instance method.
  4. Set the Operator of the VRayCompTex to Difference. This is what you should get:




Calculate the mask layer

Similar to how we created the object layer, we will use the black and pure renders to create the mask layer.

  1. Create a new VRayCompTex in an unused slot of the material editor and name it mask.
  2. Drag the black bitmap onto the Source A bitmap slot in the VRayCompTex and choose the Instance method when prompted).
  3. Drag the pure bitmap onto the Source B bitmap slot in the VRayCompTex and again, choose the Instance method.
  4. Set the Operator of the VRayCompTex to Divide. This is what you should get:




Mask the background

Now we have the mask and object layers for the final compositing. Next, we must mask the background map by applying a multiply operation with the newly created mask layer.

  1. Create a new VRayCompTex in an unused slot of the Material Editor and name it masked bg.
  2. Drag and instance the mask texture into the Source A slot of the VRayCompTex map.
  3. Drag and instance the background bitmap into the Source B slot of the VRayCompTex map.
  4. Set the Operator of the VRayCompTex to Multiply.


Add the object map

Now that we have the masked background map, we need to add the object map to it. 

  1. Create a new VRayCompTex in an unused slot of the material editor and name it final.
  2. Drag and instance the masked bg map into the Source A slot of the VRayCompTex.
  3. Drag and instance the object map into the Source B slot of the VRayCompTex.
  4. Set the Operator of the VRayCompTex to Add.

This is our final composite texture map. Here is a schematic view of how we have connected the four input images:




Render the final composite

Now we need to render that map in order to get the final image. 

  1. Open the Render Setup dialog. In the Common Tab, set the Output resolution to 600x600 (the resolution of all our images in this section).
  2. Set the Renderer to Default Scanline Renderer.
  3. In the Renderer tab, turn off the Antialiasing and Filter maps options.
  4. Open the Environment dialog and assign the final map as an environment map.
  5. Render the scene:




 The final scene for the composite can be downloaded here. Your scene should be similar if you followed all the steps correctly.

The beauty of using this method is that it can properly composite all effects (reflections, shadows, GI, etc.), without having to worry about any complications with mattes, shadows, or 3ds Max.


Part 2: Rendering with VRaySphereFade

We will use the same workflow as defined in Part 1 above to render our entire animated sequence. However, we have to render our animation three times. With heavier scenes, this means a lot of rendering. All of the scene geometry is required for the correct calculation of GI effects, so we can't just remove geometry to speed up the process. 

Most of the effects that we are interested in (shadows, reflections, GI) appear near the animated object in the scene. Ideally we would like to render only those parts, and skip rerendering the entire image. 

This is where the VRaySphereFade atmospheric effect comes into play. It allows you to render only the part of the scene that is located near the animated object. The rest of the scene is shown as a solid grey color. However GI, reflections, shadows, etc. are still computed using the entire scene, so that they produce the correct effect.

Here is how we would use the VRaySphereFade plugin in the previous scene example. 


Set up the VRaySphereFade

  1. Open the starting teapot scene again, which can be downloaded from the tutorial assets section.
  2. Open the Environment dialog and add the VRaySphereFade atmosphere effect.
  3. Create a spherical gizmo object around the teapot. Typically, you will surround each animated object with a gizmo linked to that object:


  4. Click the Pick button in the VRaySphereFade parameters and then click the newly created gizmo.


Render the scene

  1. In the Render Setup window, go to Settings tab to access the V-Ray System rollout. Enable the Optimized atmos. evaluation option. This will speed up the rendering of the areas masked by the atmospheric.
  2. Render the scene:



You can see how only the parts of the scene inside the gizmo are visible to the camera. Note the grey color. Since we are computing our mask layer through division, it is not a good idea to have pure black colors in the "normal" image. 

Proceed as in the previous step to create the pure, black, and normal renders, and to composite them onto the background. The result is this:



Normal layer


Black layer


Pure layer




Object layer = Normal - Black


Mask layer = Black / Pure


Final composite over the background plate




The result is quite close to the result in the previous section, and it was a lot faster to calculate. Here are comparisons between the two composites that we got, as well as a rendering of the original scene with the teapot inside it:



Original rendering of the scene with the teapot


Full-scene compositing


Compositing with VRaySphereFade




Using the VRaySphereFade atmospheric, we can control how much an object will affect its surroundings. For GI effects, it is usually enough to limit the influence close to the object. However, some effects (like long shadows, or reflections on surfaces at grazing angles) might require larger spheres of influence. An alternative in that case would be to add more gizmos to capture those effects, or to render them in a separate pass and composite them separately.


Now we have all the necessary information to render our animation. This is summarized in four steps:

  1. Render the background as a walk-through animation, without the animated objects.
  2. Create and link gizmos to the animated objects, create a VRaySphereFade atmospheric and add those gizmos to the atmospheric.
  3. Render the animation with the moving objects normal, black, and hidden respectively into three separate animations.
  4. Composite the background animation out of the four other animations.


Set up the background scene

First, we need to render the background template which will serve as a basis on the moving characters. We will do this similarly to how it is described in the Walk-through animation tutorial. We will calculate the light cache first.

  1. Open the starting Sponza Atrium background scene, which can be downloaded from the Tutorial Assets.
  2. We have rendered all animations at a resolution of 900 x 500 pixels. This might take quite a while (it took more than two days to render the three character animations when preparing this tutorial), so you might want to use lower resolution such as 450 x 250. To do so, in the Common tab of the Render Setup dialog, set the rendering output resolution to 450 x 250 pixels.
  3. In the V-Ray tab, under the Global switches rollout, disable Default lights.
  4. In the Image Sampler (Antialiasing) rollout, set the Antialiasing to Adaptive DMC with the default settings of 1/4.


Set up the light cache calculation

  1. In the GI tab, in the Global Illumination rollout, turn on the Enable GI option and set the Primary engine and Secondary engine to Light cache.
  2. In the Light cache rollout, set Subdivs to 4000, Sample size to 4.0, and Scale to World.
  3. Switch the light cache Mode to Fly-through. For display purposes, enable the Show calc. phase option.
  4. Turn on Use for glossy rays and set Interp. samples to 5.


Render and save the light cache

  1. Go to the V-Ray tab. Enable the GI Environment group of the Environment rollout, and set the Multiplier to 2.0.
  2. Render any frame of the animation to calculate the light cache.
  3. Save the light cache. In the Light cache rollout, change the Mode to From file and select the light cache file you just saved.


Set up the irradiance map calculation

Once we have the light cache ready, we need to calculate the irradiance map.

  1. Change the Primary GI engine to Irradiance map. In the Irradiance map rollout, set the Current preset to High.
  2. In the Global DMC rollout in the V-Ray tab, set the Noise threshold to 0.002.
  3. Enable the Don't render final image option in the Global switches rollout.
  4. In the Irradiance map rollout, set the Mode to Multiframe incremental.


Render and save the irradiance map

  1. Render every 10th frame of the animation to calculate the irradiance map.
  2. Change the irradiance map Mode to From file and select the file you just saved.


Render the background sequence

We now have everything we need to render the full sequence of the background walk-through.

  1. Turn off the Don't render final image option in the Global switches rollout.
  2. Render every 1st frame of the final background animation with the saved GI solutions and save the animation as a 48bit .png sequence.




Now we have a ready background template that will be populated with the moving objects. The scene up to this point can be downloaded here.


Set up the character sphere gizmos

The next step is to use the sphere gizmos and the VRaySphereFade atmospheric to isolate the moving objects in the scene.

  1. Continue with the background scene and unhide the four biped characters in the scene.


  2.   Create four sphere gizmos with radius of about 80.


  3.  Align each of them to each Biped COM object (Bip01, Bip02, Bip03, Bip04).



Set up VRaySphereFade

  1. Open the Environment dialog and add the VRaySphereFade atmospheric.
  2. Add the four gizmos in the list.




The scene up to this point can be downloaded here.


Set up GI for the characters

For the rendering of the three animations, we will use Brute force GI as a primary GI engine to avoid flickering problems on and around the characters.

  1. Change the Primary GI engine to Brute force GI  with 25 subdivs.
  2. Change the light cache Subdivs to 3000.
  3. Change the light cache Mode to Single frame.


  4. Go to the System rollout and enable the Optimized atmos. evaluation option. This will accelerate the calculation considerably.


Render with the VRaySphereFade

  1. First, we will render the normal animation. Render the whole sequence to 48-bit .png files.

    Frame 145


    Frame 268


  2. Second, we will render the black animation. Apply a black VRayLightMtl material to the four biped characters and render the entire sequence to 48-bit .png files.

    Frame 145


    Frame 268


  3. Lastly, we will render the pure animation. Hide all the biped characters and render the whole sequence again.


Frame 145


Frame 268



Now we have all the necessary animations to composite the final animation.


In this part, we will composite the normal, black, and pure animations with the help of the VRayCompTex map.


Set up the compositing scene

  1. Open a new scene in 3ds Max and open the Material Editor.
  2. Load the normal, black, and pure animation sequences in three different slots and name them normal, black, and pure. Also, load the background animation that we rendered before.
  3. Change the display type of all four textures to Environment and set the Mapping type to Screen.

  4.  Make four VRayCompTex maps in four unused slots.


Create the compositing scheme

  1. Drag-drop the normal map into Source A, the black map into Source B, change Operator to Subtract in the first VRayCompTex map and name it object.
  2. Drag-drop the black map into  Source A , the pure map into Source B , change Operator to Divide in the second VRayCompTex map and name it mask.
  3. Drag-drop the mask map into Source A, the background map into Source B, change Operator to Multiply in the third VRayCompTex map and name it masked bg.
  4. Drag-drop the masked bg map into Source A, the object map into Source B, change Operator to Add in the fourth VRayCompTex map and name it final.

We have just followed the scheme that we described earlier in the Part 1: Compositing with 3ds Max section.



Render the final composite

  1. Drag-drop the final map into the Environment map slot of the Environment dialog of 3ds Max.
  2. Change the Renderer to Default Scanline Renderer.
  3. In the Renderer Tab of the Render Setup dialog, disable Antialiasing and  Filter Maps .
  4. Render the final animation.

The final compositing scene can be downloaded here.






Let us look at one frame of the animation:



You can notice that the character shadow for the metallic biped is cut off where its sphere gizmo ends. This is because we used somewhat smaller gizmos when we rendered the animation, in order to save render time. To make the full shadow visible, you can either enlarge the gizmo for that character, or use another gizmo near the ground, specifically for the purpose of capturing the shadow. If we have lights that cast long shadows, or the shadows are far away from the object that casts them, it might be better to render the shadows in a separate pass and composite them additionally. The same is true for reflections of the animated objects.



We did a lot of extra work to render out our animation: setting up gizmos, rendering four different animations, and compositing them. Why was this necessary and do we really have to go through all these troubles to render any animation?  

When compositing animation against live-action footage, there isn't much of a choice other than to use compositing. As a result, there is no way around rendering all the different passes.

However, when rendering a fully CG animation, the only thing that we save is render time, which is the single point of the whole exercise. Of course, with a larger render farm available, we could have simply rendered out each frame of the animation as is with high enough settings to obtain a stable GI solution from frame to frame. This would be the best and fastest thing to do if the scene environment is simple enough. However, if we don't have a render farm or the scene is quite detailed, then the method covered by this tutorial is the best choice. We can drastically reduce the render times by avoiding re-rendering of the entire scene's background if only one or two characters are animated in the scene.