Search Unity

Best approach for instancing with textures

Discussion in 'General Graphics' started by charleshendry, Dec 10, 2019.

  1. charleshendry

    charleshendry

    Joined:
    Jan 7, 2018
    Posts:
    98
    Hi,

    I want to create a game where most of the objects are static (buildings within a large city). There will be numerous building color overlays that will be turned on/off by the user, depending on various building status items. I'm doing this with MaterialPropertyBlocks at the moment, where I can render the same mesh multiple times with different colors in a single pass.

    At the moment I have split each building into individual "component" meshes, as in the default view, they will have different colors (e.g. window glass, window frame wood, walls brickwork, door wood 2, etc.). I don't have textures yet, but I understand I can use a texture array as an input to a MPB, so this should work ok as a single material in Unity as well, showing different tiled textures per component. I can reuse these components on other buildings, so the instancing works quite well. However, each building component has a very basic mesh, so there's a lot of CPU activity and very little GPU activity. Using components is good for variation amongst the buildings, but for performance I guess ideally I want just a few complete building meshes which I then instantiate.

    Is there a way to use a single mesh but set specific parts of it to a particular color/texture? I guess even if there was, this would be a lot of CPU work, which I'm trying to minimise.

    I also can't combine meshed of all components that share the same color as depending on the status overlay shown, this results in different color groups, i.e. some meshes share the same color for one particular status, but maybe not for a different one.

    Any advice on a good setup for this would be much appreciated. Thanks!