Jul 18 2010

Setting up a simple pass dependency – baking occlusion, beauty in 3Delight

Hi there, after I did the posts about baking ambient occlusion and colour bleeding, I had several people asking me how to do it “automatically” so on the fly you bake occlusion and then read it back on the beauty pass without having to manually do both. It’s quite simple actually, you just need to setup a MEL script in the beauty pass that tells it that before rendering the beauty pass it first has to bake the occlusion, but before this we need to tell it what shaders to use in the ambient occlusion baking pass and in the beauty pass. In the end of this post you’ll have the link to the maya project I did myself with the scene file and shaders, so you can try it for yourself if you aren’t able to do it on your own.

1.- Create a pass from 3Delight > Add Render Pass > Default and call it bakeOCC. Create a new one and call it beauty. I gave them these names, you can give the names you want, just keep in mind this tutorial revolves around these names.

bakeOCC – In this pass you can use very low pixel samples, 1 or so, because we don’t need quality in the render, we just need the point cloud baked. The shading rate though, affects the density of the point cloud. The lower the shading rate the more dense the point cloud. A value of 1 should be ok. Also, in the bakeOCC pass I set the display driver to null. I don’t need to see it, I just want the point cloud created. In the Output section of the pass, leave the Render Mode to Render, otherwise the bakeOCC pass won’t be calculated before the beauty pass.

Beauty – In the beauty pass of course, you want to have the maximum quality, so 8 pixel samples and shading rate 1 should be ok, depending on your needs. In the Displays section, use what you need. If you just want to have the render appear on i-display, select idisplay, if you want the render to be saved on a file, select the display desired. In the MEL Scripts section, in the Pre Frame MEL add this command:

delightRenderMenuItemCommand bakeOCC;

This is gonna be the command that tells 3Delight that before starting the beauty pass, it should first do the bakeOCC pass. For this pass, in the Render Mode I used Background Render so you can continue using Maya while it renders. Make sure you don’t use this option in the bakeOCC pass otherwise it will start beauty at the same time as bakeOCC.

2.- Compile and import the shaders attached below. I have two shaders. One of them writes the occlusion to a point cloud, and the other one is a normal plastic shader also capable of reading back the occlusion, just for the sake of this tutorial. You can use yours if you’d like. If you want to take a look to see the parameters I used in my scene, please download it and open it.

3.- Create a Geometry Attributes Node from the 3Delight Relationship Editor. Add a visibility attribute and make it visible to diffuse rays(for the occlusion). Also, add a Culling and Dicing attribute and turn off Cull Hidden Surfaces, Cull Backfacing Surfaces and Raster Oriented Dicing.

4.- Now create a shader collection from the menu 3Delight > Assignment Panel. Click the checker box and give it a name like bakeOCC_sc. We want this to override the shader assignments for the bakeOCC pass. We could also create a beauty_sc to add in the beauty pass, but if you go to the 3Delight Relationship Editor and add a shader to an object, that will be its “permanent” shader. I used this way, I assigned the beauty shader, the plastic shader that reads occlusion, from the 3Delight Relationship Editor. Now select all the objects in your scene, open the 3Delight > Assignment Panel and with the objects selected, in the Override shaders section, click the arrow next to the Surface override and select the ptc_write shader that you should’ve imported earlier. Do the same for the Attribs override, selecting the Geometry Attributes Node created earlier.

5.- Go back to the bakeOCC pass and in the Render Sets section, in the Shader Collection select bakeOCC_sc. This will tell this pass to use the occlusion shader and the geo attributes to compute the occlusion.

6.- Open the 3Delight Relationship Editor and add the plastic shader I attached to the objects you need. I duplicated this shader several times to have some colour variance in the objects. Assign as you like. This will make the plastic shader, the “permanent” shader for these objects, that will be overridden in the bakeOCC pass by the bakeOCC_sc shader collection. When defining the path to create or read the point cloud in the shaders I always use the # sign as in PATH/point_cloud.#.ptc This way it will create the point cloud for the current frame.

That’s it, if you hit render, you should see the point cloud file being created in the path you choose, and then the beauty being rendered only after baking the occlusion. My scene is for Maya 2010. Take a look if you want to see how I did it.

Rendering from the command line:

As a last note, you can render a sequence, or a frame, from the command line without having to open maya when you have the scene ready. Like this:

render -r 3delight -rp -an 1 -s “start_frame”  -e “end_frame” “path_to_scene_file”

we actually have to use the maya render command because if we use the command from the standalone 3delight(renderdl), it will be expecting a rib file and won’t respect the structure we setup in maya. But using 3delight in the render engine flag(-r) will tell maya to use 3delight to render. The -an flag toggles the rendering of the specified frame sequence on or off.

An example would be:

render -r 3delight -rp beauty -an 1 -s 1 -e 100 PATH_TO_YOUR_FILE

Files do download:

Maya Scene and Shaders

I hope this helps, and let me know in the comments section if you have any problems. To get more info on how to setup baking occlusion read my post on this blog about that subject.

4 Responses to “Setting up a simple pass dependency – baking occlusion, beauty in 3Delight”

  • DBailey Says:

    Nice explanation. I use VRay in Maya because I love the quality of GI, glossy reflections, soft shadow, etc.

    I would like to use 3Delight more and seek to match the quality from VRay in renderman.

    Thanks for your posts, they are very helpful!

    Check out my matchmove and vray rendering pipeline.


  • Jua Says:

    That’s great jorge. Thank you for very useful tutorials.

    I try chaining render on sequence animation and it’s work great.

    But, it seem to be some bug when I applied motion blur.
    My output ptc and image files was float frame number instead of integer.

    Did anyone had an idea ??

    ps. sorry for my bad english.

  • DRL Says:

    Thank you man! You’re awesome!
    I’m just migrating from RFM to 3Delight and was wondering of how I can use point-cloud calculations in my custom shaders.
    I know it now, thanks to you… and google, which helped me to find this post. 🙂

Leave a Reply