A game about forced loneliness, made by TACStudios
1using System;
2using UnityEditor.ShaderGraph.Internal;
3using UnityEngine;
4
5namespace UnityEditor.ShaderGraph
6{
7 [Serializable]
8 abstract class MatrixShaderProperty : AbstractShaderProperty<Matrix4x4>
9 {
10 internal override bool isExposable => false;
11 internal override bool isRenamable => true;
12
13 internal override string GetHLSLVariableName(bool isSubgraphProperty, GenerationMode mode)
14 {
15 HLSLDeclaration decl = GetDefaultHLSLDeclaration();
16 if (decl == HLSLDeclaration.HybridPerInstance)
17 return $"UNITY_ACCESS_HYBRID_INSTANCED_PROP({referenceName}, {concretePrecision.ToShaderString()}4x4)";
18 else
19 return base.GetHLSLVariableName(isSubgraphProperty, mode);
20 }
21
22 internal override HLSLDeclaration GetDefaultHLSLDeclaration()
23 {
24 if (overrideHLSLDeclaration)
25 return hlslDeclarationOverride;
26
27 // Since Matrices cannot be exposed, the default declaration rules would set them to Global.
28 // However, this means new Matrix properties would be different from all other float-based property types
29 // (all others use UnityPerMaterial by default, because they are exposed).
30 // So instead, we override the default rules so that Matrices always default to UnityPerMaterial
31 return HLSLDeclaration.UnityPerMaterial;
32 }
33
34 internal override void ForeachHLSLProperty(Action<HLSLProperty> action)
35 {
36 HLSLDeclaration decl = GetDefaultHLSLDeclaration();
37
38 // HLSL decl is always 4x4 even if matrix smaller
39 action(new HLSLProperty(HLSLType._matrix4x4, referenceName, decl, concretePrecision));
40 }
41 }
42}