FAETreeShaderController.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #if VEGETATION_STUDIO_PRO
  2. using AwesomeTechnologies.VegetationSystem;
  3. using UnityEngine;
  4. namespace AwesomeTechnologies.Shaders
  5. {
  6. // ReSharper disable once InconsistentNaming
  7. public class FAETreeShaderController : IShaderController
  8. {
  9. private static readonly string[] BranchShaderNames =
  10. {
  11. "FAE/Tree Branch",
  12. "Universal Render Pipeline/FAE/FAE_TreeBranch"
  13. };
  14. private static readonly string[] TrunkShaderNames =
  15. {
  16. "FAE/Tree Trunk",
  17. "Universal Render Pipeline/FAE/FAE_TreeTrunk"
  18. };
  19. public bool MatchShader(string shaderName)
  20. {
  21. if (string.IsNullOrEmpty(shaderName)) return false;
  22. for (int i = 0; i <= BranchShaderNames.Length - 1; i++)
  23. {
  24. if (BranchShaderNames[i].Contains(shaderName)) return true;
  25. }
  26. for (int i = 0; i <= TrunkShaderNames.Length - 1; i++)
  27. {
  28. if (TrunkShaderNames[i].Contains(shaderName)) return true;
  29. }
  30. return false;
  31. }
  32. public bool MatchBillboardShader(Material[] materials)
  33. {
  34. //VSP will skip any LODs matching this shader, bypass when URP is in use so billboards are still rendered
  35. if (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset != null) return false;
  36. for (int i = 0; i <= materials.Length - 1; i++)
  37. {
  38. if (materials[i].shader.name == "FAE/Tree Billboard" || materials[i].shader.name == "Universal Render Pipeline/FAE/FAE_TreeBillboard") return true;
  39. }
  40. return false;
  41. }
  42. bool IsTrunkShader(string shaderName)
  43. {
  44. for (int i = 0; i <= TrunkShaderNames.Length - 1; i++)
  45. {
  46. if (TrunkShaderNames[i].Contains(shaderName)) return true;
  47. }
  48. return false;
  49. }
  50. public ShaderControllerSettings Settings { get; set; }
  51. public void CreateDefaultSettings(Material[] materials)
  52. {
  53. Settings = new ShaderControllerSettings
  54. {
  55. Heading = "Fantasy Adventure Environment Tree",
  56. Description = "",
  57. LODFadePercentage = true,
  58. LODFadeCrossfade = true,
  59. SampleWind = true,
  60. SupportsInstantIndirect = true
  61. };
  62. Settings.AddLabelProperty("Branch");
  63. Settings.AddColorProperty("Color", "Main color", "", ShaderControllerSettings.GetColorFromMaterials(materials, "_Color"));
  64. Settings.AddColorProperty("HueVariation", "Hue Variation", "",
  65. ShaderControllerSettings.GetColorFromMaterials(materials, "_HueVariation"));
  66. Settings.AddColorProperty("TransmissionColor", "Transmission Color", "",
  67. ShaderControllerSettings.GetColorFromMaterials(materials, "_TransmissionColor"));
  68. Settings.AddFloatProperty("AmbientOcclusionBranch", "Ambient Occlusion", "",
  69. ShaderControllerSettings.GetFloatFromMaterials(materials, "_AmbientOcclusion"), 0, 1);
  70. Settings.AddFloatProperty("GradientBrightnessBranch", "Gradient Brightness", "",
  71. ShaderControllerSettings.GetFloatFromMaterials(materials, "_GradientBrightness"), 0, 2);
  72. Settings.AddLabelProperty("Trunk");
  73. Settings.AddFloatProperty("GradientBrightnessTrunk", "Gradient Brightness", "",
  74. ShaderControllerSettings.GetFloatFromMaterials(materials, "_GradientBrightness"), 0, 2);
  75. Settings.AddFloatProperty("AmbientOcclusionTrunk", "Ambient Occlusion", "",
  76. ShaderControllerSettings.GetFloatFromMaterials(materials, "_AmbientOcclusion"), 0, 1);
  77. Settings.AddLabelProperty("Branch Wind");
  78. Settings.AddFloatProperty("WindInfluence", "Max Strength", "", ShaderControllerSettings.GetFloatFromMaterials(materials, "_MaxWindStrength"), 0, 1);
  79. Settings.AddFloatProperty("WindAmplitude", "Amplitude Multiplier", "", ShaderControllerSettings.GetFloatFromMaterials(materials, "_WindAmplitudeMultiplier"), 0, 10);
  80. }
  81. public void UpdateMaterial(Material material, EnvironmentSettings environmentSettings)
  82. {
  83. if (Settings == null) return;
  84. bool isTrunk = IsTrunkShader(material.shader.name);
  85. if (isTrunk)
  86. {
  87. material.SetFloat("_AmbientOcclusion", Settings.GetFloatPropertyValue("AmbientOcclusionTrunk"));
  88. material.SetFloat("_GradientBrightness", Settings.GetFloatPropertyValue("GradientBrightnessTrunk"));
  89. }
  90. else
  91. {
  92. material.SetColor("_Color", Settings.GetColorPropertyValue("Color"));
  93. material.SetColor("_HueVariation", Settings.GetColorPropertyValue("HueVariation"));
  94. material.SetColor("_TransmissionColor", Settings.GetColorPropertyValue("TransmissionColor"));
  95. material.SetFloat("_AmbientOcclusion", Settings.GetFloatPropertyValue("AmbientOcclusionBranch"));
  96. material.SetFloat("_GradientBrightness", Settings.GetFloatPropertyValue("GradientBrightnessBranch"));
  97. material.SetFloat("_MaxWindStrength", Settings.GetFloatPropertyValue("WindInfluence"));
  98. material.SetFloat("_WindAmplitudeMultiplier", Settings.GetFloatPropertyValue("WindAmplitude"));
  99. }
  100. }
  101. public void UpdateWind(Material material, WindSettings windSettings)
  102. {
  103. }
  104. }
  105. }
  106. #endif