123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- using System;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using UnityEngine;
- using UnityEngine.VFX;
- namespace UnityEditor.VFX
- {
- class VFXExpressionExtractMatrixFromMainCamera : VFXExpression
- {
- public VFXExpressionExtractMatrixFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
- {
- }
- public override VFXExpressionOperation operation
- {
- get
- {
- return VFXExpressionOperation.ExtractMatrixFromMainCamera;
- }
- }
- sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
- {
- if (Camera.main != null)
- return VFXValue.Constant(Camera.main.cameraToWorldMatrix);
- else
- return VFXValue.Constant(CameraType.defaultValue.transform);
- }
- }
- class VFXExpressionExtractFOVFromMainCamera : VFXExpression
- {
- public VFXExpressionExtractFOVFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
- {
- }
- public override VFXExpressionOperation operation
- {
- get
- {
- return VFXExpressionOperation.ExtractFOVFromMainCamera;
- }
- }
- sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
- {
- if (Camera.main != null)
- return VFXValue.Constant(Camera.main.fieldOfView * Mathf.Deg2Rad);
- else
- return VFXValue.Constant(CameraType.defaultValue.fieldOfView);
- }
- }
- class VFXExpressionExtractNearPlaneFromMainCamera : VFXExpression
- {
- public VFXExpressionExtractNearPlaneFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
- {
- }
- public override VFXExpressionOperation operation
- {
- get
- {
- return VFXExpressionOperation.ExtractNearPlaneFromMainCamera;
- }
- }
- sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
- {
- if (Camera.main != null)
- return VFXValue.Constant(Camera.main.nearClipPlane);
- else
- return VFXValue.Constant(CameraType.defaultValue.nearPlane);
- }
- }
- class VFXExpressionExtractFarPlaneFromMainCamera : VFXExpression
- {
- public VFXExpressionExtractFarPlaneFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
- {
- }
- public override VFXExpressionOperation operation
- {
- get
- {
- return VFXExpressionOperation.ExtractFarPlaneFromMainCamera;
- }
- }
- sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
- {
- if (Camera.main != null)
- return VFXValue.Constant(Camera.main.farClipPlane);
- else
- return VFXValue.Constant(CameraType.defaultValue.farPlane);
- }
- }
- class VFXExpressionExtractAspectRatioFromMainCamera : VFXExpression
- {
- public VFXExpressionExtractAspectRatioFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
- {
- }
- public override VFXExpressionOperation operation
- {
- get
- {
- return VFXExpressionOperation.ExtractAspectRatioFromMainCamera;
- }
- }
- sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
- {
- if (Camera.main != null)
- return VFXValue.Constant(Camera.main.aspect);
- else
- return VFXValue.Constant(CameraType.defaultValue.aspectRatio);
- }
- }
- class VFXExpressionExtractPixelDimensionsFromMainCamera : VFXExpression
- {
- public VFXExpressionExtractPixelDimensionsFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
- {
- }
- public override VFXExpressionOperation operation
- {
- get
- {
- return VFXExpressionOperation.ExtractPixelDimensionsFromMainCamera;
- }
- }
- sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
- {
- if (Camera.main != null)
- return VFXValue.Constant(new Vector2(Camera.main.pixelWidth, Camera.main.pixelHeight));
- else
- return VFXValue.Constant(CameraType.defaultValue.pixelDimensions);
- }
- }
- class VFXExpressionGetBufferFromMainCamera : VFXExpression
- {
- public VFXExpressionGetBufferFromMainCamera() : this(VFXCameraBufferTypes.None)
- { }
- public VFXExpressionGetBufferFromMainCamera(VFXCameraBufferTypes bufferType) : base(VFXExpression.Flags.InvalidOnGPU)
- {
- m_BufferType = bufferType;
- }
- public override VFXExpressionOperation operation { get { return VFXExpressionOperation.GetBufferFromMainCamera; } }
- sealed protected override VFXExpression Evaluate(VFXExpression[] constParents) { return VFXValue.Constant<Texture2DArray>(null); }
- protected override VFXExpression Reduce(VFXExpression[] reducedParents)
- {
- var newExpression = (VFXExpressionGetBufferFromMainCamera)base.Reduce(reducedParents);
- newExpression.m_BufferType = m_BufferType;
- return newExpression;
- }
- protected override int[] additionnalOperands { get { return new int[] { (int)m_BufferType }; } }
- private VFXCameraBufferTypes m_BufferType;
- }
- class VFXExpressionIsMainCameraOrthographic : VFXExpression
- {
- public VFXExpressionIsMainCameraOrthographic() : base(VFXExpression.Flags.InvalidOnGPU)
- {
- }
- public override VFXExpressionOperation operation
- {
- get
- {
- return VFXExpressionOperation.IsMainCameraOrthographic;
- }
- }
- sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
- {
- if (Camera.main != null)
- return VFXValue.Constant(Camera.main.orthographic);
- else
- return VFXValue.Constant(false);
- }
- }
- class VFXExpressionGetOrthographicSizeFromMainCamera : VFXExpression
- {
- public VFXExpressionGetOrthographicSizeFromMainCamera() : base(VFXExpression.Flags.InvalidOnGPU)
- {
- }
- public override VFXExpressionOperation operation
- {
- get
- {
- return VFXExpressionOperation.GetOrthographicSizeFromMainCamera;
- }
- }
- sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
- {
- if (Camera.main != null)
- return VFXValue.Constant(Camera.main.orthographicSize);
- else
- return VFXValue.Constant(CameraType.defaultValue.orthographicSize);
- }
- }
- }
|