VFXExpressionSampleSDF.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Linq;
  3. using System.Runtime.CompilerServices;
  4. using UnityEditor;
  5. using UnityEditor.VFX.Operator;
  6. using UnityEngine;
  7. using UnityEngine.VFX;
  8. namespace UnityEditor.VFX
  9. {
  10. class VFXExpressionSampleSDF : VFXExpression
  11. {
  12. public VFXExpressionSampleSDF() : this(VFXTexture3DValue.Default, VFXValue<Vector3>.Default, VFXValue<Vector3>.Default, VFXValue<float>.Default)
  13. {
  14. }
  15. public VFXExpressionSampleSDF(VFXExpression texture, VFXExpression uvw, VFXExpression scale, VFXExpression mipLevel)
  16. : base(Flags.InvalidOnCPU, new VFXExpression[4] { texture, uvw, scale, mipLevel })
  17. { }
  18. sealed public override VFXExpressionOperation operation { get { return VFXExpressionOperation.None; } }
  19. sealed public override VFXValueType valueType { get { return VFXValueType.Float; } }
  20. public sealed override string GetCodeString(string[] parents)
  21. {
  22. return string.Format("GetDistanceFromSDF(VFX_SAMPLER({0}), {1}, {2}, {3}) ", parents[0], parents[1], parents[2], parents[3]);
  23. }
  24. }
  25. class VFXExpressionSampleSDFNormal : VFXExpression
  26. {
  27. public VFXExpressionSampleSDFNormal() : this(VFXTexture3DValue.Default, VFXValue<Matrix4x4>.Default, VFXValue<Vector3>.Default, VFXValue<float>.Default)
  28. {
  29. }
  30. public VFXExpressionSampleSDFNormal(VFXExpression texture, VFXExpression inverseTRS, VFXExpression uvw, VFXExpression mipLevel)
  31. : base(Flags.InvalidOnCPU, new VFXExpression[4] { texture, inverseTRS, uvw, mipLevel })
  32. { }
  33. sealed public override VFXExpressionOperation operation { get { return VFXExpressionOperation.None; } }
  34. sealed public override VFXValueType valueType { get { return VFXValueType.Float3; } }
  35. public sealed override string GetCodeString(string[] parents)
  36. {
  37. return string.Format("VFXSafeNormalize(mul(float4(GetNormalFromSDF(VFX_SAMPLER({0}), {2}, {3}),0.0f), {1}).xyz )", parents[0], parents[1], parents[2], parents[3]);
  38. }
  39. }
  40. }