Saturday, March 28, 2015

bake/unwrap shader with lighting

Somebody asked me how to unwrap the rendered result of a shaderfx shader to a texture. This may seem like a strange request, because why would you want to bake your lighting into your texture?

 But I have actually had to do this myself once when porting a xbox 360 game over to low-end mobile devices. We were a very small team and could not redo all assets and we really only wanted a single texture per asset.

So, here is how to do the shaderfx part of it. Lets say we want to unwrap a rendered texture for this horse model:


What we need to do is go into Advanced mode, then enter into the "Material grp". Add a new "Vertex Shader UV space" group node. Replace ALL (!) the output of the existing Vertex Shader grp with this new node.

 It will then unwrap the 3d model in your 3d view. From here, you could use other tools to grab the view result and save it as an image.

Important:
If you want to save this file with the model unwrapped in the screen, you have to save a NEW grp for the Material grp you just changed. Otherwise, your changes won't stick after re-opening the file.
You can save the grp by renaming its Class property to something unique and then using "Save Grp".

(One tip might be to make the Maya viewport black before saving the image, or if you need to create a mask, make it bright purple so it is easy to select the background color in something like Photoshop)