Project NO. 3 : Unity Lightmapping tools (using Vray etc.)

21Jul09

Yesterday I’ve received an information that my proposal (+ video) which I sent for Unity Summer of Code contest was accepted and I’m really excited about the system development :)

Basically the system is automating the bake process for Unity powered games using a powerful rendering software VRay.

The Unity team proposed a bit different workflow and not all the original ideas will be implemented as the part of the system. It was rather clear that it would happen since the ideas I described were indeed invented rather quick for a game which I’m working on with my team (no further details now :P )

Nevertheless I’m very happy with the changes proposed by Unity team and those which came after the talk with my mentor Lucas Meijer. I think that it’ll all make the lightmapping process in Unity really simple and effective.

I didn’t setup my goals yet, since I want to be rather sure what exactly can be done in those 6 development weeks, but since many of you may be interested in the details I will often blog here information about the development progress and plans – starting from today. Feel free to submit here your ideas in a form of comment :)

Here’s the scratch of the workflow made by Joachim Ante:

From the end-users artwork we simply require:
* At import time per object unique uv’s are required (normalized to a range of 0 …  1)
[As a first step, we can just require the user to provide it, or we could automatically generate them later on]
The lightmapping process works in 5 steps:
1) Go through the scene and pack rectangle UV coordinates into a texture sheet
They can be stored in the renderer using lightmap tiling and offset: http://unity3d.com/support/documentation/ScriptReference/Renderer-lightmapTilingOffset.html
2) Create an FBX file from Unity scene. Export both the primary and secondary uv set with the packed UV coordinates.
This means that we “offset-scale pack”  the per object uv’s we have, into a new “baked uv sheet”. (FBX supports Ascii mode, so it’s quite easy to export)
3) Launch Max from inside Unity through the commandline batchmode interface, automatically open the exported FBX file and start the lightmapping process
4) Once the batchmode completes, Unity imports the textures and applies them to the renderers using the Lightmap Settings class and renderer.lightmapIndex.

From the end-users artwork we simply require:

* At import time per object unique uv’s are required (normalized to a range of 0 …  1)

[As a first step, we can just require the user to provide it, or we could automatically generate them later on]

The lightmapping process works in 4 steps:

  1. Go through the scene and pack rectangle UV coordinates into a texture sheet. They can be stored in the renderer using lightmap tiling and offset: http://unity3d.com/support/documentation/ScriptReference/Renderer-lightmapTilingOffset.html
  2. Create an FBX file from Unity scene. Export both the primary and secondary uv set with the packed UV coordinates. This means that we “offset-scale pack”  the per object uv’s we have, into a new “baked uv sheet”. (FBX supports Ascii mode, so it’s quite easy to export)
  3. Launch Max from inside Unity through the commandline batchmode interface, automatically open the exported FBX file and start the lightmapping process
  4. Once the batchmode completes, Unity imports the textures and applies them to the renderers using the Lightmap Settings class and renderer.lightmapIndex.

Here’s a short summary from the discussion with Lucas:

  • Our main goal is to “unchain” the baking process, so that one can modify the scene in Unity as much as he wants – and in every moment start the bake process (possibly several times during the work over the scene) before, the user were pretty much blocked to do changes in the imported model inside Unity
  • We’ll test the system with max and vray, but it should work with any fbx reading, lightmap creating program with some additional work
  • The user would have a choice (by selecting objects from list) which objects are meant to take part in the bake process. On the selection list will be placed combo boxes  beside each object, to make user choose a lightmap-enabled shader.
  • The scene is being exported into ascii-fbx file and then imported into 3dsmax. During the exporting process we set the 3rd channel uv using the existing (second?) channel uv which will be scalled and offseted. (We will demand an unwrap uv on second channel from the user for the beginning – later on it may be created automatically for him) [credits: Joachim Ante]
  • All the UV’s will be packed to a single or a few big texture sheets – a benefit in performance
  • We’ve got an idea to make vray materials assigning automatically according to the material name from unity – that would help the designer in preparing the scene to the baking process (when one doesn’t use any keywords in the material name in Unity then the default vrayMtl with a diffuse map (eventually in bump map – if it makes sense) will be assigned.
  • The light setup in 3dsmax is not yet outvoted – although we’ve got two conceptions:
    • The vray-lights are being created dynamically on the image of the lights created in Unity
    • We leave the light setup to the 3d artist so he can import a light rig to the scene and then bake
  • After the baking process is done the materials in Unity stay unchanged, but using the LightmapSettings class the appropriate parts of the lightmap texture are assigned to them (there are a few issues waiting to be resolved)

We’ve also considered some nice icings as for example forwarding 3dsmax communicates and render progress to Unity or a possibility to choose a custom renderer – Mental Ray for instance.

Here is a simple diagram of how the things will work inside

Vray-Unity tools diagram

About these ads


5 Responses to “Project NO. 3 : Unity Lightmapping tools (using Vray etc.)”

  1. Very interesting, Good luck with the summer code :)

  2. 2 Xin

    Hi. Thanks for the great tool. Just had a go with vray. And it’s only bakeing the GI pass(rawtotallighting pass). Which have no direct shadow in it. Is this a know issue? Can I chose what element to bake?

  3. Hi, indeed it’s using VRay_RawTotalLightingMap I’ve been experimenting a bit and it gave the best results – if you’ve got a another better proposition please write it here and I’ll consider it.

    Although you can change the way it’s going to be rendered using Vray. You just have to start a first ‘dummy’ bake (you can cancel it right after it starts) to prepare all your objects in Max’s RenderToTexture. Then you’ll be able to adjust it there and render by yourself (without ‘Bake now!’ button which is overwritting the rendering settings inside RTT)

  4. 4 Xin

    Hi, I have just realized that it’s not getting the direct shadows because I was using standard material. and yes you r right, VRay_RawTotalLightingMap is the better one to use.

  5. Sweet blog! I found it while browsing on Yahoo News. Do you
    have any suggestions on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get there! Thank you


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 35 other followers

%d bloggers like this: