Skip to content

fix: restore DOTS-instanced material props and Unity 6000.5 shader compat - #95

Open
eordano wants to merge 1 commit into
mainfrom
fix/unity-6000.5-shader-compat
Open

fix: restore DOTS-instanced material props and Unity 6000.5 shader compat#95
eordano wants to merge 1 commit into
mainfrom
fix/unity-6000.5-shader-compat

Conversation

@eordano

@eordano eordano commented Jul 20, 2026

Copy link
Copy Markdown
Member

Three independent shader fixes, all surfaced by compiling the DOTS-instancing (*_INSTANCING_ON) variants that editor compiles skip and player builds do not. The first is a live bug on main today, independent of any Unity upgrade.

1. UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO no longer exists

Scene/URP/LitInput.hlsl and Scene/URP/UnlitInput.hlsl define every instanced material property through UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(...). That macro is not defined anywhere in the URP we currently ship — the only references to it in the whole package tree are these two files. Unity removed it when the override-mode system landed; the surviving macro is

// com.unity.render-pipelines.core/ShaderLibrary/UnityDOTSInstancing.hlsl:154
#define UNITY_ACCESS_DOTS_INSTANCED_PROP(type, var) ( /* Compile-time branches */ \
UNITY_DOTS_INSTANCED_PROP_IS_OVERRIDE_ENABLED(var) ? LoadDOTSInstancedData_##type(UNITY_DOTS_INSTANCED_METADATA_NAME(type, var)) \
: UNITY_DOTS_INSTANCED_PROP_IS_OVERRIDE_REQUIRED(var) ? LoadDOTSInstancedDataOverridden_##type(UNITY_DOTS_INSTANCED_METADATA_NAME(type, var)) \
: ((type)0) )

It also takes a different argument: the bare property name, composing the metadata symbol itself via UNITY_DOTS_INSTANCED_METADATA_NAME. So the call sites move from (float4, Metadata__BaseColor) to (float4, _BaseColor) — the Metadata_ prefix is dropped, not just the macro renamed.

This is why it only shows up in player builds: nothing compiles those defines until UNITY_DOTS_INSTANCING_ENABLED is set.

Codegen is unchanged. Both predicates compare static const int values, so the ternaries fold at compile time and the emitted code is a single LoadDOTSInstancedData_##type(metadata) — exactly what the old spelling produced. No extra load, no runtime branch, no register pressure.

Why the plain macro and not _WITH_DEFAULT: the two differ only when the override mode is disabled, where plain yields ((type)0) and _WITH_DEFAULT yields the CBUFFER value. UNITY_DOTS_INSTANCED_PROP expands to ..._OVERRIDE_SUPPORTED unless UNITY_DOTS_INSTANCED_PROP_OVERRIDE_DISABLED_BY_DEFAULT is defined, and we never define it — so IS_OVERRIDE_ENABLED is true and the load branch is taken. Plain is correct here.

2. unity_ObjectToWorld -> GetObjectToWorldMatrix()

Four call sites across Avatar_CelShading_DepthNormalsPass, DCL_ToonHighlight and DCL_ToonOutline. GetObjectToWorldMatrix() is UNITY_MATRIX_M, which under BRG/DOTS instancing resolves to the instanced matrix instead of the raw builtin. Same matrix load, no added cost — a correctness fix for the instanced variants, where the builtin is not the right source.

3. DCL_ToonOutline instance ID plumbing

frag already called UNITY_SETUP_INSTANCE_ID(i) on a VertexOutput that never carried an instance ID. Adds UNITY_VERTEX_INPUT_INSTANCE_ID to the struct and UNITY_TRANSFER_INSTANCE_ID(v, o) in vert, completing a contract that was already half-written. Cost is one extra interpolator, and only under instancing — UNITY_VERTEX_INPUT_INSTANCE_ID compiles to nothing otherwise.

4. URP 17.5 LitInput collision (the 6000.5 item)

Unity 6000.5's URP added #include "LitInput.hlsl" to LitForwardPass.hlsl, pulling ShaderLibrary/SurfaceInput.hlsl into the one DCL translation unit that includes URP's real LitForwardPass (DCL_Toon ForwardLit) — colliding with DCL_ToonInput.hlsl (_BaseMap, Alpha, UnityPerMaterial members) and rendering avatars magenta.

Pre-claims URP's UNIVERSAL_LIT_INPUT_INCLUDED guard so the new self-include no-ops (the same guard-reuse pattern this repo already uses in Scene/URP/LitInput.hlsl), and inlines the parameterless IsSurfaceTypeTransparent() that 6000.5's LitForwardPass calls — under the real file's own guard, since Shaders/Utils/SurfaceType.hlsl does not exist in 6000.4's URP. With _Surface defined 0.0f it returns false, matching 6000.4 behaviour exactly.

Verification

Both editors, zero errors and zero shader errors:

  • unity-explorer dev on Unity 6000.4.0f1 — editor and macOS player build
  • unity-explorer #9392 on Unity 6000.5.4f1 — editor, macOS player build, and in-world visual check (avatars correctly toon-shaded)
  • StandaloneWindows64 / d3d11 full player build on 6000.5.4f1 — 0 shader errors, 0 CS errors across 132k log lines, Explorer.exe produced. DCL_Toon ForwardLit, DCL/Scene, and all DOTS-instancing variants compiled clean.

@github-actions

Copy link
Copy Markdown

🔗 Merge Alignment Reminder

If this PR targets main, please make sure the corresponding changes in unity-explorer are also ready to merge.

Both repos should be merged in coordination to avoid breaking changes. Do not merge one without the other being ready.

- DCL_Toon ForwardLit: claim UNIVERSAL_LIT_INPUT_INCLUDED, inline
  IsSurfaceTypeTransparent (6000.4 URP has no SurfaceType.hlsl).
- Toon outline/highlight and CelShading depth-normals: GetObjectToWorldMatrix
  instead of unity_ObjectToWorld; carry the instance id into the toon
  outline fragment stage.
- Scene URP Lit/Unlit input: UNITY_ACCESS_DOTS_INSTANCED_PROP replaces the
  removed _FROM_MACRO accessor.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@eordano
eordano force-pushed the fix/unity-6000.5-shader-compat branch from 5261933 to 952a977 Compare July 27, 2026 14:37
@eordano eordano changed the title fix: keep URP 17.5 LitInput out of the DCL_Toon ForwardLit pass fix: restore DOTS-instanced material props and Unity 6000.5 shader compat Jul 30, 2026
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