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.

May 27 2010


Hi Everyone. I want to apologize for not having replied to your comments in the past months. I literally received thousands and thousands of spam comments, and its virtually impossible not to miss the proper ones. I just installed a new plug-in in my blog that they claim that gets rid of all the spam. I will try to reply to you guys as soon as I have time. Meanwhile I am also preparing some new posts regarding Shader Writing, so stay tuned.

For the few ones that follow this blog, thank you for your patience.


Sep 9 2009

Point-based Indirect Diffuse/Colour Bleeding

If you read my previous post about baking occlusion, you’ll be very comfortable about this subject.

Much like baking occlusion into a point cloud, baking indirect diffuse also involves two steps. First we need to actually bake it into a point cloud, and then we need to read it back from the same point cloud.

First step:

Instead of having to add a surface shader that computes indirect diffuse to every object, in this approach we are going to use a light shader that computes that for us. This way we can leave our surface shaders, etc, untouched and only using a simple light with this shader I wrote. Just create an ambient light and apply the shader to it. You can also specify the number of samples in the shader, and the intensity of the indirect diffuse being calculated.
To bake it, we need to make sure to turn off the culling operations to be sure that the backfacing and hidden faces are taken into account by the renderer when creating the indirect diffuse pass(second step of this approach), and we also need to use a dicing method that is independent from the camera view:

Attribute “cull” “hidden” [0]
Attribute “cull” “backfacing [0]
Attribute “dice” “rasterorient” [0]

Again, we can use low pixel samples because we are not interested in the quality of the render, we only want to create the point cloud at this stage, thus its creation being faster:

PixelSamples 1 1

If we want a very dense point cloud, then we need to use a low shading rate. 0.5 should be enough. Just play around a bit to get this value right.

Second step:

In this step we only have to read back the information stored in the point cloud. To do this we use this shader I wrote in the same light, which is specific to read the data stored in the point cloud we created in the step before.
You can increase the pixel samples, lower the shading rate if needed and turn the culling and dicing back on.


To render these images, I used 3Delight. The shaders that work with PRman are here. I haven’t tested them but they should work.

Let me know what you guys think,


Apr 9 2009

Where The Wild Things Are

Hello. I’ve been a bit busy at work and doing some Shader Writing, but just wanted to post the trailer for the movie I am working on at the moment, “Where The Wild Things Are”. I am Lighting the Characters. Take a look here at the apple website.

Where The Wild Things Are

Mar 7 2009

Point-Based Ambient Occlusion

Hello, this is my first post and I’m going to talk about ambient occlusion, also known as geometric exposure, with Renderman. The approach I’m going to describe is called Point-Based Ambient Occlusion and uses a point cloud to compute the occlusion. If you read my “About” you know I use 3Delight to do my personal research and tests.

This approach is done in two passes. In the first pass we need to convert the scene’s geometry to a point cloud, and in the second pass the point cloud is used to compute the occlusion effect.

Why using this?

Well, it’s much faster than ray-traced occlusion, doesn’t produce any noise, uses less memory, and displacements that usually are a very costly operation when using ray-tracing, don’t have any additional cost when using the point-based approach.

There are also disadvantages. For example, as it is a two-pass approach, it can become a bit daunting when setting up its pipeline. Also, it is not numerically accurate as the ray-tracing approach, but we are not aiming to have numerically accurate results, but instead, having visually accurate approach. In other words we want it to look as good as the ray-tracing approach, and if it takes less time and resources, we’ve achieved our goal.

Now, the steps.

First we need to create a point cloud. This pass is very simple. We only need to use a shader that will convert the geometry into a point cloud. This shader will use the bake3d shadeop to convert each micropolygon to a point, thus creating the point cloud. I use a shader that comes with 3Delight, it is in the $DELIGHT/examples/ptc_occlusion/ folder and is called ptc_write.

In order to get this right, we must do some things first. We need to make sure to turn off the culling operations to make sure that the backfacing and hidden faces are taken into account by the renderer when creating the occlusion pass(second pass of this approach). We also need to use a dicing method that is independent from the camera view:

Attribute “cull” “hidden” [0]
Attribute “cull” “backfacing [0]
Attribute “dice” “rasterorient” [0]

As in this pass we only care about creating the point cloud, and not having a high quality result, we can use low Pixel Samples:

PixelSamples 1 1

This way the creation of the point cloud will be faster. However, if we are aiming to have a very dense point cloud we should lower the Shading Rate. A value of 0.5 should be enough to have a very dense point cloud, but the point cloud creation will be slower.

Now, to the occlusion creation:

Here we use a shader that reads back the point cloud file to compute the occlusion. It can get a bit tricky to get good and fast results. Regarding the occlusion shadeop used in this shader, my experience, and hearing opinions from others, is that we need to have a good balance between the bias and the max solid angle. A bias value of 0.1 should be enough. As for the max solid angle if we use higher values, the rendering time will be faster but the quality decreases and vice-versa. So a good range is 0.01 to 0.5.

We should also set “hitsides” to “both” so that each side of the point cloud’s samples will produce occlusion.

Usually we’ll also want to set “clamp” to 1, as this creates results similar to the ray-tracing approach, but at the cost of speed.

The shader that comes with 3Delight that reads the point cloud to create the occlusion, is very simple, so I made some modifications in order for me to able to control the parameters of the occlusion shadeop. You can get it here if you’d like.

Finally we need to set the quality of the render, such as Pixel Samples, etc, as we want.

When you render it, you’ll notice it is much faster than the ray-tracing approach. Here you can see two renders I did with the purpose of showing you the render times. Higher Resolution image is here. The Ray-Tracing approach took me 13 minutes and the Point-Based only 4 minutes and 40 seconds. Less than half time.


I hope you find this useful, and please, leave me a comment if you think I did something wrong or if you have something to add.