Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

5.6.0b4 disable instancing on vertex/fragment shader

Discussion in '5.6 Beta' started by CDF, Jan 18, 2017.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Hi, so reading the release notes:

    "#pragma multi_compile_instancing" line now is no longer needed in surface shaders. Instancing variants are automatically generated for surface shaders, unless you explicitly specify "noinstancing" in "#pragma surface" line."

    I'd like to know how to add "noinstancing" to my Vertex/fragment shader?

    I'm getting warnings on my static Meshes that use my non surface Shader:



    Is there something I can add to my Shader that tells it not to use instancing? Or is this a bug?
     
  2. zeroyao

    zeroyao

    Unity Technologies

    Joined:
    Mar 28, 2013
    Posts:
    169
    Hey,

    Handwritten vertex/fragment shaders don't have instancing automatically generated unless, like before, you added #pragma multi_compile_instancing line in the shader, which seems to be your case.

    I will update this warning message to make it disappear if instancing is not enabled. Thanks for reporting.
     
  3. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Nice, thanks
     
  4. Justin-Wasilenko

    Justin-Wasilenko

    Joined:
    Mar 10, 2015
    Posts:
    104
    Just to confirm, I have a mobile VR project with some custom shaders, I need to add #pragma multi_compile_instancing to the shader code for Instancing to be enabled? Unity won't add it in for me automagicically in 5.6?

    Is that all that is needed to add instancing support? Is adding '#pragma multi_compile_instancing'?

    I have some shaders based on the Mobile/Diffuse Specular bump map shader and thought Instancing could give me a performance boost. I'm not a shader expert by any means :)
     
    Last edited: Jan 25, 2017
  5. zeroyao

    zeroyao

    Unity Technologies

    Joined:
    Mar 28, 2013
    Posts:
    169
    Hello Justin,

    Since 5.6 beta 4, to actually enable instancing, you'll need to select your Material that is intended to be used on instanced objects and click "Enable Instancing" checkbox. you don't need to add "#pragma multi_compile_instancing" to the shader unless you don't see this checkbox.

    Instancing comes with some overhead on GPU and will only benefit projects that have a large amount of identical objects to render and the FPS is bound by CPU processor power. Often you don't have out-of-the-box performance boost by simply make everything instanceable.
     
    IgorAherne likes this.
  6. CorruptScanline

    CorruptScanline

    Joined:
    Mar 26, 2009
    Posts:
    217
    How can you set the enable instancing state of a material through code?

    EDIT: nevermind I was looking at the wrong assembly. Theres a Material property for that.
     
    Last edited: Feb 1, 2017