Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

One Batch: Combine hundreds of materials into one draw call

Discussion in 'Assets and Asset Store' started by jbooth, Sep 14, 2018.

  1. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    Does the texture have an alpha channel? Do you mind sending me the assets?
     
  2. DrInternet

    DrInternet

    Joined:
    Apr 6, 2014
    Posts:
    94
    Yes it does and no I don't. But it won't help as I'm not able to reproduce it on clean project either. OB files copied from main project to clean project work fine, but those from clean project copied to main project work even worse (mesh data works the same, just material switching causes all object to be black).
    ---
    Ok, I found something. I think it's this material refresh bug again. After closing and re-opening clean project, cutout is bugged (looks like opaque). Upon selecting the object in scene, it returns to normal. The only problem is, in the main project it does not get fixed.

    http://drinternet.pl/ms/sticks.zip
     
  3. DrInternet

    DrInternet

    Joined:
    Apr 6, 2014
    Posts:
    94
    I take it back, refreshing does work, but - here comes a good one - you have to have "selection outline" gizmo checked.
    So cutout is somehow working. The only "problem" is no "cutout amount" value/slider.
     
  4. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    I thought that was in the individual material properties? If not, I'll have to add it.
     
  5. AlterSpace

    AlterSpace

    Joined:
    Jun 29, 2014
    Posts:
    32
    Hi, I just bought your asset and I love it. I wanted to know two things:
    1 - could it be possible to add another uv layer (uv3 maybe) to the mesh with the plugin? I would like to adapt a multi-layer shader created in Amplify Shader, but I would need another index
    2- could it be possible to have the mesh instantiated in the editor - not at runtime - without modifying the original mesh or creating a new asset in the project folder? I have used other plugins, like MeshCombine, that leave the choice to the user between asset instance creation and prefab/asset-in-project-folder creation. That could be useful to see the changes building the level, with a slider on a script attached to the mesh renderer gameObject. The script should create a copy with different vertices values, I suppose, without necessarily saving it.
     
  6. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    If your mesh has uv3's, it will copy them over when it creates the new meshes, so that should work just fine.

    I have no plans for runtime generation, mainly because packing the textures takes quite a bit of time.
     
  7. AlterSpace

    AlterSpace

    Joined:
    Jun 29, 2014
    Posts:
    32
    And if my mesh has no UV3, can a function like Mesh.SetUV be used to create a new channel?
     
  8. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    Yes.. It's still a standard mesh..
     
  9. AlterSpace

    AlterSpace

    Joined:
    Jun 29, 2014
    Posts:
    32
    Can I ask you if you can add a button somewhere to add other channels to the mesh? I know that Mesh.SetUV exists, but that's all I know about mesh modification inside Unity via code :(
    Sorry to bother you on this subject but I really don't know how to do it
     
  10. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    No, turning One Batch into a UV editor doesn't really make sense. If you want a new UV channel, you should add whatever UV data you want in your 3d modeling program to your original mesh, which has a UV editor.
     
  11. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    Also, judging from your last message, you seem to be confusing UV data on a mesh with vertex to fragment interpolators in a shader.
     
  12. daisySa

    daisySa

    Joined:
    Dec 29, 2011
    Posts:
    340
    Is it possible to provide LTS compatibility for this asset?
     
  13. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    LTS?
     
  14. daisySa

    daisySa

    Joined:
    Dec 29, 2011
    Posts:
    340
    Sorry! :) Unity LTS (Long Term Support) a.k.a. 2017.4.
     
  15. DavidLieder

    DavidLieder

    Joined:
    Feb 14, 2016
    Posts:
    83
    Hi Jason,

    I have a couple of quick questions in regards to One Batch and best practices for setting up a scene.

    I was wondering about asset pack collections from the asset store (or wherever) that already have been committed to a texture atlas. What I mean is a scenario where we get an asset pack from the asset store (or wherever) and it has a lot of prefabs (models) and the entire collection is already dumped to a texture atlas. Then we use only a couple of prefabs and remove the rest, but the entire texture atlas is still there. Then for the few we kept, we run the specific prefabs through One Batch. I assume One Batch will have to grab the entire atlas, or will it grab only the textures needed?

    Is there a way to "unpack" these type of assets (that are already committed to a texture atlas), with the goal that our project only has the needed textures?
     
  16. unisip

    unisip

    Joined:
    Sep 15, 2010
    Posts:
    269
    This does look really cool indeed. Really clever approach to atlasing's main problem, which in my opinion is tiling.

    Can you clarify what data you're adding to the meshes (I kinda missed that part in your video) ? I'm guessing material index to sample the right textures... What channel are you using for that ?
    I'm considering using your system but I have some procedural geometry in some parts of my game, so I just wanna see if I need to plan for adding one batch compliant data when I create my meshes. (And BTW, is source code included so that I can have a look if needed to help understand what to do with my procedural meshes ?)

    Tks!
     
  17. hungrybelome

    hungrybelome

    Joined:
    Dec 31, 2014
    Posts:
    274
    Did you ever get it working correctly for specular/smooth materials?
     
  18. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    Yes, source is included. the data is stored in texcoord0.zw components.

    The specular workflow? Yes- it works in my test cases. But if you have a particular case of data that does not work feel free to send it over.
     
  19. hungrybelome

    hungrybelome

    Joined:
    Dec 31, 2014
    Posts:
    274
    Just tested the latest and sorry, you are right that the specular workflow works well!

    Also, just sent you a project with a "IndexOutOfRangeException: Array index is out of range." edge case when using some models with LODs. Thanks
     
  20. DrInternet

    DrInternet

    Joined:
    Apr 6, 2014
    Posts:
    94
    OK, I will "send you over a particular case of data" as apparently you can't even test your own asset. Or no, even better, I will use your "particular case of data".

    Open your demo scene. Select a stone material. Delete all maps but diffuse and normal. Change shader to standard specular. Use stone_ao as specular map. Now create new OB config, drag and drop stone sphere. Extract, combine.
    Compere before and after look.
    Also try changing "specular color" in OB. Hint: it doesn't work even if per-pixel map is not provided.
    Now tell me again that specular is working.

     
  21. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    382
    @jbooth this will be a massive workflow time saver, thanks so much
     
  22. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    Now that you have provided ACTUAL repro steps I can test this. When you say specular is not working, that can have like 5 meanings. Specular values, specular textures, specular response in a metallic workflow, etc. that is why ACTUAL repro steps are important instead of just screaming “something doesn’t work”
     
    DavidLieder and Willbkool_FPCS like this.
  23. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    It also doesn't help that the last submitted version of one batch is apparently still stuck in review since I submitted it a month ago. I submitted a new version, so hopefully that will unstick it..
     
  24. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,797
    Sorry to butt in but book of the dead assets are engineered for the HDRP pipeline which isn't the same setup as standard shader, just a heads up as as I wander along the forum (you'd need to swizzle your textures a bit).
     
  25. DavidLieder

    DavidLieder

    Joined:
    Feb 14, 2016
    Posts:
    83
    One Batch is a great product and the support from Jason is incredible. Unfortunately, people like you "Dr. Internet" try to pollute the community, but hopefully, you will either fizzle out or change your attitude, while the rest of us move forward and create cool apps and games.
     
  26. AlterSpace

    AlterSpace

    Joined:
    Jun 29, 2014
    Posts:
    32
    Hi, I noticed that there's a repetition in the script OneBatchConfigEditor_UI, at line 152. The "ma.metalStrength" was already set up at line 149, and the repeated one used the normal strength value, messing things up when moving the normal value slider.
    I also tried to use the vanilla Amplify Shader example in the provided demo scene, and that was the result:
    Screenshot (70).png

    I just used the already created Albedo and Normal texture arrays. Is it possible that the OneBatch Texture Index function does not work as intended? Or do I have, with my already proved ignorance, to do something more to make things work? :D
     
  27. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    Ah, nice catch. Yes, the indexing function is wrong; I just fixed it for the next patch, but it's easy to fix if you don't want to wait. Open up Examples/AmplifyShaderEditor/AmplifyFunctions/OneBatchTextureIndex and drag the output of the VertexColor A channel to the multiply node (it is incorrectly mapped from the B channel).
     
  28. AlterSpace

    AlterSpace

    Joined:
    Jun 29, 2014
    Posts:
    32
    I just modified the multiplied channel, from B to A, in the vertex color window and I couln't see any change in my scene view. Here's the result:
    Screenshot (71).png
    Other ideas? I don't know how to help.
    OneBatch worked as a charm with the included standard shaders anyway ;)
     
  29. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    I'll check it out after work- that was noticeably wrong, but there might be something else going on..
     
  30. AlterSpace

    AlterSpace

    Joined:
    Jun 29, 2014
    Posts:
    32
    Any news about custom shader support? I really need that :oops:
     
  31. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    Fixed. I'll pm you the files until the patch comes out..
     
  32. AlterSpace

    AlterSpace

    Joined:
    Jun 29, 2014
    Posts:
    32
    I've just fallen in love... I will try it in the next hours, thanks ;)
     
  33. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    201
    Apart from requiring textures to be the same size, what limitations should we be aware of if using One Batch? The benefits are clear, but are there down-sides to be mindful of?
     
  34. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    Well, all textures will be scaled to be the same size. Right now, big limitation is that it's tied to the standard shader. Also keep in mind that it's not a cure all- many other things may break static batching in Unity as well as multiple materials.
     
    Deckard_89 likes this.
  35. ArkadiuszR

    ArkadiuszR

    Joined:
    Jan 21, 2016
    Posts:
    20
    @jbooth Sooo how I understand it not support lightweight yet? :)
     
  36. AlterSpace

    AlterSpace

    Joined:
    Jun 29, 2014
    Posts:
    32
    Hi, I got this error trying to combine a list of prefab (and that's not my first use of OneBatch):
    Screenshot (72).png
    Any idea where did it come from?
     
  37. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    Most likely some error case I'm not testing against - like a Mesh Renderer which has no material, or a Mesh Filter with no mesh assigned.
     
  38. AlterSpace

    AlterSpace

    Joined:
    Jun 29, 2014
    Posts:
    32
    I already checked for those, with an automated script that removed every gameobject with a missing mesh filter and or material, before creating the prefabs. If I split the prefabs between two differents OneBatch config files, the error doesn't occur anymore. It looks like I've reached some kind of "not visible" internal limit
     
  39. AlterSpace

    AlterSpace

    Joined:
    Jun 29, 2014
    Posts:
    32
    Not sure why, but removing a single, specific, prefab (that I already checked and that has no missing mesh asset under the mesh filter neither missing materials) from the config list solved the problem. I will investigate more
     
  40. hiljadnikova

    hiljadnikova

    Joined:
    Feb 19, 2019
    Posts:
    1
    InvalidCastException: Cannot cast from source type to destination type.
    JBooth.OneBatch.OneBatchConfigEditor.AlbedoHasAlpha (JBooth.OneBatch.OneBatchConfig cfg) (at Assets/OneBatch/Editor/OneBatchConfigEditor.cs:72)
    JBooth.OneBatch.OneBatchConfigEditor.CompileConfig (JBooth.OneBatch.OneBatchConfig cfg, System.Collections.Generic.List`1 src, System.String ext, Boolean texturesOnly) (at Assets/OneBatch/Editor/OneBatchConfigEditor_Compiler.cs:432)
    JBooth.OneBatch.OneBatchConfigEditor.CompileConfig (JBooth.OneBatch.OneBatchConfig cfg) (at Assets/OneBatch/Editor/OneBatchConfigEditor_Compiler.cs:955)
    JBooth.OneBatch.OneBatchConfigEditor.DelayedCompileConfig () (at Assets/OneBatch/Editor/OneBatchConfigEditor_Compiler.cs:299)
    UnityEditor.EditorApplication.Internal_CallDelayFunctions () (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:200)

    Why
     
  41. DavidJares

    DavidJares

    Joined:
    Dec 18, 2016
    Posts:
    37
    @jbooth Wow. Thank you very much for the insightful detailed rendering-Explanation part at the end of the manual. You explain very! well. All I have as background in CG is a base-course in Computergraphics and Animation at University and some self-education. I study Computer Science. Am doing Unity-Related things as mainly in my free-time since 4 years. Have you ever thought of writing a small book / guide / Tips n Tricks / Overview & Explanation-"thing" for how this stuff in Unity works together ? If you sold a book with sharing these kind of useful insights into your knowledge, Ill be happy to throw money to you and instantly buy it , and I am sure I am not the only one :) PS: I am very happy with onebatch of course.
     
  42. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    No- worked on some chapters in a book once (DX9 Audio Exposed), and it's an incredible amount of work with little chance of significant profit. So while I'm glad I did it, I have no desire to do it again. I do teach or lecture at schools and conferences sometimes, which is pretty similar on the work to profit ratio, but I find it a lot more enjoyable and much more bit sized.
     
  43. DavidJares

    DavidJares

    Joined:
    Dec 18, 2016
    Posts:
    37
    @jbooth Hmm, yes I understand. Well, as a follow up, did you maybe think about a udemy-course ? thex can vary in length and, while there is a plethora of "how to make games in unity ( fast :)) ", there is quite no such thing with regards to your knowledge. I think this is a hole you could potentially utilize as additional income. I already enjoyed every of your youtube videos, you explain really well! ( i will buy the microsplat-combo-package now ). I am saying this just because I think that your knowledge would really benefit to a lot of those many indies with scattered & varying degrees of knowledge. And I think making a video-course with a range of 1-4 hours maybe would be a assemblance of bit-sized work and less stressful than a book. ( I understand that selling specific technical books is probably not very rewarding these days ). I my own own quite a lot of udemy courses, not all are worth the money, but that is the same with assets. Therefore some really shine ( and also have quite some customers ). I am just saying and trying to encourage you a bit. Maybe just think about it :) Best regards, David.
     
  44. Barritico

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    193
    Hi.

    I bought the asset.

    Following the documentation, I created a new project.
    I have opened example / scene

    And this is what appears to me:

    onebatch.jpg

    Thank you.
     
  45. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    What Unity version? Are you running an SRP? Can you try in a new project?
     
  46. Barritico

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    193

    - Unity Version - Unity 2018.3.13f1
    - Running an SRP - No.
    - Try in a new project - Yes.... but same problem.

    Attach more images with more data. For your consideration.

    onebatch2.jpg
     
  47. AlterSpace

    AlterSpace

    Joined:
    Jun 29, 2014
    Posts:
    32
    I noticed that the Amplify Shader Function "OneBatchData" does not work. It always uses the first material data and not the next ones, like it's using the same 0 index.
    You can see that using your "Amplify Shader" shader example with the already OneBatched scene: if you change the Tint color for the first entry, in the config file, to green it will turn the entire scene to green and not only the "Brick" materials of that entry.

    I'm using Unity 2019.1 anyway
     
  48. AlterSpace

    AlterSpace

    Joined:
    Jun 29, 2014
    Posts:
    32
    It looks like the Property Texture in your material is missing. The first entry is empty and it should not be like that ;)
     
  49. Barritico

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    193
    Well, I do not know, honestly.

    It is the scene of the example, as is. Without changing anything.
     
  50. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,659
    I wonder if it got unhooked in the Unity version upgrade?