Home Technical Talk

N Individual materials for N objects VS one material for N objects

polycounter lvl 6
Offline / Send Message
Pinned
D4N005H polycounter lvl 6
Yes, the question seems silly. But the answer is vital for me. That's why I asked you professionals to clarify it.
I am making a car paint shader, and I want to put into it as much as parameters I can. Thus I'm adding parameters for stop lights, rear lights and blinkers to it. Or I can make a new shader only for the lights. But I'm not sure which way is better. So that is why I asked this question.
Looking for an answer,
Regards.

Replies

  • D4N005H
    Options
    Offline / Send Message
    D4N005H polycounter lvl 6
    Guys, found the answer.

    The answer is really interesting. If you make a 3D model with 4 meshes for Unity3D and that each of these meshes use one material (means thet use one shader and one material), in the runtime you are going to have four different materials of one shader in memory with the same material properties as the one in the disk. You can change a material properties in runtime but the other 3 materials wouldn't get affected and the original material (that those 4 materials had been instanced by this one) would not get affected, neither.

    So having N different materials of one shader is better than N same materials, I guess. So I tried to combine my "Car Body Paint" shader and "Car Lights Shader" into one shader and use different material properties for the car body and the lights models. Thus I'd have one shader but two different materials and no performance impact should happen. Although the shader I'm talking about shouldn't be too much expensive.

    Would be glad to hear your comments about this topic.

  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter
     I wouldn't have thought memory was really a concern here, I'd be more interested in what you're actually drawing to screen . 
    It'll depend on how the renderer batches materials and what effect changing parameters has as to what happens at render time. That simple material colour change could mean you're quadrupling the render cost of the car but equally it could mean you're not.

    In most cases a single shader on a single mesh is going to be the cheapest option.
    However, If you want to do something interesting like have transparency or flashing lights it's almost always going to be cheaper to only apply that shader to the bits of mesh that need it because by doing this you're reducing the number of pixels on screen that need extra processing. 

    As I said above, the cheapest solution will depend on what the renderer is doing and what the target hardware is good at so the only way to be sure is to profile it. 
     
Sign In or Register to comment.