VFXExpressionTextureDim.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Linq;
  3. using System.Runtime.CompilerServices;
  4. using UnityEngine;
  5. using UnityEngine.VFX;
  6. namespace UnityEditor.VFX
  7. {
  8. class VFXExpressionTextureWidth : VFXExpression
  9. {
  10. public VFXExpressionTextureWidth() : this(VFXTexture2DValue.Default)
  11. { }
  12. public VFXExpressionTextureWidth(VFXExpression texture)
  13. : base(Flags.InvalidOnGPU, new VFXExpression[1] { texture })
  14. { }
  15. sealed public override VFXExpressionOperation operation { get { return VFXExpressionOperation.TextureWidth; } }
  16. sealed public override VFXValueType valueType { get { return VFXValueType.Uint32; } }
  17. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  18. {
  19. var tex = constParents[0].Get<Texture>();
  20. return VFXValue.Constant<uint>(tex ? (uint)tex.width : 0u);
  21. }
  22. }
  23. class VFXExpressionTextureHeight : VFXExpression
  24. {
  25. public VFXExpressionTextureHeight() : this(VFXTexture2DValue.Default)
  26. { }
  27. public VFXExpressionTextureHeight(VFXExpression texture)
  28. : base(Flags.InvalidOnGPU, new VFXExpression[1] { texture })
  29. { }
  30. sealed public override VFXExpressionOperation operation { get { return VFXExpressionOperation.TextureHeight; } }
  31. sealed public override VFXValueType valueType { get { return VFXValueType.Uint32; } }
  32. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  33. {
  34. var tex = constParents[0].Get<Texture>();
  35. return VFXValue.Constant<uint>(tex ? (uint)tex.height : 0u);
  36. }
  37. }
  38. class VFXExpressionTextureDepth : VFXExpression
  39. {
  40. public VFXExpressionTextureDepth() : this(VFXTexture2DValue.Default)
  41. { }
  42. public VFXExpressionTextureDepth(VFXExpression texture)
  43. : base(Flags.InvalidOnGPU, new VFXExpression[1] { texture })
  44. { }
  45. sealed public override VFXExpressionOperation operation { get { return VFXExpressionOperation.TextureDepth; } }
  46. sealed public override VFXValueType valueType { get { return VFXValueType.Uint32; } }
  47. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  48. {
  49. var tex = constParents[0].Get<Texture>();
  50. uint depth = 0u;
  51. if (tex != null)
  52. {
  53. if (tex is Texture3D)
  54. depth = (uint)((Texture3D)tex).depth;
  55. else if (tex is Texture2DArray)
  56. depth = (uint)((Texture2DArray)tex).depth;
  57. else if (tex is CubemapArray)
  58. depth = (uint)((CubemapArray)tex).cubemapCount;
  59. else
  60. depth = 1u;
  61. }
  62. return VFXValue.Constant<uint>(depth);
  63. }
  64. }
  65. }