UniversalShaderGraphUtils.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using UnityEditor;
  6. using UnityEditor.Graphing;
  7. using UnityEditor.ShaderGraph;
  8. using UnityEditor.ShaderGraph.Internal;
  9. using Data.Util;
  10. using UnityEngine;
  11. namespace UnityEditor.Rendering.Universal
  12. {
  13. static class UniversalShaderGraphUtilities
  14. {
  15. public static void SetRenderState(SurfaceType surfaceType, AlphaMode alphaMode, bool twoSided, ref ShaderPass pass)
  16. {
  17. // Get default render state from Master Node
  18. var options = ShaderGenerator.GetMaterialOptions(surfaceType, alphaMode, twoSided);
  19. // Update render state on ShaderPass if there is no active override
  20. if(string.IsNullOrEmpty(pass.ZWriteOverride))
  21. {
  22. pass.ZWriteOverride = "ZWrite " + options.zWrite.ToString();
  23. }
  24. if(string.IsNullOrEmpty(pass.ZTestOverride))
  25. {
  26. pass.ZTestOverride = "ZTest " + options.zTest.ToString();
  27. }
  28. if(string.IsNullOrEmpty(pass.CullOverride))
  29. {
  30. pass.CullOverride = "Cull " + options.cullMode.ToString();
  31. }
  32. if(string.IsNullOrEmpty(pass.BlendOverride))
  33. {
  34. pass.BlendOverride = string.Format("Blend {0} {1}, {2} {3}", options.srcBlend, options.dstBlend, options.alphaSrcBlend, options.alphaDstBlend);
  35. }
  36. }
  37. }
  38. }