Search Unity

problem about shaders in asset bundle and "Graphics.Always Included Shaders"

Discussion in 'Asset Bundles' started by uncleciba2game, Jun 10, 2019.

  1. uncleciba2game

    uncleciba2game

    Joined:
    Jul 22, 2016
    Posts:
    11
    My configuration:
    Graphics.Always Included Shaders : contains my shaders and some built-in shader ( e.g. Sprite/Default)
    my shader location : Resources folder
    prefabs and materials use both my shaders and built-in shader

    then, build asset bundles(android), use AssetStudio to view asset bundle and find that:
    my shader code is in the asset bundle, but built-in shader is not in.( just a reference to the shader, ref: https://support.unity3d.com/hc/en-u...ders-are-pink-when-loaded-from-an-AssetBundle)

    playing in unity editor(windows):
    the game object which use built-in shader is ok ( use the project's shader )
    and others which use my shaders is pink. (use the shader in asset bunlde, not supported because platform specified)

    Although, I can change the editor's graphics API to gles2 to make the shader compatible.
    But , I want keep my shader in the main project instead of in the assetbundle.

    the "Always Included Shaders" is running work for built-in shader ,but not work for my self shader.
    Is it a bug ?
    unity verison 2018.2.0f2
     
    phobos2077 likes this.
  2. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    This is intended behavior. Only built in shaders in the Always Included Shaders list can be referenced and used by asset bundles.
     
    yildirimcemalcan likes this.
  3. KanishkaCemtrex

    KanishkaCemtrex

    Joined:
    Mar 28, 2018
    Posts:
    2
    Agreed this is an intended behavior as your other project is not able to identify the shader types but this could be resolved.

    Follow this steps :
    -- Play the project in standalone. Note down the shaders which are turning into pink.
    -- Go into graphics settings of the project from where you are creating assetbundle.
    -- Add the previously noted shaders into the "Always included shaders".
    -- Rebuild assetbundle And put it in the project where you need it.
    -- Load the assetbundle... Boom your problem is solved.
     
    yildirimcemalcan likes this.
  4. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    When you add a shader to "Always included" list, Unity is forced to generate and include all variants of that shader in your bundle. For some of the built-in shaders this can easily add dozens of MBs to the bundle that contains the shader.

    I had success very recently with going into the Graphics Settings and using the button that allows you to save the known used variants to a .shadervariant asset, then add that into the same bundle we add the shaders. You can then manually add shaders and variants to this file if you find they are missing. This cut down our shader bundle from 38MBs to 5MBs and fixed problems we had with missing variants.
     
  5. uncleciba2game

    uncleciba2game

    Joined:
    Jul 22, 2016
    Posts:
    11
    thank you.
    I have solved the problem.The same way you said, put shader in asset bundle, and load the asset bundle.
    But I'm still depressed.
    When I put my shaders in "Always included shaders",Why can't unity put my shaders in the program ontology
     
  6. eyalfx

    eyalfx

    Joined:
    Oct 8, 2010
    Posts:
    108
    This works for external shader, but I'm having the same issues with the Standard shader.
    You can't add the standard shader because it's not available in the project.