Wednesday, July 3, 2013

3Delight for Maya | Bake texture - english


In order to 'bake' occlusion or diffuse environment data to a texture, we just have to connect these values through a "dummy" node where "bake()" is executed and the best way to do it is using a renderman code node...





Firstly, the scene here is very simple (you can download it here). The rendermanCode node will help us to specify a path for the texture we are going to write. In hypershade, create a rendermanCode node  (Create > General Utilities > Renderman Code).

Add this in shading parameters:

varying color i_color
uniform string shape
uniform float enable

output varying color o_color

And this in shading code:


extern float s;
extern float t;

o_color = i_color;
if (enable == 1)
 bake( concat(shape,"&binary"), s, t, i_color );

In the shape field,we will add the path for the file to be written. Enable will just enable or disable the node.

occlusion can be computed using a mental ray node (mental ray textures -> mib_amb_occlusion). Set samples to 64 or 128 and connect mib_amb_occlusion1.outValue to renderman code (i_color) input:





renderman code is connected to the color slot of the material assigned to the polyPlane (lambert2.color in this case). What we are doing here is visualize the occlusion result and pass it to bake(), so you can connect this rendermanCode node anywhere in lambert (ambient, diffuse, etc). Don't forget to enable bake (Enable = 1)


Once rendered, we will get a binary file in the specified path in rendemanCode node 'shape'. To use this file, we have to create a texture, so open up a terminal or command line and use tdlmake:



tdlmake -progress -bakeres 2048 -preview 1 -byte your_BAKE_file.bake   your_TIF_file.tif


-bakeres is the resulting texture's resolution
-byte will make that texture 8 bit (if omitted, will be a 32 bit texture).

Documentation for tdlmake can be read here.





Resulting tif file looks like this:






You can spot some artifacts there. That's because texture won't be calculated in areas the camera can't see (3delight as REYES renderer). So, in maya, select the polyPlane and attach a delightGeoAttribs node (3Delight > assignment panel > click the checker right next to Attribs). Right click over Add/Remove Attributes and select Cull Hidden Surfaces and Cull Backfacing Surfaces. Disable those options when added:






Render again and process the texture again using tdlmake:



If you load the resulting texture file using a file node in maya and using it as color you'll get:





For this to work, your objects must have properly laid UVs (non overlapping). Don't forget to disable the baking node if you're not going to use it!.

Final scene can be found here.

2 comments:

Anonymous said...

When you use the mental ray ambient occlusion node, I hope it doesn't use mental ray in the baking process, since we wan't only 3Delight to bake.

Unknown said...

Yup. mental ray wouldn't understand 3delight's nodes anyway.

And I'm surprised how this hasn't improved over the years, on the 3delight side.