暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MatrixShaderProperty.cs 1.7KB

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