NoiseSineWaveNode.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using UnityEngine;
  2. using System.Reflection;
  3. namespace UnityEditor.ShaderGraph
  4. {
  5. [Title("Math", "Wave", "Noise Sine Wave")]
  6. class NoiseSineWaveNode : CodeFunctionNode
  7. {
  8. public NoiseSineWaveNode()
  9. {
  10. name = "Noise Sine Wave";
  11. }
  12. protected override MethodInfo GetFunctionToConvert()
  13. {
  14. return GetType().GetMethod("NoiseSineWave", BindingFlags.Static | BindingFlags.NonPublic);
  15. }
  16. static string NoiseSineWave(
  17. [Slot(0, Binding.None)] DynamicDimensionVector In,
  18. [Slot(1, Binding.None, -0.5f, 0.5f, 1, 1)] Vector2 MinMax,
  19. [Slot(2, Binding.None)] out DynamicDimensionVector Out)
  20. {
  21. return
  22. @"
  23. {
  24. $precision sinIn = sin(In);
  25. $precision sinInOffset = sin(In + 1.0);
  26. $precision randomno = frac(sin((sinIn - sinInOffset) * (12.9898 + 78.233))*43758.5453);
  27. $precision noise = lerp(MinMax.x, MinMax.y, randomno);
  28. Out = sinIn + noise;
  29. }
  30. ";
  31. }
  32. }
  33. }