No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BakedLitShader.cs 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using UnityEngine;
  3. using UnityEditor.Rendering.Universal;
  4. namespace UnityEditor.Rendering.Universal.ShaderGUI
  5. {
  6. internal class BakedLitShader : BaseShaderGUI
  7. {
  8. // Properties
  9. private BakedLitGUI.BakedLitProperties shadingModelProperties;
  10. // collect properties from the material properties
  11. public override void FindProperties(MaterialProperty[] properties)
  12. {
  13. base.FindProperties(properties);
  14. shadingModelProperties = new BakedLitGUI.BakedLitProperties(properties);
  15. }
  16. // material changed check
  17. public override void ValidateMaterial(Material material)
  18. {
  19. SetMaterialKeywords(material);
  20. }
  21. // material main surface options
  22. public override void DrawSurfaceOptions(Material material)
  23. {
  24. if (material == null)
  25. throw new ArgumentNullException("material");
  26. // Use default labelWidth
  27. EditorGUIUtility.labelWidth = 0f;
  28. base.DrawSurfaceOptions(material);
  29. }
  30. // material main surface inputs
  31. public override void DrawSurfaceInputs(Material material)
  32. {
  33. base.DrawSurfaceInputs(material);
  34. BakedLitGUI.Inputs(shadingModelProperties, materialEditor);
  35. DrawTileOffset(materialEditor, baseMapProp);
  36. }
  37. public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
  38. {
  39. if (material == null)
  40. throw new ArgumentNullException("material");
  41. // _Emission property is lost after assigning Standard shader to the material
  42. // thus transfer it before assigning the new shader
  43. if (material.HasProperty("_Emission"))
  44. {
  45. material.SetColor("_EmissionColor", material.GetColor("_Emission"));
  46. }
  47. base.AssignNewShaderToMaterial(material, oldShader, newShader);
  48. if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/"))
  49. {
  50. SetupMaterialBlendMode(material);
  51. return;
  52. }
  53. SurfaceType surfaceType = SurfaceType.Opaque;
  54. BlendMode blendMode = BlendMode.Alpha;
  55. if (oldShader.name.Contains("/Transparent/Cutout/"))
  56. {
  57. surfaceType = SurfaceType.Opaque;
  58. material.SetFloat("_AlphaClip", 1);
  59. }
  60. else if (oldShader.name.Contains("/Transparent/"))
  61. {
  62. // NOTE: legacy shaders did not provide physically based transparency
  63. // therefore Fade mode
  64. surfaceType = SurfaceType.Transparent;
  65. blendMode = BlendMode.Alpha;
  66. }
  67. material.SetFloat("_Blend", (float)blendMode);
  68. material.SetFloat("_Surface", (float)surfaceType);
  69. if (surfaceType == SurfaceType.Opaque)
  70. {
  71. material.DisableKeyword("_SURFACE_TYPE_TRANSPARENT");
  72. }
  73. else
  74. {
  75. material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
  76. }
  77. }
  78. }
  79. }