Search Unity

AssetBundles are Causing Issues with Realtime Shadows and Terrain

Discussion in 'Editor & General Support' started by minibeaststudios, Sep 13, 2019.

  1. minibeaststudios

    minibeaststudios

    Joined:
    Aug 9, 2017
    Posts:
    35
    I've had to switch my project over to utilize AssetBundles, which I've managed to get working really well - however one sticking point is that the realtime shadows that are cast on my Terrain assets are now completely messed up.

    If I run the game in the Editor (still using AssetBundles, none of the gameplay scenes are included in Build Settings) then the shadows appear as they should do. If I run off a build and run Standalone however shadows become broken - appearing massive and covering most of the scene. There's a picture of the issue here.


    Some things to note about my setup:
    • Using Unity 2017.4.30f1
    • I'm using Unity Terrain
    • I am not using any kind of lightmaps / baked lighting
    • I'm using the default Built in Standard Terrain Material / Shader
    • In Project > Graphics Settings I have included Nature/Terrain/Standard and Nature/Terrain/Diffuse shaders
    • I'm utilizing Occlusion Culling, with the Static property applied to the terrain
    • I use the following BuildPipeline settings:

    Code (CSharp):
    1. BuildAssetBundles(@"pathstring", BuildAssetBundleOptions.DeterministicAssetBundle | BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.StandaloneWindows64);

    Happy to provide more details if needed.

    ps. Tagging @Ryanc_unity - aka AssetBundles-Wan Kenobi
     
    Last edited: Sep 14, 2019
  2. minibeaststudios

    minibeaststudios

    Joined:
    Aug 9, 2017
    Posts:
    35
    UPDATE: I tried changing the Terrain's shader to something different (I picked a Mobile Diffuse shader, which isn't appropriate but just as test) and all shadows were being cast as expected on the Terrain. So it's something to do with the shader, or rather how AssetBundles are handling the specific shader in Builds.


    I'm continuing to search for a solution to this problem, but if anyone has overcome this already or can identify the root cause I'd really appreciate your input.
     
  3. minibeaststudios

    minibeaststudios

    Joined:
    Aug 9, 2017
    Posts:
    35
    UPDATE #2: And the problem has been resolved! It's a non-platform specific issue, and seems to be that a shader (or more) that the Built In Terrain Shader relies on wasn't being included in the build, or was being stripped at runtime.

    I had to do the following to make it work (this may be overkill as it could require just a single specific shader, but this is working for me)

    1) Downloaded the Built In Shaders for my version of Unity from here: https://unity3d.com/get-unity/download/archive
    2) Extracted the files and then located the shaders I needed in Builtin Shaders\DefaultResourcesExtra\TerrainShaders\Splats
    3) Imported them into my Unity project
    4) Added them to my Always Included Shaders list (here's a screenshot of what that now looks like - the blue brackets indicate what I had been including before, the red ones are the additions I've made which resolved the problem)

    Shadows are now being correctly rendered on the Terrain!