Search Unity

Question Shader inclusion in Asset Bundles

Discussion in 'Shader Graph' started by BogdanM, Jun 5, 2023.

  1. BogdanM

    BogdanM

    Joined:
    Sep 3, 2017
    Posts:
    8
    TL;DR Is there a way to check which compiled shaders made it into a build?

    We have recently upgraded our project from Built-In to Universal Render Pipeline, with the arrival of LTS 2022. The conversion was relatively easy, with the exception of custom shaders which needed to be converted from CG to HLSL. The shader in question is a Full Screen Shader which used to be done with a simple Blit OnRenderImage, but now it is done through a FullScreen Render Feature. There is no documentation of how a fullscreen shader should look like in URP, so ShaderGraph was the only sane option. Since the actual logic is quite complex, we used a custom node with an external .hlsl file. After some tweaking it all worked fine in the editor, but the issue arrived when testing the build. The fullscreen effect is completely absent.

    The camera is set up with the correct renderer, proven by an extra fullscreen feature (the default invert). So now the question is, how can I track if the shader made it into the build? I am not at all familiar with shader compilation, so any explanation would be welcomed.

    VariantCompilation.png

    AddressablesBuild.png

    The Addressables Layout Reporter only really signals the presence of .shadergraph, but no actual .shader. Which is what I would expect to be included in the binaries, as .shadergraph is only a proto shader.
    BundleLayout.png

    Yet for some reason the Player.log of the build still reports some Shader Compilation happening between scene transitions! This is the part that makes no sense to me... why are there variant compilations at build time AND at runtime?
    PlayerLog.png

    And finally another issue that I believe might have the same cause, is that some shadows are broken on basic assets with a standard URP/Lit shader. Again the Player.log reports that the gameobject is using "Hidden/InternalErrorShader" which it should absolutely not be.

    My best guess is that Shader Stripping is at the root of all this, but there are absolutely no errors reported at build time nor at runtime. I tried to deactivate stripping in Graphics settings, in the Render Pipeline Settings, putting the materials and shaders in a dedicated asset group, tried to move the function from a separate .hlsl file to be an inlined string in the shdergraph, to no avail.

    Again, I do not believe this to be a trivial setup issue, as everything works as expected in the Editor.
     
  2. BogdanM

    BogdanM

    Joined:
    Sep 3, 2017
    Posts:
    8
    After using the "Project Settings/Player/Strict shader variant matching" option, we were able to identify what variants are missing exactly, as they are not silently failing anymore. Still no missing variants are reported for the fullscreen shader.

    After more digging we uncovered that the source of the problem is that a fullscreen shader graph cannot sample a render texture correctly, but only on standalone AND if the shader in question is an addressable. If the texture is a static one, the issue is not present.

    The workaround was to make sure that the fullscreen material (and associated shader) has a hard reference in the one scene included in the build and no other indirect reference within the addressables system, so as to not be pulled into the Asset Bundle. It's not really a fix; I am confident there is some incompatibility between the 2 packages here... but we'll have to make do with the workaround.