Skip to content

Commit 161915f

Browse files
committed
Fix the stubborn matrix define compiler bug
1 parent a676571 commit 161915f

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/VFX/Config.template.hlsl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,12 @@ void BuildElementToWorld(VaryingsMeshType input)
202202

203203
void SetupVFXMatrices(AttributesElement element, inout VaryingsMeshType output)
204204
{
205+
// Due to a very stubborn compiler bug we cannot refer directly to the redefined UNITY_MATRIX_M / UNITY_MATRIX_I_M here, due to a rare case where the matrix alias
206+
// is potentially still the constant object matrices (thus complaining about l-value specifying const object). Note even judicious use of preprocessors seems to
207+
// fix it, so we instead we directly refer to the static matrices.
208+
205209
// Element -> World
206-
UNITY_MATRIX_M = GetElementToVFXMatrix(
210+
elementToWorld = GetElementToVFXMatrix(
207211
element.attributes.axisX,
208212
element.attributes.axisY,
209213
element.attributes.axisZ,
@@ -213,13 +217,13 @@ void SetupVFXMatrices(AttributesElement element, inout VaryingsMeshType output)
213217
element.attributes.position);
214218

215219
#if VFX_LOCAL_SPACE
216-
UNITY_MATRIX_M = mul(ApplyCameraTranslationToMatrix(GetRawUnityObjectToWorld()), UNITY_MATRIX_M);
220+
elementToWorld = mul(ApplyCameraTranslationToMatrix(GetRawUnityObjectToWorld()), elementToWorld);
217221
#else
218-
UNITY_MATRIX_M = ApplyCameraTranslationToMatrix(UNITY_MATRIX_M);
222+
elementToWorld = ApplyCameraTranslationToMatrix(elementToWorld);
219223
#endif
220224

221225
// World -> Element
222-
UNITY_MATRIX_I_M = GetVFXToElementMatrix(
226+
worldToElement = GetVFXToElementMatrix(
223227
element.attributes.axisX,
224228
element.attributes.axisY,
225229
element.attributes.axisZ,
@@ -230,22 +234,22 @@ void SetupVFXMatrices(AttributesElement element, inout VaryingsMeshType output)
230234
);
231235

232236
#if VFX_LOCAL_SPACE
233-
UNITY_MATRIX_I_M = mul(UNITY_MATRIX_I_M, ApplyCameraTranslationToInverseMatrix(GetRawUnityWorldToObject()));
237+
worldToElement = mul(worldToElement, ApplyCameraTranslationToInverseMatrix(GetRawUnityWorldToObject()));
234238
#else
235-
UNITY_MATRIX_I_M = ApplyCameraTranslationToInverseMatrix(UNITY_MATRIX_I_M);
239+
worldToElement = ApplyCameraTranslationToInverseMatrix(worldToElement);
236240
#endif
237241

238242
// Pack matrices into interpolator if requested by any node.
239243
#ifdef VARYINGS_NEED_ELEMENT_TO_WORLD
240-
output.elementToWorld0 = UNITY_MATRIX_M[0];
241-
output.elementToWorld1 = UNITY_MATRIX_M[1];
242-
output.elementToWorld2 = UNITY_MATRIX_M[2];
244+
output.elementToWorld0 = elementToWorld[0];
245+
output.elementToWorld1 = elementToWorld[1];
246+
output.elementToWorld2 = elementToWorld[2];
243247
#endif
244248

245249
#ifdef VARYINGS_NEED_WORLD_TO_ELEMENT
246-
output.worldToElement0 = UNITY_MATRIX_I_M[0];
247-
output.worldToElement1 = UNITY_MATRIX_I_M[1];
248-
output.worldToElement2 = UNITY_MATRIX_I_M[2];
250+
output.worldToElement0 = worldToElement[0];
251+
output.worldToElement1 = worldToElement[1];
252+
output.worldToElement2 = worldToElement[2];
249253
#endif
250254
}
251255

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/VFX/FragInputsDeclaration.template.hlsl.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)