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

[ShaderIncludePath] is deprecated, what to use instead?

Discussion in '2018.3 Beta' started by Elringus, Oct 25, 2018.

  1. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    In the latest beta update ShaderIncludePathAttribute is obsoleted with the following message:
    But I'm using this attribute in one of my Asset Store assets to add shader include path to a folder inside my package. The package itself can be moved by user, so I can't use a static path and instead I'm finding the package root using a special marker file inside my package:
    Code (CSharp):
    1. [ShaderIncludePath]
    2. public static string[] GetShaderIncludePaths ()
    3. {
    4.     return new[] { Path.Combine(PackageRootPath, "Shaders") };
    5. }
    PackageRootPath is a variable here and could change when user moves the package.

    So, the question is, what should I do know, when the [ShaderIncludePath] is deprecated? There seems to be no other way to add a dynamic path to shader include files.
     
  2. Juho_Oravainen

    Juho_Oravainen

    Unity Technologies

    Joined:
    Jun 5, 2014
    Posts:
    42
    Hey!

    Unfortunately from 2019.1 onward there is atm no way to set arbitrary shader include search paths. The shader includes must locate either in a known place under the Assets folder or in a package manager package. For a package manager package you can simply call
    Code (CSharp):
    1. #include "Packages/myPackageName/pathInsideThePackage/MyInclude.cginc"
    in the shaders and it will be automatically found. For something that is inserted inside the Assets folder unfortunately the user needs to manually include them from the correct path.

    Some background on this change:
    The [ShaderIncludePath] attribute was originally created as a quick hack to make our internal SRP shader library development possible. It turned out quite quickly to be a really bad design as it makes shader importing dependent on the script compilation and brings absolute paths into our asset system in a bad way. So we developed the new way to include shaders from package manager packages which covers our main use case. We do realize that the [ShaderIncludePath] attribute covered a long-time usability hole on asset distribution (outside the package manager) and now we've taken it away, but the solution just wasn't sustainable.
     
    a436t4ataf likes this.
  3. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Thanks for the clarification!

    I guess when Asset Store publishers will be allowed to distribute packages via the package manager, we'll be able to use static include paths, but, as far as I know, it won't happen before Unity 2019.2 or something? Would it be possible to not completely remove [ShaderIncludePath] until then?
     
  4. Juho_Oravainen

    Juho_Oravainen

    Unity Technologies

    Joined:
    Jun 5, 2014
    Posts:
    42
    Unfortunately keeping it around would hold back important improvements on the asset management side. So it is unlikely that we'd keep it around that long. But I will raise up this concern again in our teams to see if there would be any stopgap solution.
     
    Elringus likes this.
  5. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Yes that correct. You can already use local packages that will work for this, it's just that it's not super well supported via asset store yet :(
     
    Elringus likes this.
  6. litefeel

    litefeel

    Joined:
    Dec 6, 2016
    Posts:
    68
  7. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Well, relative paths (like `../../Folder/IncludedStuff.cginc`) were available a long time ago, but it won’t work in my case. I need a dynamic path, so that users are able to include stuff from my Asset Store plugin into their shaders wherever the package with the plugin is located. Guess I’ll just have to remove that feature until we’re allowed to distribute packages via the package manager.
     
  8. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,266
    This unfortunately poses an issue for custom effects from the asset store in 2018.3 onward. Since these sit in the /Assets folder and cannot reach the package manager directories.

    A workable, but hardly feasible solution is to navigate to the PackageCache folder. Though, if the version should change, the paths would be rendered invalid:
    Code (CSharp):
    1. #include "../../../../../../Library/PackageCache/com.unity.postprocessing@2.0.14-preview/PostProcessing/Shaders/StdLib.hlsl"
    For dependencies on the Post Processing Stack, it is possible to copy the contents of the "Shaders" folder into the /Assets folder, and reference those files instead. This feels like bad practice, but this is what I think I'll go with for now.

    Hopefully a solution can be devised to bridge the gap between 2018.3 and the upcoming package manager distribution :)
     
    Lars-Steenhoff and Elringus like this.