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.
  2. Dismiss Notice

Bug No Shadows in Asset Bundles or Standalone builds!

Discussion in 'Universal Render Pipeline' started by funkyCoty, Apr 22, 2022.

  1. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    Hey there. We're currently developing a Quest 2 / PC title in URP. We're on Unity 2021.2.19f1, using URP 12.1.6.

    When building with Asset Bundles, it seems all shaders related to shadows are getting stripped from builds. If I go into the URP Global Settings and disable all shader stripping, the shadow-variants no longer get stripped, but of course then our builds take an enormous amount of time.

    I believe this is a URP bug, because our Quality settings for PC/Consoles has a separate URP Renderer Asset slotted in. To be safe, our default Graphics setting's URP Renderer is the PC version, which has shadows-variants enabled in the settings.

    We are using a lot of custom shaders and using a custom asset bundle managing solution, so maybe we're hitting something weird. But aside from disabling URP stripping entirely I haven't been able to get shadows in builds (they DO work in editor - unless I'm just loading asset bundles from the editor - in which case they also do not work, because it seems they've been stripped from bundles too).

    Is there any workaround for this that does not involve waiting hours for shaders to compile every time? Thanks.


    Some notes:
    • Looking in the Frame Debugger, shadows ARE rendering. However, all materials in the game are NOT sampling from them.
    • Despite the frame debugger claiming that the shader variant keywords are in use, they definitely are not because it does not show the shadowmap textures.

    URP Global Settings:

    Unity_COeFlbRTst.png

    Unity's Quality Settings
    Unity_1dlzCorH6s.png

    URP Renderer for PC quality:
    upload_2022-4-22_10-23-56.png
     
    Last edited: Apr 22, 2022
  2. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    Bug report submitted with our whole project: Case 1422243
     
  3. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
  4. emartino

    emartino

    Joined:
    Mar 1, 2019
    Posts:
    2
    Hello. Did you find a solution?
     
  5. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Due to how URP shader stripping works it, you have to have some URP asset and renderer data asset (with the settings you need for your shaders) assigned to either main graphics settings or quality levels overrides and have these assets available at the build time. I'm guessing these assets going into asset bundle (?) could make the shader preprocessor think they don't exist and it strips those variants away that you actually needed.

    So alternatives to fix this would be: have at least one URP asset + renderer data asset assigned at build time that use the shader features you need.

    Or use custom URP package that and modify it's ShaderPreProcessor.cs so it doesn't set shadow pass stripping to true on places where it checks that (there seems to be several places for those checks there).
     
  6. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    No, I submitted a bug ages ago but Unity has yet to actually do anything about it, it seems.

    I've ran over it a bunch of time but can't find anything that should cause it to be stripped from builds. Turning off stripping has been our temporary solution to getting shadows, but finding whats actually causing it to be stripped has been the pain point for sure.
     
  7. pfdaniel

    pfdaniel

    Joined:
    May 3, 2020
    Posts:
    14
    Any luck with this? We're facing the same issues - to solve it so far we've been adding hidden objects to our scenes that contain the necessary shaders... which isn't great obviously.
     
  8. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    Nope, I'm still waiting too!
     
  9. wtmsuperman

    wtmsuperman

    Joined:
    Jul 11, 2014
    Posts:
    8
    Same issue,I have tried add some lit materials to the shader bundle,not worked.
     
  10. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    They closed my bug report without actually fixing it. Wow.
     
  11. AetherMFP

    AetherMFP

    Joined:
    Feb 11, 2022
    Posts:
    28
    Can confirm this issue still exist even after 2022.2.5
     
  12. gotiobg

    gotiobg

    Joined:
    May 10, 2017
    Posts:
    19
    I had the same issue and the workaround you mentioned by disabling strip shaders worked for me, thank you. My build time didn't increase so I'll be using this for now.