LuxURPCustomGlassShaderGUI.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using UnityEngine;
  2. using UnityEditor;
  3. public class LuxURPCustomGlassShaderGUI : 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. // Blending
  10. int blendMode = (int)material.GetFloat("_Blend");
  11. // None
  12. if (blendMode == 0) {
  13. material.SetFloat("_SrcBlend", 1.0f);
  14. material.SetFloat("_DstBlend", 0.0f);
  15. material.DisableKeyword("_FINALALPHA");
  16. material.DisableKeyword("_ADDITIVE");
  17. }
  18. // Alpha blending
  19. else if (blendMode == 1) {
  20. material.SetFloat("_SrcBlend", (float)UnityEngine.Rendering.BlendMode.SrcAlpha);
  21. material.SetFloat("_DstBlend", (float)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
  22. material.EnableKeyword("_FINALALPHA");
  23. material.DisableKeyword("_ADDITIVE");
  24. }
  25. // Additive
  26. else {
  27. material.SetFloat("_SrcBlend", (float)UnityEngine.Rendering.BlendMode.SrcAlpha);
  28. material.SetFloat("_DstBlend", (float)UnityEngine.Rendering.BlendMode.One);
  29. material.EnableKeyword("_FINALALPHA");
  30. material.EnableKeyword("_ADDITIVE");
  31. }
  32. // Double sided
  33. if (material.HasProperty("_Cull")) {
  34. var _Culling = ShaderGUI.FindProperty("_Cull", properties);
  35. if(_Culling.floatValue == 0.0f) {
  36. if (material.doubleSidedGI == false) {
  37. Debug.Log ("Material " + material.name + ": Double Sided Global Illumination enabled.", (Object)material);
  38. }
  39. material.doubleSidedGI = true;
  40. }
  41. else {
  42. if (material.doubleSidedGI == true) {
  43. Debug.Log ("Material " + material.name + ": Double Sided Global Illumination disabled.", (Object)material);
  44. }
  45. material.doubleSidedGI = false;
  46. }
  47. }
  48. // Get RenderQueue Offset - if any
  49. int QueueOffset = 0;
  50. if ( material.HasProperty("_QueueOffset") ) {
  51. QueueOffset = material.GetInt("_QueueOffset");
  52. }
  53. // Get rid of the normal map issue
  54. if ( material.HasProperty("_BumpMap") ) {
  55. if (material.HasProperty("_ApplyNormal") ) {
  56. if ( material.GetFloat("_ApplyNormal") == 0.0f && material.GetTexture("_BumpMap") == null ) {
  57. //material.SetTexture("_BumpMap", Texture2D.normalTexture); // Is not linear?!
  58. material.SetTexture("_BumpMap", Resources.Load("LuxURPdefaultBump") as Texture2D );
  59. }
  60. }
  61. }
  62. // Needed to make the Selection Outline work
  63. if (material.HasProperty("_MainTex") && material.HasProperty("_BaseMap") ) {
  64. // Alpha might be stored in the Mask Map
  65. bool copyMaskMap = false;
  66. if(material.HasProperty("_AlphaFromMaskMap") && material.HasProperty("_MaskMap")) {
  67. if (material.GetFloat("_AlphaFromMaskMap") == 1.0) {
  68. copyMaskMap = true;
  69. }
  70. }
  71. if (copyMaskMap) {
  72. if (material.GetTexture("_MaskMap") != null) {
  73. material.SetTexture("_MainTex", material.GetTexture("_MaskMap"));
  74. }
  75. }
  76. else {
  77. if (material.GetTexture("_BaseMap") != null) {
  78. material.SetTexture("_MainTex", material.GetTexture("_BaseMap"));
  79. }
  80. }
  81. }
  82. }
  83. }