Search Unity

Adding shaders from mods

Discussion in 'Shaders' started by pardeike, Jun 18, 2017.

  1. pardeike

    pardeike

    Joined:
    Oct 27, 2016
    Posts:
    6
    Hi,

    I have several mods (dlls that are loaded by the main unity game) in Rimworld. I now want to use my own custom shaders but I have not been able to get them into the game at runtime. What I don't want to do is to modify the original game directory because it just leads to problems.

    So the question is: is it possible to add custom shaders in any way from a dll that is not part of the original game?

    Rimworld uses Unity 5.4.1f1.

    Thankful for any help or pointers into the right direction,
    Andreas Pardeike
     
  2. LukasCh

    LukasCh

    Unity Technologies

    Joined:
    Mar 9, 2015
    Posts:
    102
    Hey, the only way how you can add shader at runtime is by asset bundles. Any way I'm curious why you want to add them at runtime?
     
  3. pardeike

    pardeike

    Joined:
    Oct 27, 2016
    Posts:
    6
    Rimworld has extensive support for loading custom dlls (mods). Extending the game is almost limitless and now I want to have a few effects that require a shader that is not build into the core game. One of them is for example a deep mask shader (http://wiki.unity3d.com/index.php?title=DepthMask) and I also want to add other effects.

    I am not trying to hack a Unity game. Mods are an important part of content for the main game, in case you wonder.

    I tried asset bundles but it seems that these are cumulative and since I don’t have access to the originals games Unity project I could not get them to load at all. Can you describe this in more detail or point me to an example/tutorial?
     
  4. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    As far as I know, that actually doesn't work. Like with scripts, the variables are deserialized from the assetbundle, but the actual code is not loaded from the assetbundle, but from the project itself. I assume this is to prevent being able to load in arbitrary code and executing it.

    TLDR: You can load materials from an assetbundle, but no shaders.
     
  5. LukasCh

    LukasCh

    Unity Technologies

    Joined:
    Mar 9, 2015
    Posts:
    102
    Shaders should also work.

    I made small example, where shaders are loaded from asset bundle. Build player in project folder as it uses relative path to find in Assets/AssetBundles/myassetbundle.
     

    Attached Files:

  6. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Hey @LukasCh. Should it also work if your shader is not in your project, so only known from the assetbundle?

    We currently have the problem that it doesn't work for us, unfortunately. In our case, we have two projects: one client project and one assetbundle project. The shaders we create should only be available in the assetbundle project and then be delivered via the assetbundles. When the client downloads the assetbundle, the fallback shader is used, though the material is correct.

    When viewing it via the frame debugger, I can see that the wrong shader is assigned.

    Here's the frame debugger screenshot from the assetbundle project:

    shader_assetbundle_project.png

    Here's the one from the client:

    shader_client.png

    If you say that it should work, I'll create a small reproduction project to check if we may do something wrong. If it shouldn't work at all, would it be possible at all what we try to achieve?

    Thanks,
    Patrick
     
  7. LukasCh

    LukasCh

    Unity Technologies

    Joined:
    Mar 9, 2015
    Posts:
    102
    @pahe This should work. Just make sure that unity versions are same both on client and server. Also it should include all variants, because server might not include the one that client requires.

    If it doesn't work you can try create the bug for it and post here, I could take a look at it. BTW try to remove fallback, it might print some sensible error.
     
    pahe likes this.
  8. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Hey LukasCh.
    We created a small test project and we can confirm that it works there, so there's a problem anywhere in our working project then. We'll remove the fallback shader and check if that fixes the problem then.

    Thx.
     
    LukasCh likes this.