Search Unity

Texture baker - bake and extract specular, tint, AO, etc

Discussion in 'Works In Progress - Archive' started by Ippokratis, Oct 25, 2014.

  1. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Hi,
    I am starting developing a new tool - Texture baker

    What it does ?

    -Specular Bake-
    To use a texture in the specular family of shaders you have to add the specular map in the alpha channel of the diffuse map.
    Say you have a diffuse map and a specular map. Simply add the maps in their slots and hit a button - ready.

    -Specular Extract-
    You have some textures that have specular baked in their alpha channel and you want to tweak them.
    Add the texture to the slot and hit the button.

    -AO Bake-
    Put the diffuse map and the ambient occlusion map in their slots, hit button -> a diffuse map with baked AO.

    -Tint Bake-
    Tint a texture by a color.

    If you have some ideas - suggestions let me know.
    Kind regards
    -Ippokratis
     
    2dchaos and shkar-noori like this.
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Hi Ippokratis,

    Looks like you are a bit of a pioneer :) Yes that's how it would work, so it's easy to author textures but mangle them to fit Unity workflows. A lot of artists would find it easier. It needs to support automatically updating a texture though. For example the source file was changed in photoshop, so the conversion should automatically run again, and the same textures as before should be spit out, as to emulate the Unity hot updating method, since artists do this frequently and tab to Unity to check.

    I don't think they mind a couple seconds delay in updating, you could always make that another option as alternative to update button.

    Best,
    Rob
     
    x_african_warrior_x likes this.
  3. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Hi Robert, the script is... Done. 5hrs :)
    ( I was thinking that automatic updating should be there anyway, didn't occur to me that it is a feature )
    I 'll try to show some examples next.

    So
    - auto updating (an example video follows soon)
    - all the operations are non destructive
    - coding language - CSharp ± 250lines.
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Hopefully you will sell it on asset store, it would be useful for current Unity too I think - people often have difficulties with packing things in alpha. I wonder if packing things in normal map alpha channel is also an optimisation, for example less texture read in fragment.

    Seems like an advanced user case but interesting nonetheless.
     
  5. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    @hippocoder
    Well, the alpha in Normal maps can be written - as is - with the Texture Baker.
    Someone should write special shaders to make it work though - if you have specific info you need to pack in the shader in mind, let me know in a pm.

    To those who wonder, what is a specular map and why should I bake it in alpha ?

    -Specular maps define how much light is reflected in each part of a model.
    -They come as a black and white texture, either exported directly by the modeling app or made by hand.
    -Artists usually create many maps for a model : specular, AO, diffuse, normal and provide them as separate maps for flexibility.
    -Shaders that use many maps are expensive, so developers try to pack the textures.
    -Unity Specular shaders support specular (or gloss) maps by putting them in the alpha channel.

    Ok now suppose that you have a diffuse and a specular map for a given model. Using Texture Baker you just put the diffuse in a slot, the specular in another, hit the Bake button. A dialog appears and asks you where you want to save the texture. You choose a name, press save and it's done.
     
  6. dirtybassett

    dirtybassett

    Joined:
    Oct 3, 2012
    Posts:
    59
    I use substance painter so being able to pack grey scale textures into colour channels from within the editor would be great.
     
  7. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Would you like to give some examples ?
     
  8. dirtybassett

    dirtybassett

    Joined:
    Oct 3, 2012
    Posts:
    59
    Substance outputs all textures in separate files, PBR shaders like what LUX uses need these packed into a single texture.. For example a metal mask in the red channel , AO in green , specular in the blue channel and roughness in alpha. Doing this in editor would be far better than flipping to photoshop all the time.
     
  9. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    I understand the workflow.
    Would you like to send me an example scene so I can try it out ?
    A simple model, with the substance textures ( native output ), the modified textures (for use with Lux) ?
     
  10. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Sounds good, so overall we get cheaper materials for rendering (what is overall improvement with that technic VRAM sparing or drawcalls or?). Will this work with any shader overall?
     
  11. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Hi,
    The main issue this tool exists is to make it easier to perform some actions that make materials more performant.
    It eases the workflow - no flipping to photoshop to use a specular or an ambient occlusion map.
    Or, instead of using the tint in the desktop diffuse shader, you can bake the tint in the texture and use the mobile desktop instead.

    I am working on a demo using the model coastal gun battery from Mr Necturus.
    This is how it looks using the diffuse shader

    Screen Shot 2014-10-25 at 21.44.21.png

    and here using the specular :

    Screen Shot 2014-10-25 at 21.44.37.png

    the model comes with separate specular maps. To make them usable you normally have to export them to photoshop, along with the diffuse, add a channel to the diffuse, copy paste the specular in diffuse alpha, reimport in unity.
    With the tool you just put the textures in their slots and press bake.

    t Screen Shot 2014-10-25 at 21.52.23.png
     
  12. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    @dirtybassett, you mean the skin shader in Lux ?
    This is the needed order ?
    Screen Shot 2014-10-25 at 22.21.52.png
     
  13. dirtybassett

    dirtybassett

    Joined:
    Oct 3, 2012
    Posts:
    59
    Yeah exactly. Going to and fro from Photoshop gets a pain when your working on multiple textures.
     
  14. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    @dirtybassett I have done some progress on that, would you like to send me some files to test it out ?
     
  15. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Sounds great. Along this tool would be cool to have some atlas baking tool too something that would bake multiple textures into single atlas. That would make great combo as it would reduce use of Photoshop for such things.
     
  16. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    Another great plugin helper that should be integrated in Unity editor.

    Why not making the plugin lot more universal ? with the possibility to map any textures to any channels or to alpha ?
    Like you choose the number of source textures then for each you attribute rgb, or rgba , or only one channel (alpha, r,g,b).
    This would make the tool lot more universal for any use, people could decide to bake AO, specular, curvatureor any map information they need on any channels.
     
    hopeful likes this.
  17. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    @zenGarden
    Yup, I 've had the same thought after reading @dirtybasett's post. Someone else besides Lars will develop a clever shader that uses multiple channels of one texture for different maps, like DOTA etc does.
    I am thinking about giving another two options :

    Composer mode : choose a color or a channel (rgba) from a source texture to be remapped in one channel of the destination texture, for every channel of the destination texture.

    Color or R-source1 or G-source1 or B-source1 or A-Source1 to R-Dest
    Color or R-source2 or G-source2 or B-source2 or A-Source2 to G-Dest
    Color or R-source3 or G-source3 or B-source3 or A-Source3 to B-Dest
    Color or R-source4 or G-source4 or B-source4 or A-Source4 to A-Dest

    [EDIT]
    It is not useful to implement this, since few people will compose textures and fewer will compose textures from composite textures. I opt for making the following instead :

    map1 or value1 to R - Dest
    map2 or value2 to G - Dest
    map3 or value3 to B - Dest
    map4 or value4 to A - Dest
    [EDIT]

    Decomposer mode : Extract one channel of the Source texture to a destination texture

    ...to be implemented :)
     
    Last edited: Oct 27, 2014
    zenGarden likes this.
  18. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Here is a demonstration of the Ambient occlusion baker.
    I used the Cartoon Submachine Gun model from Torry.
    Torry includes a diffuse and an ambient occlusion map.

    I developed an unlit shader (included in the package) that uses an ambient occlusion texture, multiplied by a ambient occlusion factor. In plain Greek, or English, the ambient occlusion factor accentuates or diminishes the ambient occlusion effect.
    Examples :
    with ambient occlusion factor = 0
    Screen Shot 2014-10-26 at 20.32.23.png
    with ambient occlusion factor = 1
    Screen Shot 2014-10-26 at 20.32.31.png
    with ambient occlusion factor = 3
    Screen Shot 2014-10-26 at 20.32.40.png

    What is cool is I included an option to recreate this effect in the AO Bake :)
    So, after you decide on the AO factor you like on the shader
    Screen Shot 2014-10-26 at 20.35.38.png

    you enter the same value on the AO Bake AO factor
    Screen Shot 2014-10-26 at 20.36.48.png

    and you get the baked texture, ready to be used in a regular Unlit shader :)
     
  19. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    @janpec I love atlases but I wish to keep the price low, around 10$. There are many solutions available that allow you to combine materials, including Batching Tools (an atlas without uv remapping and vertices merge is useless really).
     
    hopeful likes this.
  20. giyomu

    giyomu

    Joined:
    Oct 6, 2008
    Posts:
    1,094
    Look like an handy tool ! Keep us updated :)
     
  21. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Here is a demonstration of Texture Baker in Bake specular mode :
    textureBaker-Bake Specular.gif
     
  22. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    It is ready.
    Texture baker.gif

    Bake Specular : Bakes a specular map in the alpha channel

    Extract specular : Extracts a baked specular map from the alpha channel. Useful if you have assets with baked specular (like the ones at the Unity Robot Lab project) and you want to use those maps in Unity 5.

    Bake AO and Tint : You tweak in the Unlit AO Tint shader the appearance of the texture, using an ambient occlusion texture (that can be further adjusted by a AO factor) and a Tint Color. Then, you bake the results in the diffuse texture for max efficiency.

    Extract channel : You have a composite texture (like in the Lux skin shader) and you want to extract a map stored in a channel. Select the channel and extract it.

    Compose : You wish to create a composite texture for a clever shader like the above that stores different maps in each channel. Put the maps in the channels and get the composite texture.

    Thanks for your input everyone, you really helped me a lot.
    I 'll write the manual tomorrow and I 'll submit it in the asset store.
    Let me know if you have more ideas.

    Kind regards,
    Ippokratis
     

    Attached Files:

  23. x_african_warrior_x

    x_african_warrior_x

    Joined:
    Jun 24, 2014
    Posts:
    80
    wow, this is moving fast. yes its great with pbr (lux) shader. just saves alot of time wasted flipping btn windows
     
  24. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    I made another two shaders that will be included in the package and are aimed to help artists tweak their textures,

    -Bumped Specular Map AO -
    With a separate specular map slot, as well as an ambient occlusion map slot and a AO factor

    Bumped Specular Map AO.png

    -Specular Map AO-
    With a separate specular map slot, as well as an ambient occlusion map slot and a AO factor

    Specular Map AO.png

    Their purpose is
    - to allow you to visualize your specular maps in unity before you bake them
    - to allow you tweak the Tint and the ambient occlusion before you bake them

    Now if I could write that manual faster...
     
  25. Kirbyrawr

    Kirbyrawr

    Joined:
    Jul 23, 2012
    Posts:
    945
    Looks good keep it up! ^^
     
  26. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
  27. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    I submitted it - will show up soon.
    Thanks every beta tester for their patience - the next update will be based on your input.

    I wish to clarify that this tool will not create a specular map from a diffuse map.
    It will embed or extract a specular map that is stored in the alpha channel.
    So, if you use it with a diffuse texture that has no specular map in the alpha channel, you will get a white texture.
    Which is expected and perfectly normal.
    There are a few diffuse maps in the Robot Lab project that have a specular map baked in the alpha, so you can try them if you wish. Or you can make your own.

    Kind regards,
    -Ippokratis
     
    Last edited: Nov 2, 2014
  28. omarzonex

    omarzonex

    Joined:
    Jan 16, 2012
    Posts:
    158
  29. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    I had some great feedback from the beta testers - thanks for your input :)

    I received suggestions, some of them are planned for the next update
    - invert channel : Useful for working with normal maps that have an inverted channel
    - save at the same folder : Now, each time you save a texture the save dialog presents the Asset folder. It is better to present the folder you saved the last textures (e.g a "baked" folder or a "Textures" folder)
    - context help : Some pop-up that explains what each element does

    I also have another idea
    - tweak - bake normals : control how "deep" the normals will be and bake this ( currently the only way to do it is to go to the texture import settings, guess a value, cross fingers it works ).

    I plan to implement those 1-2 weeks after the 1.0 version appears on the asset store. If you have suggestions on extra functionality, let me know.
    -Ippokratis
     
  30. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,932
    Oh, this is just getting better and better. I need it now. lol I spent two days testing models and much of that time messing around with photoshop. This is exactly what I need. I will be looking for it on the asset store.

    Thank you for taking the time to make it!
     
  31. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Hey, thanks for the kind words :)
    I hope it gets approved soon, I work on the 1.1 version.
    Normal maps strength works, now I try to implement the tooltip help.
    Seriously, I need ideas - suggestions.
     
    Teila likes this.
  32. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Well,
    Asset Store review takes time.
    This is not the package that will make Unity or me rich, it can speedup some people's workflow though.
    Until it is accepted, feel free to contact me via pm for direct purchase at 10$.
     
  33. dirtybassett

    dirtybassett

    Joined:
    Oct 3, 2012
    Posts:
    59
  34. Razmot

    Razmot

    Joined:
    Apr 27, 2013
    Posts:
    346
    This is really cool, tell us when it's on the store !
     
  35. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    It is not going to happen actually.
    I got a reply from the asset store, telling me that the images I created for displaying the asset are not of the required level.
    So, I have to pay someone to create the images for me.
    It is not going to happen.
    I do not have the funds to promote a 10$ asset by paying a graphic artist that fits a niche need.
    I am not pleased from this interaction really, it makes me reconsider my attitude towards the forums and the asset store.
    If someone wants it, contact me via pm.
     
  36. Razmot

    Razmot

    Joined:
    Apr 27, 2013
    Posts:
    346
    It's sad cause your tool is especially useful for people like us, programmers who have difficulties to make things look good ! Maybe you could find someone to help on presentation for free. Some artists like to help just for being credited. In the mean time, just sell it on paypal on your own site, or use something like stripe.com if you want more protection against refunds.
     
  37. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    I've implemented Undo for the script and I will re-try to submit it using new artwork.
    If someone feels like making cute graphics, please let me know.
     
  38. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    You should learn a little about making good 2D presentations, it could help you selling next stuff ;)
    Try learning using gradients, shadow effects, look at exemples on the asset store showing great attractive presentation and take them as a base work.
     
    Ippokratis likes this.
  39. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,685
    Surely it will be accepted, but if it isn't ... I bet somebody here can help you out without too much trouble.
     
  40. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,932
    Oh, too bad! I just realized how much I need this today and went searching only to find it was not accepted. So sorry. It would be so useful, a true time saver.
     
  41. PetrSevostianov

    PetrSevostianov

    Joined:
    Nov 26, 2012
    Posts:
    18
    Hi!
    We've made a Unity tool for texture composing by masks. It calls CompositeMap and it is accessible on the AssetStore.

    It works similar to CompositeMap in 3ds Max or LayeredTexture in Maya and allows to create and edit textures by masks and real-time evaluate the result on the current settings of Unity scene and shader.
    Different renderes and shaders uses different layers for keeping information about diffuse color, glossiness, etc. Our tool allows to work with any of them.
    We uses our own 3ds max script for creating masks. It could be freely downloaded wrom our website. Maybe it will be useful for you.
     
  42. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,932
    This would be very useful to me, Petr. Unfortunately, the videos are not enough documentation and the written instructions are all in Russian, a beautiful language, but not one I can read. :) I remember a few words from a visit there many years ago, but can't read all those lovely Cyrillic letters.

    Any chance you could translate them for us?
     
  43. PetrSevostianov

    PetrSevostianov

    Joined:
    Nov 26, 2012
    Posts:
    18
    Hi Teila, thank you very much for your comment! It was a problem with our website language autodetect. I've just fixed it. Now you can find english documentation and tutorial for CompositeMap and MaskBaker there. Also you always can ask me if something in documentation is incomprehensible :).
     
  44. x_african_warrior_x

    x_african_warrior_x

    Joined:
    Jun 24, 2014
    Posts:
    80
    i use this tool daily and love it. thank you.