VolumetricFogSInfo.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. using UnityEngine;
  2. using System.Text;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. namespace VolumetricFogAndMist {
  6. public class VolumetricFogSInfo {
  7. public string name = "";
  8. public string path = "";
  9. public List<SCShaderPass> passes = new List<SCShaderPass> ();
  10. public List<SCKeyword> keywords = new List<SCKeyword> ();
  11. public bool pendingChanges;
  12. public bool editedByShaderControl;
  13. public int enabledKeywordCount;
  14. public void Add (SCShaderPass pass) {
  15. passes.Add (pass);
  16. UpdateKeywords ();
  17. }
  18. public void EnableKeywords () {
  19. keywords.ForEach ((SCKeyword keyword) => keyword.enabled = true);
  20. }
  21. void UpdateKeywords () {
  22. passes.ForEach ((SCShaderPass pass) => {
  23. for (int l = 0; l < pass.keywordLines.Count; l++) {
  24. SCKeywordLine line = pass.keywordLines [l];
  25. for (int k = 0; k < line.keywords.Count; k++) {
  26. SCKeyword keyword = line.keywords [k];
  27. if (!keywords.Contains (keyword)) {
  28. if (SCKeywordChecker.IsValid (keyword.name)) {
  29. keywords.Add (keyword);
  30. }
  31. }
  32. }
  33. }
  34. });
  35. enabledKeywordCount = 0;
  36. keywords.ForEach ((SCKeyword kw) => {
  37. if (kw.enabled)
  38. enabledKeywordCount++;
  39. });
  40. }
  41. public SCKeyword GetKeyword (string name) {
  42. int kCount = keywords.Count;
  43. for (int k = 0; k < kCount; k++) {
  44. SCKeyword keyword = keywords [k];
  45. if (keyword.name.Equals (name))
  46. return keyword;
  47. }
  48. return new SCKeyword (name);
  49. }
  50. }
  51. public class SCShaderPass {
  52. public int pass;
  53. public List<SCKeywordLine> keywordLines = new List<SCKeywordLine> ();
  54. public int keywordCount;
  55. public void Add (SCKeywordLine keywordLine) {
  56. keywordLines.Add (keywordLine);
  57. UpdateKeywordCount ();
  58. }
  59. public void Add (List<SCKeywordLine> keywordLines) {
  60. this.keywordLines.AddRange (keywordLines);
  61. UpdateKeywordCount ();
  62. }
  63. void UpdateKeywordCount () {
  64. keywordCount = 0;
  65. keywordLines.ForEach ((SCKeywordLine obj) => keywordCount += obj.keywordCount);
  66. }
  67. public void Clear () {
  68. keywordCount = 0;
  69. keywordLines.Clear ();
  70. }
  71. }
  72. public class SCKeywordLine {
  73. public List<SCKeyword> keywords = new List<SCKeyword> ();
  74. public bool hasUnderscoreVariant;
  75. public SCKeyword GetKeyword (string name) {
  76. int kc = keywords.Count;
  77. for (int k = 0; k < kc; k++) {
  78. SCKeyword keyword = keywords [k];
  79. if (keyword.name.Equals (name)) {
  80. return keyword;
  81. }
  82. }
  83. return null;
  84. }
  85. public void Add (SCKeyword keyword) {
  86. if (GetKeyword (keyword.name) != null)
  87. return;
  88. // ignore underscore keywords
  89. bool goodKeyword = false;
  90. for (int k = 0; k < keyword.name.Length; k++) {
  91. if (keyword.name [k] != '_') {
  92. goodKeyword = true;
  93. break;
  94. }
  95. }
  96. if (goodKeyword) {
  97. keywords.Add (keyword);
  98. } else {
  99. keyword.isUnderscoreKeyword = true;
  100. hasUnderscoreVariant = true;
  101. }
  102. }
  103. public void DisableKeywords () {
  104. keywords.ForEach ((SCKeyword obj) => obj.enabled = false);
  105. }
  106. public void Clear () {
  107. keywords.Clear ();
  108. }
  109. public int keywordCount {
  110. get {
  111. return keywords.Count;
  112. }
  113. }
  114. public int keywordsEnabledCount {
  115. get {
  116. int kCount = keywords.Count;
  117. int enabledCount = 0;
  118. for (int k = 0; k < kCount; k++) {
  119. if (keywords [k].enabled)
  120. enabledCount++;
  121. }
  122. return enabledCount;
  123. }
  124. }
  125. public override string ToString () {
  126. StringBuilder sb = new StringBuilder ();
  127. for (int k = 0; k < keywords.Count; k++) {
  128. if (k > 0)
  129. sb.Append (" ");
  130. sb.Append (keywords [k].name);
  131. }
  132. return sb.ToString ();
  133. }
  134. }
  135. public class SCKeyword {
  136. public string name;
  137. public bool enabled;
  138. public bool isUnderscoreKeyword;
  139. public SCKeyword (string name) {
  140. this.name = name;
  141. enabled = true;
  142. }
  143. public override bool Equals (object obj) {
  144. if (obj is SCKeyword) {
  145. SCKeyword other = (SCKeyword)obj;
  146. return name.Equals (other.name);
  147. }
  148. return false;
  149. }
  150. public override int GetHashCode () {
  151. return name.GetHashCode ();
  152. }
  153. public override string ToString () {
  154. return name;
  155. }
  156. }
  157. static class SCKeywordChecker {
  158. static Dictionary<string, string> dict = new Dictionary<string, string> ();
  159. static SCKeywordChecker() {
  160. string[][] kw = new string[][] {
  161. new string[] { VolumetricFog.SKW_FOG_HAZE_ON, "Sky Haze" },
  162. new string[] { VolumetricFog.SKW_FOG_OF_WAR_ON, "Fog of War" },
  163. new string[] { VolumetricFog.SKW_LIGHT_SCATTERING, "Light Scattering" },
  164. new string[] { VolumetricFog.SKW_SUN_SHADOWS, "Sun Shadows" },
  165. new string[] { VolumetricFog.SKW_FOG_VOID_BOX, "Fog Void (Box shape)" },
  166. new string[] { VolumetricFog.SKW_FOG_VOID_SPHERE, "Fog Void (Sphere shape)" },
  167. new string[] { VolumetricFog.SKW_FOG_AREA_BOX, "Fog Area (Box shape)" },
  168. new string[] { VolumetricFog.SKW_FOG_AREA_SPHERE, "Fog Area (Sphere shape)" },
  169. new string[] { VolumetricFog.SKW_FOG_BLUR, "Depth Blur" },
  170. new string[] { VolumetricFog.SKW_FOG_USE_XY_PLANE, "Use XY Plane" },
  171. new string[] { VolumetricFog.SKW_FOG_COMPUTE_DEPTH, "Compute Depth" }
  172. };
  173. for (int k=0;k<kw.Length;k++) dict[kw[k][0]] = kw[k][1];
  174. }
  175. public static bool IsValid (string name) {
  176. return dict.ContainsKey (name);
  177. }
  178. public static string Translate (string name) {
  179. if (dict.ContainsKey (name)) {
  180. return dict [name];
  181. } else {
  182. return name;
  183. }
  184. }
  185. }
  186. }