Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Create shader variant from material

Discussion in 'General Graphics' started by Vifi, Feb 28, 2022.

  1. Vifi

    Vifi

    Joined:
    Aug 5, 2013
    Posts:
    28
    Hi,
    i am writting some tool to find out, which material is qualified into which shader variant in shader variants collection.
    My plan was to generate shader variant and use contains and at least to check if it is in shader variants collection. Then i could just sum the same shader variants to check how many materials is in every variant.
    Sadly i don't understand it enough to do so.
    I stopped on generating new shader variant because it needs to get PassType, which i cannot aquire.

    Code (CSharp):
    1. var item = materials[0];
    2. ShaderVariantCollection.ShaderVariant shader = new ShaderVariantCollection.ShaderVariant(item.shader,/*don't know how to get it*/, item.shaderKeywords);
    I did some research and found out (not sure if correctly) that PassType is just value of "LightMode" tag inside shader pass?
    But there might be multiple passes in shader, does it mean one shader variant is in fact one pass from shader?
    Same as there might be multiple subshaders per shader, isn't it? So every variant is one of passes inside one of subshaders from one of shaders?
    I don't think i understand it right :(
    Do you guys know how to bite it?
    Thanks in advance
    Cheers