Baking is a popular ‘technique’ to flat down your shading work into easy to use images (textures) that can be applied to your 3d models without any concerns with lighting calculation. This can help game development, online visualization, 3d printing, archiviz animations, and many other fields.

bake-koro

Koro, from Caminandes project, fully baked

Since last September I’ve been working part time for the Blender Foundation to help implementing game related features in Blender. So far I worked on bug fixes and a few nice features such as: improvements in the Triangulation Modifier, Photoshop PSD support and Walk Navigation System. Then comes December, and with it the possibility of tackling something new. We decided it was time to give baking a go.

Supported Maps

The Cycles renderer is based on physics based lighting calculations. That means the passes we can bake in Cycles are different than what you may be used to in the Blender Internal renderer.

Data Passes

  • Normal
  • UV
  • Diffuse/Glossy/Transmission/Subsurface/Emit Color

Light Passes

  • AO
  • Combined
  • Shadow
  • Diffuse/Glossy/Transmission/Subsurface/Emit Direct/Indirect

koro_AO

Koro Ambient Occlusion Bake Map

koro_COMBINED

Koro Combined Bake Map

The above maps illustrates Ambient Occlusion and Combined baking. Ambient Occlusion can be used to lit the game scene, while combined emulates what you get out of a full render of your object, which can be used in shadless engines.

The character baked here is Koro from the Caminandes project. Koro was gently made available as CC-by, so while I take no credits on the making of it, I did enjoy supporting their project and using Koro in my tests. Koro and all the other production files from Caminandes Gran Dillama are part of the uber cool USB customized card  you can buy to learn the nitty-gritty of their production, and to help supporting the project and the Blender Foundation.

Open Shading Language

Open Shading Language (OSL) is a shading language created and maintained by Sony Image Works and used by them in many blockbusters already (Amazing Spider Man, MIB III, Smurfs 2, …). It’s a great contribution from Sony to the industry, given that it was released in a permissive license, free to be implemented, and expanded by any interested party.

Blender was the first 3d package outside of Sony to officially support OSL, and since November 2012 we can use OSL in a “Script Node” to create custom shaders. Blender uses OSL via Cycles. The “Script Node” was implemented by Brecht, Lukas, Thomas and … me (:

Thus, with baking support in Cycles we get for “free” a way to store the shaders designed with it. In the following example you see the Node Cell Noise sample script from OpenShading.com. So even if your game engine has never heard of OSL, you can still benefit from it to make your textures and materials look more robust. How cool is that?

Open Shading Language Baking

Open Shading Language Baking

I Want to Try It

There are no official builds of this feature yet. However if you are familiar with git and building Blender, you can get it from my github repository. Clone the bake-cycles branch from the blender-git repository. Once you build you need to UV Unwrap the object you want to bake, select it and run the following script:

import bpy
bpy.ops.object.bake(type='COMBINED', is_save_external=True, filepath="/tmp/baked.png", width=512, height=512)

If you can’t build your own Blender get a build on GraphicAll.org. You can also follow my Blender Foundation Weekly Report to learn about the progress of this feature and to be informed on when the work will be ready and merged upstream in the official Blender repository.

Missing Bits

There is still more work ahead of this project. Cycles Baking is actually a small part of a big planned baking refactor in Blender, which includes Baking Maps and Cage support. We only decided for Cycles baking to be a start point because the idea was to use Cycles to validate the proposed refactor of the internal baking API.

That means Cycles Baking may or may not hit Blender on its own any soon. There are bugs to be fixed, loose ends to be tied, so it’s not that I’m spending time anxiously wondering about when this will land anyways (;

I would like to take the opportunity to thank Brecht van Lommel for all the help along this project, and the Blender Foundation for the work opportunity. I’m glad to be involved in a high impact project such as the Blender development.

Last but not least. If you work professionally with Blender and can benefit from features like this, consider donating to the Blender Foundation via the Development Fund page.

Best regards,
Dalai Felinto

32 Thoughts on “Cycles Baking – Development Teaser

  1. Wow Dalai, this really is great news and a step into the right direction. My fingers are crossed that this generates enough interest that we’ll see it in 2.71.

    Thanks for encouraging others to donate to the Development Fund, I’ve been giving for the past half year or more and am thrilled at what you guys are delivering, if only we could get another 100 people giving a few dollars/euros a month.

  2. Is it far enough along to bake box-texture mapping?

  3. Hi
    Its great news ! Thanks a lot for Your/Yours work. BTW can cycles in future rendering height, cavity maps too?
    Greetings

  4. Oh right, that was very unclear. There is a texture mapping feature that allows us to “box-map” a texture to a model without applying the texture to the UV Coords, yet it’s seamless and without distortion. Here is the setup http://www.pasteall.org/pic/show.php?id=66469

    This could not be easier, it took five minutes to find the picture and then apply it. Now if this could be baked…

  5. >Baking Maps
    What about Bake Node?

    • What would you want a Bake Node for? Baking Maps is a way to pre-setup your scene so you can do batch baking (and re-baking) of several objects at once.

  6. Forget all that. I had assumed that because your instructions were super short that you must have left out a bunch of steps.

    It’s actually that you made it so simple and straight forward that what you wrote is all you need. Thanks, it works.

  7. Dalai, thank you for implementing this feature! I hope that it will be merged into trunk eventually.

  8. I assume that clearing up the seams will be next, or did I miss something..

    For the GLSL texture baker that I built, I was planning on passing the FBO capture of the baked texture through several passes of various blur algorithms and then stacking them together with the original at the top.

    I’m not sure that it will work perfectly, but if it does then dealing with margin overdraw becomes trivial.

    By the way thanks, I’ve been looking forward to this for a year. So have many other people.

  9. lolko7 on February 8, 2014 at 4:33 pm said:

    Great news ! Thanks for Your work. BTW Is cycles will have a height, cavity maps ?

  10. Using the graphicall build 6c144bc for windows x64, when I unwrap the cube and run the script I get the following error:

    Traceback (most recent call last):
    File “”, line 1, in
    File “C:UsersDesktopBake_Cycles_Win7.x64-6c144bc2.69scriptsmodulesbpyops.py”, line 188, in __call__
    ret = op_call(self.idname_py(), None, kw)
    RuntimeError: Error: Problem baking object map

    Am I doing something wrong or is that build problematic?

    Anyway, using a second winx64 build, after complaining that it couldn’t save on “/tmp/bake.png”, I changed the save address to a random folder and now the error changed:

    File “”, line 1
    SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-4: truncated UXXXXXXXX escape

    • The problem seems to be the filepath you are using. In windows there is no /tmp/.
      Try: bpy.ops.object.bake(type=’COMBINED’, is_save_external=True, filepath=”C:\baked.png”)
      (note, the \ is intentional, since Python interprets as special chars)

  11. Hello Dalai,

    This cycles baking looks very promising! I noticed in the description above that under light passes a separate shadow map can be created. In other words, it seems possible to catch only the shadows. This raises a question. Do you think it is possible to use the same technique to create a ‘shadow catcher’ shader node and catch the shadow in real time (without baking)?

    Keep up the good work!

    Best regards,
    Steven

    • Hi Steven, well not only is possible but I believe you can already have it as a separate pass for compositing. In fact a lot of the code I wrote for the baking is based on the existent compositing passes.

  12. mani pastorelli on February 16, 2014 at 7:00 pm said:

    Hey I love the the fact this is finally compiling, I keep getting a script error though when I try this, however a huge thumbs up for the work going into this feature, I have been waiting on this a long time now.

    • mani pastorelli on February 18, 2014 at 6:00 pm said:

      Wow I managed to fix the script error by checking out the repository again and running the compile a second time. Not sure if I did it wrong the first time or I just caught something broken which was later fixed. Anyway WOW the results of this are amazing. I was thrown at first because every time I had something linked to displacement on the output material node it rendered black. By changing that to use normal maps I got stunning results. AMAZING work I can’t wait to see this a a full working part of blender in the future.

  13. James Sky on March 4, 2014 at 4:39 am said:

    Does anyone know what’s happening? I downloaded the Cycle Baking 2.69 file, my object is unwrapped, I’ve selected my desktop as a file path, yet this happens!

    Traceback (most recent call last):
    File “/Users/christopher/Library/Application Support/Blender/2.69/scripts/addons/io_scene_valvesource/__init__.py”, line 105, in scene_load_post
    game_path_changed(s,bpy.context)
    File “/Users/christopher/Library/Application Support/Blender/2.69/scripts/addons/io_scene_valvesource/__init__.py”, line 139, in game_path_changed
    p_cache.gamepath_valid = os.path.exists(os.path.join(getGamePath(),”gameinfo.txt”))
    File “/Users/christopher/Desktop/Blender/Misc/Test Builds/Blender 2.70/blender.app/Contents/MacOS/2.69/python/lib/python3.3/posixpath.py”, line 83, in join
    path += b
    TypeError: unsupported operand type(s) for +=: ‘NoneType’ and ‘str’
    Traceback (most recent call last):
    File “/Users/christopher/Library/Application Support/Blender/2.69/scripts/addons/io_scene_valvesource/__init__.py”, line 105, in scene_load_post
    game_path_changed(s,bpy.context)
    File “/Users/christopher/Library/Application Support/Blender/2.69/scripts/addons/io_scene_valvesource/__init__.py”, line 139, in game_path_changed
    p_cache.gamepath_valid = os.path.exists(os.path.join(getGamePath(),”gameinfo.txt”))
    File “/Users/christopher/Desktop/Blender/Misc/Test Builds/Blender 2.70/blender.app/Contents/MacOS/2.69/python/lib/python3.3/posixpath.py”, line 83, in join
    path += b
    TypeError: unsupported operand type(s) for +=: ‘NoneType’ and ‘str’
    Traceback (most recent call last):
    File “”, line 1, in
    File “/Users/christopher/Desktop/Blender/Misc/Test Builds/Blender 2.70/blender.app/Contents/MacOS/2.69/scripts/modules/bpy/ops.py”, line 188, in __call__
    ret = op_call(self.idname_py(), None, kw)
    AttributeError: Calling operator “bpy.ops.object.bake” error, could not be found

    • admin on March 20, 2014 at 2:34 am said:

      First the “valve” issue you have is not related to this project/branch/patch.
      Second, try to download an updated build in graphicall with support for Cycles Baking to access the functionality via the UI (no more need to fiddle with Python scripts).

  14. Judas Shuffle on March 4, 2014 at 12:08 pm said:

    Really impressive as a second life user this could be invaluable , thanks

  15. Great work! I’ve been looking forward to Cycles baking for ages, especially tied with OSL!

    I’m wondering, could this be a part of Cycles standalone or is it tied to Blender only? This would be great as an external program that could be executed directly from a game engine editor for example, or another DCC package like xNormal can be somewhat tweaked to do.

    Kind regards

    • admin on March 20, 2014 at 2:32 am said:

      Hm good question. It’s more the other way around where Blender is doing a lot of the heavy-lifting while Cycles is being called to do a part of the job. To implement it all in Cycles Stand Alone would mean duplicate a lot of the Blender code inside Cycles.

      On the other hand, the way it’s implemented, other external engines can easily implement baking integrated with Blender.

  16. Gregory on March 25, 2014 at 4:55 am said:

    You project very important. The idea the best.But Graphicall not give me you build(for Ubuntu).
    And … I want quickly adding you project to the official branch of Blender!!!
    Hi Ton, it is MUST exist into Blender!!!!!!!!

    • admin on March 30, 2014 at 7:53 pm said:

      Hi Gregory, I’m not maintaining the builds in Graphicall, but I’m assure we are doing the best we can to land this in ‘master’ sooner than later. It should be committed for BLender 2.71.

  17. Hi!
    I’ve downloaded your Baking Cycles for Mac from GraphicAll.
    I make a Smart UV Project and when I try to create a new image in UV/Image Editor, for the bake, blender just crashes, all the time.

    Thank you,
    Inês

  18. mani pastorelli on March 31, 2014 at 6:16 pm said:

    Is it my imagination of is baking using cycles currently not taking account the attribute node?

  19. Frits Lyneborg on December 20, 2014 at 10:27 pm said:

    Hi dfelinto,

    Sorry for bumping this old tread, I’m searching like a mad man and all traces point to you 🙂

    I merely want to end up with 6 images that when applied to the inside of a cube (Skybox in Unity) and seen from 0.0.0 in any direction creates the illusion of a sphere that matches the Blender scene.

    Now, I carefully avoided naming any Blender (Cycles) lingo in my description, because what I’m asking is: What would you use in Cycles to do this?

    It appears to me that everything is there (Blender Version 2.72 when writing this) – but I just cannot get things set up to do that render+manual cutting/those renders.

    Thanks a bunch!

    • dfelinto on January 5, 2015 at 3:40 pm said:

      Hi,
      Happy holidays 🙂

      Cycles gives you two options for that:
      (1) to render out an Equirectangular Panorama (change camera lens to Panorama and change the lens mode to Equirectangular), and to convert it to cubemap externally (or to convert from within Blender, but that’s requires some extra skills).

      (2) to use the new Cycles bake to bake the Environment to an UV-Unwrapped cube.

      (3) … in the future we may have a straight render to cubemap from Cycles, but it’s just not there yet.

      I hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation