LuxURPCustomBillboardShaderGUI.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using UnityEngine;
  2. using UnityEditor;
  3. public class LuxURPCustomBillboardShaderGUI : ShaderGUI
  4. {
  5. public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
  6. {
  7. base.OnGUI(materialEditor, properties);
  8. Material material = materialEditor.target as Material;
  9. var _Surface = ShaderGUI.FindProperty("_Surface", properties);
  10. int QueueOffset = material.GetInt("_QueueOffset");
  11. // Alpha Testing
  12. if(_Surface.floatValue == 0.0f) {
  13. material.EnableKeyword("_ALPHATEST_ON");
  14. material.DisableKeyword("_APPLYFOGADDITIVELY");
  15. if (material.GetInt("_ApplyFog") == 1) {
  16. material.EnableKeyword("_APPLYFOG");
  17. material.DisableKeyword("_APPLYFOGADDITIVELY");
  18. }
  19. material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest + QueueOffset;
  20. material.SetOverrideTag("RenderType", "TransparentCutout");
  21. material.SetInt("_ZWrite", 1);
  22. material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
  23. material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
  24. material.SetShaderPassEnabled("ShadowCaster", true);
  25. }
  26. // Alpha Blending
  27. else {
  28. material.DisableKeyword("_ALPHATEST_ON");
  29. material.renderQueue = (int) UnityEngine.Rendering.RenderQueue.Transparent + QueueOffset;
  30. material.SetOverrideTag("RenderType", "Transparent");
  31. material.SetInt("_ZWrite", 0);
  32. if (material.GetInt("_Blend") == 0) {
  33. material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
  34. material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
  35. material.DisableKeyword("_APPLYFOGADDITIVELY");
  36. if (material.GetInt("_ApplyFog") == 1) {
  37. material.EnableKeyword("_APPLYFOG");
  38. }
  39. else {
  40. material.DisableKeyword("_APPLYFOG");
  41. }
  42. }
  43. else if (material.GetInt("_Blend") == 1) {
  44. material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
  45. material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
  46. material.DisableKeyword("_APPLYFOG");
  47. if (material.GetInt("_ApplyFog") == 1) {
  48. material.EnableKeyword("_APPLYFOGADDITIVELY");
  49. }
  50. else {
  51. material.DisableKeyword("_APPLYFOGADDITIVELY");
  52. }
  53. }
  54. else {
  55. material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusDstColor);
  56. material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
  57. material.DisableKeyword("_APPLYFOG");
  58. if (material.GetInt("_ApplyFog") == 1) {
  59. material.EnableKeyword("_APPLYFOGADDITIVELY");
  60. }
  61. else {
  62. material.DisableKeyword("_APPLYFOGADDITIVELY");
  63. }
  64. }
  65. material.SetShaderPassEnabled("ShadowCaster", false);
  66. }
  67. if (material.HasProperty("_Culling")) {
  68. var _Culling = ShaderGUI.FindProperty("_Culling", properties);
  69. if(_Culling.floatValue == 0.0f) {
  70. if (material.doubleSidedGI == false) {
  71. Debug.Log ("Double Sided Global Illumination enabled.");
  72. }
  73. material.doubleSidedGI = true;
  74. }
  75. }
  76. // Get rid of the normal map issue
  77. if ( material.HasProperty("_BumpMap") ) {
  78. if (material.HasProperty("_ApplyNormal") ) {
  79. if ( material.GetFloat("_ApplyNormal") == 0.0f && material.GetTexture("_BumpMap") == null ) {
  80. //material.SetTexture("_BumpMap", Texture2D.normalTexture); // Is not linear?!
  81. material.SetTexture("_BumpMap", Resources.Load("LuxURPdefaultBump") as Texture2D );
  82. }
  83. }
  84. }
  85. }
  86. }