You can't load a shader directly in-game, you need to compile it first. And for that, you need unity with exactly the same version as the one which Streets of Rogue uses.
Go to Unity download archive and download there version 2020.3.23f1
(Unity hub may ask you for license, just select "personal")
Now, create new empty project in unity. Create there folder "Editor", and put there this file.
Now, create your shader. You need to know HLSL to write it, and you can try looking at existing shaders.
Then, select New > Material
, and select your shader as material's shader.
In inspector, below material's properties, there should be two fields with None
value.
First one can be anything, that's the name of the asset bundle you'll load in-game. Second one must be .assets
After that, right click anywhere in file viewer, and select "Build AssetBundles". If you did Add builder
step correctly, it should appear.
Just select your bundle, and it'll be built.
After your bundle was builded, it should appear in Assets/AssetBundles
.
You can drag it from unity to file explorer. Put it somewhere in your mod, and add that resource, just like any sprite you add.
See more about loading sprites here
To use your shader, you need to load it.
private Material? material;public IEnumerator Start(){ AssetBundleCreateRequest req = AssetBundle.LoadFromMemoryAsync(Properties.Resources.CrispyBundle); yield return req; material = req.assetBundle.LoadAsset<Material>("<Name of your material>");}
Then use that material somehow.
[BepInEx.BepInPlugin(@"abbysssal.streetsofrogue.crispymod", "S&S: Crispy Mod", "1.0.0")]public class CrispyPlugin : BepInEx.BaseUnityPlugin{ public void Awake() { Harmony harmony = new Harmony(Info.Metadata.GUID); harmony.Patch(AccessTools.Method(typeof(CameraScript), nameof(CameraScript.RealStart)), null, new HarmonyMethod(AccessTools.Method(typeof(CrispyPlugin), nameof(AttachCrispyScript)))); } public static void AttachCrispyScript(CameraScript __instance) { GameObject go = __instance.GetComponentInChildren<Camera>().gameObject; _ = go.GetComponent<CrispyScript>() ?? go.AddComponent<CrispyScript>(); }}public class CrispyScript : MonoBehaviour{ private float brightness = 1.5f; private float saturation = 2f; private float contrast = 2f; private Material? material; public IEnumerator Start() { AssetBundleCreateRequest req = AssetBundle.LoadFromMemoryAsync(Properties.Resources.CrispyBundle); yield return req; material = req.assetBundle.LoadAsset<Material>("CrispyMaterial"); } public void Update() { if (Input.GetKeyDown(KeyCode.Insert)) brightness += 0.1f; if (Input.GetKeyDown(KeyCode.Delete)) brightness -= 0.1f; if (Input.GetKeyDown(KeyCode.Home)) saturation += 0.1f; if (Input.GetKeyDown(KeyCode.End)) saturation -= 0.1f; if (Input.GetKeyDown(KeyCode.PageUp)) contrast += 0.1f; if (Input.GetKeyDown(KeyCode.PageDown)) contrast -= 0.1f; } public void OnRenderImage(RenderTexture src, RenderTexture dest) { if (material is not null && material) { material.SetFloat("_Brightness", brightness); material.SetFloat("_Saturation", saturation); material.SetFloat("_Contrast", contrast); Graphics.Blit(src, dest, material); } else Graphics.Blit(src, dest); }}