VFXExpressionCamera.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 VFXExpressionExtractMatrixFromMainCamera : VFXExpression
  9. {
  10. public VFXExpressionExtractMatrixFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
  11. {
  12. }
  13. public override VFXExpressionOperation operation
  14. {
  15. get
  16. {
  17. return VFXExpressionOperation.ExtractMatrixFromMainCamera;
  18. }
  19. }
  20. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  21. {
  22. if (Camera.main != null)
  23. return VFXValue.Constant(Camera.main.cameraToWorldMatrix);
  24. else
  25. return VFXValue.Constant(CameraType.defaultValue.transform);
  26. }
  27. }
  28. class VFXExpressionExtractFOVFromMainCamera : VFXExpression
  29. {
  30. public VFXExpressionExtractFOVFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
  31. {
  32. }
  33. public override VFXExpressionOperation operation
  34. {
  35. get
  36. {
  37. return VFXExpressionOperation.ExtractFOVFromMainCamera;
  38. }
  39. }
  40. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  41. {
  42. if (Camera.main != null)
  43. return VFXValue.Constant(Camera.main.fieldOfView * Mathf.Deg2Rad);
  44. else
  45. return VFXValue.Constant(CameraType.defaultValue.fieldOfView);
  46. }
  47. }
  48. class VFXExpressionExtractNearPlaneFromMainCamera : VFXExpression
  49. {
  50. public VFXExpressionExtractNearPlaneFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
  51. {
  52. }
  53. public override VFXExpressionOperation operation
  54. {
  55. get
  56. {
  57. return VFXExpressionOperation.ExtractNearPlaneFromMainCamera;
  58. }
  59. }
  60. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  61. {
  62. if (Camera.main != null)
  63. return VFXValue.Constant(Camera.main.nearClipPlane);
  64. else
  65. return VFXValue.Constant(CameraType.defaultValue.nearPlane);
  66. }
  67. }
  68. class VFXExpressionExtractFarPlaneFromMainCamera : VFXExpression
  69. {
  70. public VFXExpressionExtractFarPlaneFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
  71. {
  72. }
  73. public override VFXExpressionOperation operation
  74. {
  75. get
  76. {
  77. return VFXExpressionOperation.ExtractFarPlaneFromMainCamera;
  78. }
  79. }
  80. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  81. {
  82. if (Camera.main != null)
  83. return VFXValue.Constant(Camera.main.farClipPlane);
  84. else
  85. return VFXValue.Constant(CameraType.defaultValue.farPlane);
  86. }
  87. }
  88. class VFXExpressionExtractAspectRatioFromMainCamera : VFXExpression
  89. {
  90. public VFXExpressionExtractAspectRatioFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
  91. {
  92. }
  93. public override VFXExpressionOperation operation
  94. {
  95. get
  96. {
  97. return VFXExpressionOperation.ExtractAspectRatioFromMainCamera;
  98. }
  99. }
  100. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  101. {
  102. if (Camera.main != null)
  103. return VFXValue.Constant(Camera.main.aspect);
  104. else
  105. return VFXValue.Constant(CameraType.defaultValue.aspectRatio);
  106. }
  107. }
  108. class VFXExpressionExtractPixelDimensionsFromMainCamera : VFXExpression
  109. {
  110. public VFXExpressionExtractPixelDimensionsFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
  111. {
  112. }
  113. public override VFXExpressionOperation operation
  114. {
  115. get
  116. {
  117. return VFXExpressionOperation.ExtractPixelDimensionsFromMainCamera;
  118. }
  119. }
  120. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  121. {
  122. if (Camera.main != null)
  123. return VFXValue.Constant(new Vector2(Camera.main.pixelWidth, Camera.main.pixelHeight));
  124. else
  125. return VFXValue.Constant(CameraType.defaultValue.pixelDimensions);
  126. }
  127. }
  128. class VFXExpressionGetBufferFromMainCamera : VFXExpression
  129. {
  130. public VFXExpressionGetBufferFromMainCamera() : this(VFXCameraBufferTypes.None)
  131. { }
  132. public VFXExpressionGetBufferFromMainCamera(VFXCameraBufferTypes bufferType) : base(VFXExpression.Flags.InvalidOnGPU)
  133. {
  134. m_BufferType = bufferType;
  135. }
  136. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.GetBufferFromMainCamera; } }
  137. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents) { return VFXValue.Constant<Texture2DArray>(null); }
  138. protected override VFXExpression Reduce(VFXExpression[] reducedParents)
  139. {
  140. var newExpression = (VFXExpressionGetBufferFromMainCamera)base.Reduce(reducedParents);
  141. newExpression.m_BufferType = m_BufferType;
  142. return newExpression;
  143. }
  144. protected override int[] additionnalOperands { get { return new int[] { (int)m_BufferType }; } }
  145. private VFXCameraBufferTypes m_BufferType;
  146. }
  147. class VFXExpressionIsMainCameraOrthographic : VFXExpression
  148. {
  149. public VFXExpressionIsMainCameraOrthographic() : base(VFXExpression.Flags.InvalidOnGPU)
  150. {
  151. }
  152. public override VFXExpressionOperation operation
  153. {
  154. get
  155. {
  156. return VFXExpressionOperation.IsMainCameraOrthographic;
  157. }
  158. }
  159. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  160. {
  161. if (Camera.main != null)
  162. return VFXValue.Constant(Camera.main.orthographic);
  163. else
  164. return VFXValue.Constant(false);
  165. }
  166. }
  167. class VFXExpressionGetOrthographicSizeFromMainCamera : VFXExpression
  168. {
  169. public VFXExpressionGetOrthographicSizeFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
  170. {
  171. }
  172. public override VFXExpressionOperation operation
  173. {
  174. get
  175. {
  176. return VFXExpressionOperation.GetOrthographicSizeFromMainCamera;
  177. }
  178. }
  179. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  180. {
  181. if (Camera.main != null)
  182. return VFXValue.Constant(Camera.main.orthographicSize);
  183. else
  184. return VFXValue.Constant(CameraType.defaultValue.orthographicSize);
  185. }
  186. }
  187. }