Skip to content

2.21.2 — SPI shader auto-patching

Choose a tag to compare

@MrTactical MrTactical released this 26 Jul 11:43

Shaders that only draw into one eye can now be fixed automatically.

ChilloutVR renders single-pass instanced. VRChat renders double-wide single-pass. Both SDKs force their own mode, unconditionally — StereoRenderingPath.Instancing in the CCK's CCK_EnvConfig.cs, StereoRenderingPath.SinglePass in the VRChat SDK's EnvConfig.cs.

That difference is the whole problem. Under double-wide a shader receives both eyes without having to ask. Under instancing it has to declare that it knows which eye it's drawing — so a shader that never opted in looks entirely correct in VRChat and draws into one eye only in ChilloutVR. Nobody did anything wrong, and there's nothing to fix in the original project: converting is what exposes it. Which makes it exactly the sort of thing worth handling here.

The CCK flags these as potentially non-SPI. AvatarBridge now reports them too, and can repair the ones that are fixable mechanically — turn on Patch non-SPI shaders for VR in Advanced.

What it does

For each affected shader it writes a patched copy into RehomedAssets beside your converted avatar, adds the stereo macros, and points this avatar's materials at the copy.

Your original shader is never modified, and neither is the original material — both are copied, so other avatars sharing them are unaffected. These shaders usually aren't yours to edit.

A copy that doesn't compile is thrown away, and the original left exactly as it was. The worst case is a line in the report rather than wrong pixels.

Not everything can be patched. Surface shaders have no vertex stage to edit, locked and generated shaders can't be parsed, and structs living in a shared include can't be edited from one file. Those are listed in the report for hand-fixing or replacing, not quietly mangled.

There's nothing to undo. The macros are the mode-agnostic ones — they expand to real instancing code under ChilloutVR's mode and to nothing under VRChat's or on desktop. The patched copy is a valid shader on both platforms, not a ChilloutVR-only fork.

Passing the CCK's check isn't the same as being correct

The CCK looks for four macros. A shader can have all four and still be broken.

The shader that prompted this feature — KriptoFX/ME/Particle, a soft-particle effect — is exactly that case. It declares sampler2D _CameraDepthTexture and reads it with tex2Dproj, and under single-pass instanced that texture is an array. Add the four macros and validation goes green while the effect stays wrong.

So the patch makes six edits, not four, rewriting that pair to UNITY_DECLARE_DEPTH_TEXTURE and SAMPLE_DEPTH_TEXTURE_PROJ as well.

Why it's off by default

Compilation is the only thing that can be checked automatically. Whether the result looks right is a judgement no editor script can make. A patched shader is repairing something already broken in ChilloutVR, so the downside is small — but look at the effect in both eyes before you trust it.

Also in 2.21.x

  • One clone per material, not per slot. A material used by three renderers was being copied three times, producing byte-identical assets that no longer batched with each other.
  • Line endings in the patched file now match the source, so Unity stops warning about mixed endings and blaming AvatarBridge for a shader that imported fine.
  • Corrected in 2.21.2: 2.20.0's diagnostic and 2.21.0's notes claimed VRChat rendered the same way and that these shaders were "already broken there". That was backwards. It sent people looking for damage in their VRChat project that was never there.

Verified end to end on a 400k-triangle, 56-slot avatar: detected, patched, compiled, validated clean, built and uploaded.