Settings.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // River Modeler
  2. // Staggart Creations (http://staggart.xyz)
  3. // Copyright protected under Unity Asset Store EULA
  4. // Copying or referencing source code for the production of new asset store content is strictly prohibited.
  5. using System;
  6. using System.Collections.Generic;
  7. using UnityEngine;
  8. #if MATHEMATICS
  9. using Unity.Mathematics;
  10. #endif
  11. namespace sc.modeling.river.runtime
  12. {
  13. [Serializable]
  14. public class Settings
  15. {
  16. public enum VertexColorChannel
  17. {
  18. Red, Green, Blue, Alpha
  19. }
  20. [Serializable]
  21. public class Triangulation
  22. {
  23. [Tooltip("Minimum distance between each edge loop created over the length of the spline." +
  24. "\n\nUse higher values if corners exhibited overlapping triangles")]
  25. [Min(0.5f)] public float vertexDistance = 2f;
  26. [Tooltip("Minimum distance between each edge loop created over the width of the river." +
  27. "\n\nTypically want to keep this between 1-2 to add sufficient vertices for effects.")]
  28. [Min(0.5f)] public float vertexDistanceWidth = 1f;
  29. [Header("Simplification")]
  30. [Tooltip("Optimize the mesh by skipping edge loops on sections that run straight")]
  31. [Min(0f)]
  32. public float turnFilter;
  33. [Tooltip("Reduces the amount of edge loops on spline areas that are considered flat")]
  34. [Min(0f)]
  35. public float flatFilter = 0f;
  36. }
  37. public Triangulation triangulation = new Triangulation();
  38. [Serializable]
  39. public class Shape
  40. {
  41. [Tooltip("The base width of the mesh")]
  42. [Min(0.1f)] public float width = 10f;
  43. [Space]
  44. [Tooltip("Offsets the generated geometry from the spline curve.")]
  45. public Vector2 offset;
  46. [Tooltip("Curvature of the mesh over the width of the river")]
  47. public AnimationCurve widthCurve = AnimationCurve.Linear(0f, 0f, 1f, 0f);
  48. [Tooltip("Ignore the X and Z rotation of a spline knot so the river stays level")]
  49. public bool twistCorrection = false;
  50. }
  51. public Shape shape = new Shape();
  52. [Serializable]
  53. public class Displacement
  54. {
  55. [Serializable]
  56. public class Layer
  57. {
  58. [Tooltip("Perlin noise frequency as repeated over the spline. Typical values lies between 0.1 and 1")]
  59. public Vector2 noiseFrequency = new Vector2(0.2f, 1f);
  60. [Tooltip("Vertical offset created by the noise")]
  61. [Range(0f, 2f)]
  62. public float noiseAmplitude;
  63. [Tooltip("Angle range this noise layer takes effect in")]
  64. public Vector2 minMaxSlopeAngle = new Vector2(0f, 90f);
  65. [Range(0f, 1f)]
  66. [Tooltip("Remaps the values. 0=Only negative (downward) displacement. 1=Only positive (upward) displacement.")]
  67. public float normalization = 0.5f;
  68. }
  69. public List<Layer> layers = new List<Layer>()
  70. {
  71. new Layer()
  72. };
  73. }
  74. public Displacement displacement = new Displacement();
  75. [Serializable]
  76. public class UV
  77. {
  78. public Vector2 tiling = new Vector2(1f, 1f);
  79. [Tooltip("Push the edges of the UV slightly back on the Y-axis, to simulate slower water")]
  80. public float edgeDrag = 0f;
  81. [Space]
  82. public bool reverse;
  83. public bool rotate;
  84. [Space]
  85. [Tooltip("Enable the generation of a lightmap UV. This is a UV that repeat once over the surface of the mesh")]
  86. public bool lightmapUV;
  87. [Tooltip("Store the rivers flow direction into the UV2 channel (in C#: Mesh.uv3). This may be used in both shaders and C# flow calculations")]
  88. public bool flowVectors;
  89. }
  90. public UV uv = new UV();
  91. [Serializable]
  92. public class Foam
  93. {
  94. [Tooltip("Vertex color channel to store the foam weights in." +
  95. "\n\nWhen using the Stylized Water asset choose the Alpha channel")]
  96. public VertexColorChannel vertexColorChannel = VertexColorChannel.Alpha;
  97. [Range(0f,1f)]
  98. public float uniformAmount = 0f;
  99. [Space]
  100. public Vector2 noiseFrequency = new Vector2(1f, 1f);
  101. [Range(0f, 2f)]
  102. public float noiseAmplitude = 0f;
  103. [Tooltip("Perform a smoothstep operation on the generated noise")]
  104. public Vector2 noiseLevels = new Vector2(0f, 1f);
  105. [Space]
  106. [Range(0f,1f)]
  107. [Tooltip("Contribute displacement to foam weight")]
  108. public float displacementFoam;
  109. [Tooltip("Perform a smoothstep operation on the generated displacement")]
  110. public Vector2 displacementLevels = new Vector2(0f, 1f);
  111. [Space]
  112. [Range(0f,1f)]
  113. public float opacity = 1f;
  114. public void Validate()
  115. {
  116. noiseLevels.x = Mathf.Clamp01(noiseLevels.x);
  117. noiseLevels.y = Mathf.Clamp01(noiseLevels.y);
  118. displacementLevels.x = Mathf.Clamp01(displacementLevels.x);
  119. displacementLevels.y = Mathf.Clamp01(displacementLevels.y);
  120. }
  121. }
  122. public Foam foam = new Foam();
  123. [Serializable]
  124. public class Transparency
  125. {
  126. [Tooltip("Vertex color channel to store the transparency weights in." +
  127. "\n\nWhen using the Stylized Water asset choose the Green channel")]
  128. public VertexColorChannel vertexColorChannel = VertexColorChannel.Green;
  129. public float startFadeOffset = 0f;
  130. [Min(0.1f)]
  131. public float startFadeLength = 5f;
  132. public float endFadeOffset = 0f;
  133. [Min(0.1f)]
  134. public float endFadeLength = 5f;
  135. }
  136. public Transparency transparency;
  137. }
  138. }