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

Global RenderSettings not working when loading scene from AssetBundle

Discussion in 'General Graphics' started by sbsmith, Jan 3, 2020.

  1. sbsmith

    sbsmith

    Joined:
    Feb 7, 2013
    Posts:
    113
    My game renders differently depending on if asset bundles are enabled. Both of these screenshots are taken in the editor.

    The first has all scenes included in the build settings. The second loads scenes from asset bundles.
    WithoutAssetBundles.PNG WithAssetBundles.PNG

    The general setup is that a control scene (the little bit of desk visible in the background on the left) loads additional scenes dynamically (the stuff within the picture). A custom camera manager changes RenderSettings before the dynamic scenes are drawn.

    The dynamic scenes have their lighting setups stored in a separate object. In the camera pre-cull, I set the global RenderSettings I want for ambient light and fog. I have verified in the script debugger that the values are being assigned, so they are being correctly stored in the bundle. I don't know why the effects aren't visible though.

    Any insight would be much appreciated.
     
    DaveL99 likes this.
  2. sbsmith

    sbsmith

    Joined:
    Feb 7, 2013
    Posts:
    113
    Ooooh, this seems to be something to do with shader stripping. When I turn the fog to manual in the graphics settings it comes back. The ambient light still isn't there. I'm not sure what setting affects that.
    ManualFog.JPG
     
  3. sbsmith

    sbsmith

    Joined:
    Feb 7, 2013
    Posts:
    113
    I will attempt to update this later but the cause seems to be the related to what bundle the material, shader, and objects are stored in.
     
  4. DaveL99

    DaveL99

    Joined:
    Jul 5, 2018
    Posts:
    22
    Interesting. I have experienced very similar problems, but sadly haven't managed to *properly* figure out what is wrong. I found that certain objects in my 3D world would not receive ambient lighting - but only when the scene containing the lights was loaded from an asset bundle at runtime. When loaded additively in the editor everything was fine. I found a workaround, which was that as long as my lighting scene contained at least one light-probe then it appeared to behave the same in both cases.

    However, then much later on I decided to try baked lightmaps in my environment, rather than just real-time ones. Same problem then re-occured but this time I couldn't find any quick 'n' easy way of fixing it. In my case baked lightmaps didn't really add enough benefit to keep digging, so I just reverted it.
     
  5. sbsmith

    sbsmith

    Joined:
    Feb 7, 2013
    Posts:
    113
    I could not identify the exact problem. My workaround for the foreground trees was to give them their own shader and materials that were bundled with the specific scene. It's a hack but it worked. Regarding my strategy of setting global light parameters in the pre-cull, it has some drawbacks. It doesn't seem to always work properly. This happened if different scenes had different techniques for ambient light. For example, if one used colour while another used skybox. I converted them all to colour. I've had additional problems where the smoothness factor of surfaces simply wouldn't work in bundles and I was just able to hack the shaders to get "close enough" to the intended effect. To compound the difficulty in figuring this out, I'm often using the bundles on systems with different hardware (mobile and consoles). Also, nearly everything on screen does a stencil test before rendering a pixel and can cause unexpected results (see: https://forum.unity.com/threads/why...-the-caster-is-stenciled.800673/#post-5332749). Long story short. I solved the problem but don't have a precise solution to help people that stumble on this later.