Skip to content

Conversation

legoandmars
Copy link

It's not feasible to decompile custom shaders such as the posterization shader, which means they're very difficult to use in editor.
YAML shaders might work, but are buggy/unstable and won't work in a build.

I present a new (slightly scuffed) method of using the base game's custom shaders, one that supports:

  • Editor
  • Editor play mode
  • Builds

Here's how it works:

An additional pass is added that uses AssetsTools.NET to extract the compiled shader objects from the game.

After getting these objects, we create a new AssetBundle in-editor using a dummy shader. Once the AssetBundle is compiled, we use AssetsTools.NET to swap out the dummy shader for our base game custom shader, then recompile the AssetBundle.

This will create a seperate AssetBundle for each base game shader in the StreamingAssets/ShaderInjections folder.

These AssetBundle shaders can then be used as normal shaders until one of the following happens:

  • You relaunch the editor
  • You save a scene in which the materials are present

I have included patches that automatically replace the shader with the correct one when both of these events happen, making the shader look seamless from the perspective of the user.

Problems

I am not 1000% sure well how this works long term, or if there's any stability issues. I haven't run into any big problems, but the only way to know for sure is to have somebody use this in their project while doing complicated tasks for a long period of time.

Runtime/Patches/CustomPassRuntimePatch.cs should probably be replaced with something that happens at project extraction time.

Ideally this would use AssetRipper instead of AssetsTools.NET to avoid adding more dependencies, but I am not super familiar with AssetRipper or how that would be made.

@legoandmars legoandmars changed the base branch from v0.4.0 to master February 17, 2024 03:28
@legoandmars
Copy link
Author

more notes:

  • The HoloGramShader should work now, but the animation is broken due to a bad reference to the Volume (you can view the animation clip to see what I mean)
  • The bee shader could work if we got VisualEffect extraction working, but I'm not sure how realistic that is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant