Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

LightTextureNode.cs 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using UnityEditor.Graphing;
  3. using UnityEditor.Rendering.Universal.ShaderGraph;
  4. using UnityEditor.ShaderGraph;
  5. using UnityEditor.ShaderGraph.Drawing.Controls;
  6. using UnityEditor.ShaderGraph.Internal;
  7. namespace UnityEngine.Experimental.Rendering.Universal
  8. {
  9. enum BlendStyle
  10. {
  11. LightTex0,
  12. LightTex1,
  13. LightTex2,
  14. LightTex3,
  15. }
  16. [Title("Input", "2D", "Light Texture")]
  17. [SubTargetFilterAttribute(new[] { typeof(UniversalSpriteCustomLitSubTarget), typeof(UniversalSpriteUnlitSubTarget)})]
  18. class LightTextureNode : AbstractMaterialNode, IGeneratesFunction
  19. {
  20. private const int OutputSlotId = 0;
  21. private const string kOutputSlotName = "Out";
  22. [SerializeField] private BlendStyle m_BlendStyle = BlendStyle.LightTex0;
  23. [EnumControl("")]
  24. public BlendStyle blendStyle
  25. {
  26. get { return m_BlendStyle; }
  27. set
  28. {
  29. if (m_BlendStyle == value)
  30. return;
  31. m_BlendStyle = value;
  32. Dirty(ModificationScope.Graph);
  33. }
  34. }
  35. public LightTextureNode()
  36. {
  37. name = "2D Light Texture";
  38. UpdateNodeAfterDeserialization();
  39. }
  40. public sealed override void UpdateNodeAfterDeserialization()
  41. {
  42. AddSlot(new Texture2DMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
  43. RemoveSlotsNameNotMatching(new[] { OutputSlotId });
  44. }
  45. string GetVariableName()
  46. {
  47. return $"_ShapeLightTexture{(int)m_BlendStyle}";
  48. }
  49. public override string GetVariableNameForSlot(int slotId)
  50. {
  51. return $"Unity_GetLightTexture{(int)m_BlendStyle}()";
  52. }
  53. public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
  54. {
  55. registry.RequiresIncludePath("Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/ShapeLightShared.hlsl", true);
  56. registry.RequiresIncludePath("Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/ShapeLightVariables.hlsl");
  57. registry.ProvideFunction($"Unity_GetLightTexture{(int)m_BlendStyle}", s =>
  58. {
  59. s.AppendLine($"UnityTexture2D Unity_GetLightTexture{(int)m_BlendStyle}()");
  60. using (s.BlockScope())
  61. {
  62. s.AppendLine("#if USE_SHAPE_LIGHT_TYPE_0 || USE_SHAPE_LIGHT_TYPE_1 || USE_SHAPE_LIGHT_TYPE_2 || USE_SHAPE_LIGHT_TYPE_3");
  63. s.AppendLine(" return " + $"UnityBuildTexture2DStructNoScale(" + GetVariableName() + ");");
  64. s.AppendLine("#else");
  65. s.AppendLine(" return " + $"UnityBuildTexture2DStructNoScale(_DefaultWhiteTex);");
  66. s.AppendLine("#endif");
  67. }
  68. });
  69. }
  70. public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
  71. {
  72. properties.AddShaderProperty(new Texture2DShaderProperty()
  73. {
  74. overrideReferenceName = GetVariableName(),
  75. generatePropertyBlock = false,
  76. defaultType = Texture2DShaderProperty.DefaultType.White,
  77. // value = m_Texture,
  78. modifiable = false
  79. });
  80. }
  81. }
  82. }