How to use matte shading with Krakatoa.
In most cases, your particle systems do not stand alone. You will need to combine them with other plates or rendered elements. The following exercises will introduce you to Krakatoa features for handling matte objects, shadow-casting lights, and particle shadows on geometry.
Occluding Particles In the View
- To demonstrate the use of Matte Objects, create a sphere with Radius 10 in your scene and position it such that it obscures your camera’s view of the particle system.
- In the bottom of the Krakatoa GUI, check the >Matte Objects checkbutton to enable the rendering of Matte Objects.
- To quickly scroll down to the Matte Objects rollout, simply right-click the same checkbutton - the Main Controls rollout will collapse and the Matte Objects rollout will expand!
- Select your new sphere object in the viewport and click the Create/Update Matte Selection Set button
- This will create a Named Selection Set named "KrakatoaMatteObjects" in your scene and will add it to the right list box. Krakatoa will use all geometry objects in the Named Selection Sets listed in the right list as matte objects occluding the particles behind them and, under certain conditions, blocking light and thus casting shadows onto the particles.
- Check >Iterative [Full] and click the RENDER FRAME button to render an image.
Observe that the particles behind the sphere are no longer visible.
Casting Shadows On Particles
- Select and move the Sphere to the right so that it occludes the light from the Spotlight, thus potentially casting shadows onto the particles.
- Select the Spotlight and in the Modify Panel, turn Shadows on.
- Make sure the Shadow type is set to Shadow Maps (Krakatoa uses the Shadow Map Size value to define the size of its Attenuation maps, if no such parameter is found, a default size of 512 will be used).
- Press RENDER FRAME again.
Observe that the sphere is now casting a shadow into the particles. In the Rendered Frame Window, toggle between RGB and Alpha channels to see where particles are obscured by your matte object versus where they are simply in the shadow of the matte object.
Note on shadow quality:
Several factors will affect the quality of your shadows. If you begin to see moiré patterns,
you may need some combination of increasing the shadow map size, increasing the number of particles,
and decreasing the particle density.
Intersecting Particles and Matte Objects
In the first example of occlusion above, rendering the Matte Object would not make much sense unless it was casting shadows on the particles - since all particles were behind the Matte Object, one could have just composited the rendering of the Matte Object from another renderer on top of the particles. But Matte Objects are especially useful when the particles interact directly with them - some particles are in front of the Matte Object, while others are behind, like in the following example:
- Assign a Standard material to the Sphere, set diffuse color to red and self-illumination to 10.0.
- Change the Radius of the Sphere to 20 and move it in the middle of the particle cloud:
Since shadows are also on in the Spotlight, the Sphere now both occludes particles and cast shadows on those behind it:
- Save this image to disk including the Alpha channel.
- Switch to Scanline Renderer - use the Switch Back From Krakatoa To Previous Renderer icon provided by the Krakatoa MacroScript. This will save the current Krakatoa settings as an RPS render preset which can be restored easily later.
- Save this image to disk too.
- Open Renderer > Video Post or use a 3rd party compositor like Combustion, Fusion, Nuke, After Effects etc.
- Load both saved images and composite the particle rendering on top of the scanline rendering:
Opacity-Mapped Matte Objects
Krakatoa v1.5.0 intruduced the ability to respect Opacity Maps of the Matte Objects when occluding particles and/or casting shadows.
- Open Material Editor
- In the default Standard Material of the Sphere, assign a Checker map to the Opacity Map slot.
- Set the U Tiling to 4 and V Tiling to 2.
- Compositing the Krakatoa and Scanline Rendering produces the following image:
You will probably notice that the edges of the Sphere are rather jagged. This is caused by the Krakatoa Matte Alpha which does not contain Anti-Aliasing info to smooth the edges - a particle that is partially occluded by the sphere is considered either completely visible or completely invisible because the pixel of the Matte image is either fully white or fully black.
We can increase the sampling of the Matte Objects in Krakatoa to fix this.
- Go to the Matte Objects rollout in the Krakatoa GUI and increase the Sub-Divisions spinner from 1 to 3.
- Render the Krakatoa pass once again
- Run the Video Post once again to produce the following result:
With matte objects and shadow-casting lights, you have created a layer that is easy to integrate into a final composite.
In the next exercise, we will show how your particles can cast shadows on rendered scene geometry.
Shadows on Geometry
Your final composites will likely contain other geometric objects to be integrated with your particle system. To assist in casting shadows on geometry rendered with other 3ds Max renderers, Krakatoa can store attenuation maps for each shadow-casting light. In turn, these maps can be assigned to the projection slots of your lights to project shadows onto your scene objects. Krakatoa also provides shortcuts for assigning maps and switching renderers.
To create and save Attenuation Maps
- Right-click the RENDER button and make sure Save Render Output and Set Render Output Filename are both checked. If they are not, select Set Render Output Filename and pick the location and the name of the image files to save.
- In the same Right-click menu, select the item Save Attenuation Maps - if checked, a sub-folder called \Shadows will be automatically generated when rendering the output images and an attenuation map containing the name of the light object it was generated from will be saved in EXR format for each frame.
Alternatively, you can expand the Shadows On Geometry rollout in the Krakatoa GUI and check the >Save Attenuation Maps When Rendering option. The right-click menu is a shortcut to the same option.
- Render the scene as usual - when finished, right-click the RENDER button again and select the Explore Render Path option - a Windows Explorer will be opened to reveal the render output location.
- The folder should contain a sub-folder called \Shadows - check to see that there is an attenuation map saved for each light and frame rendered.
- Now either press the Open Krakatoa Shadows Utility button in the Shadows On Geometry rollout, or, if you have installed the Krakatoa MacroScripts in the 3ds Max GUI, locate the KrakatoaShadows button and press it to open the utility.
- The utility is a MAXScript dialog which will help you apply the shadow information to your lights.
- It will take the current render output path and attempt to resolve the location of the \Shadows folder automatically. If the folder could not be resolved (for example because the Render Output Path has been removed or changed after the rendering has finished), press the Select Shadows Data Location button and pick the folder containing the attenuation maps by selecting a representative attenuation map. The File Prefix will be the portion of the file name from the beginning to the first underscore character. The file prefix can be used to distinguish between multiple rendering sessions stored within the same folder. For example, if you rendered to the image file name "myFirstTest_0000.exr", the attenuation maps would be called like "myFirstTest_Omni01_0000.exr", "myFirstTest_Spot01_0000.exr" and so on. If you decided to change the name of the output image to, say, "secondTest_0000.exr", then the shadows will also use the new prefix. Thus, picking a file with the desired prefix will ensure you are using the correct sequence of attenuation maps.
- Next, press the large ADD KRAKATOA SHADOWS TO THE SCENE button - the utility will scan the scene for lights, match them with the attenuation maps in the \shadows folder and assign the Projector maps as necessary. Existing projector map will be preserved and MULTIPLIED with the Attenuation map. Using the REMOVE Krakatoa Shadows From The Scene later will remove the Krakatoa attenuation maps and any RGB Multiply maps and restore the projector maps as they were before the application of the shadows.
- Finally, you want to switch the renderer from Krakatoa back to Scanline, mental ray, VRay, Brazil etc. to perform the actual rendering of scene geometry with Krakatoa shadows projected by the lights. You can either select any of the existing renderer classes displayed in the first drop-down list, or pick a previously generated render preset.
Once you are done rendering, you can revert back to Krakatoa by pressing the RESTORE Krakatoa Renderer button at the bottom of the dialog.
You should be able to combine the Krakatoa particle rendering pass with the main pass rendered in another renderer in Video Post or any compositing application.