Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Shared material but different texture offsets : possible ?

Discussion in 'Editor & General Support' started by p-lux, Aug 7, 2009.

  1. p-lux

    p-lux

    Joined:
    Oct 21, 2008
    Posts:
    59
    Hi there :)

    I'm trying to optimize my draw calls and I have a question about material : I have about 50 little objects composed of 1 mesh and 1 mat (UVed). In order to optimize the use of the VRAM, I have a unique texture for all the different colors of the meshes.

    Here's the mesh :

    http://img12.imageshack.us/i/meshuv.jpg/

    And the shared texture :

    http://img8.imageshack.us/i/meshuv2.jpg/

    What I'm trying to do is to change the offset of the texture for each mesh, but when I move the offset it obviously changes the offset for all the meshes in the same time.

    So, is there any technique which allows to share one material and one texture but with different offsets for each of the meshes ?

    Thx
     
  2. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    Short of directly changing the uv on your model, I don't think there is :(.

    It's a pity that the texture matrix cannot be manipulated without spawning a new material, as it would allow much more efficient use of texture atlases. To me it would make more sense to have the texture matrix set on the renderer rather than the material, but I guess there are other reasons why it was designed like this instead.

    Anyway, I believe the most workable solution for your problem is to use different meshes for each color, each seperate mesh with pre-baked uv's for its specific color.
     
  3. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    I've never tried this in practice, but in theory it should be possible to offset the actual UVs of the mesh into the appropriate color section.

    http://unity3d.com/support/documentation/ScriptReference/Mesh-uv.html

    Now if you're also trying to combine all of these pins into a single mesh at runtime, this method would become a lot more complex.

    The other more artist friendly option is to just make several copies of your pin, offset the UVs in a 3d app, and then save out an individual pin with each color. This way they'll still all use the same material and can be combined into a single draw call.
     
  4. p-lux

    p-lux

    Joined:
    Oct 21, 2008
    Posts:
    59
    Thanks for your help, I'll try your solution :)
    See ya !
     
  5. p-lux

    p-lux

    Joined:
    Oct 21, 2008
    Posts:
    59
    OK, it works !

    I've made a little test : in Wings3d (my favorite editor for the moment, I'm developer not artist) I created a simple mesh (pen) and duplicated it 3 times, then I UV-mapped these 4 pens in the same scene with always the same texture, but adjusting the UVs of each mesh to match the desired color in the texture. Finally, I exported each pen as a unique 3ds file in my assets folder.

    Importing all pens in Unity gaves me 4 draw calls (the mat is vertex-lit), and after combining I go to 1 draw call for all the pens !

    Very cool !!!

    Another quick question please : how many max draw calls are acceptable for an Intel GMA card ? I plan to have an average of 500 draw calls in my scene, is it too much ?
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Draw calls are a function of CPU power, not the graphics chip.

    --Eric
     
  7. p-lux

    p-lux

    Joined:
    Oct 21, 2008
    Posts:
    59
    OK

    I wondered if it could be a good solution to move the UVs by script, using this technique : http://unity3d.com/support/documentation/ScriptReference/Mesh-uv.html

    I think it could be efficient for meshes that don't require detailled textures, like in the previous example there are just colours.

    I'll try it, otherwise I'll make a big 1024x1024 palette with all the colors I need :)
     
  8. AndreiMarian

    AndreiMarian

    Joined:
    Jun 9, 2015
    Posts:
    77
    Any news on using the same material with various UV offsets? Even after reading in that link, I still can't figure out how to offset texture on x and y, plus what about cases when there's no mesh, like in UI/Image?
    I was thinking about manually drawing part of texture something alike Graphics.DrawTexture() but that's in screen coordinates and for a dynamically positioned UI it wouldn't be viable, plus I guess it would still count as a new draw call...
     
    Last edited: Nov 17, 2019