Нема описа
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.

CustomTextureSlice.cs 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. using UnityEditor.ShaderGraph;
  3. using UnityEditor.Graphing;
  4. using UnityEditor.ShaderGraph.Internal;
  5. namespace UnityEditor.Rendering.CustomRenderTexture.ShaderGraph
  6. {
  7. [Title("Custom Render Texture", "Slice Index / Cubemap Face")]
  8. [SubTargetFilter(typeof(CustomTextureSubTarget))]
  9. class CustomTextureSlice : AbstractMaterialNode, IGeneratesFunction
  10. {
  11. private const string kOutputSlotCubeFaceName = "Texture Cube Face";
  12. private const string kOutputSlot3DSliceName = "Texture Depth Slice";
  13. public const int OutputSlotCubeFaceId = 3;
  14. public const int OutputSlot3DSliceId = 4;
  15. public CustomTextureSlice()
  16. {
  17. name = "Slice Index / Cubemap Face";
  18. UpdateNodeAfterDeserialization();
  19. }
  20. protected int[] validSlots => new[] { OutputSlotCubeFaceId, OutputSlot3DSliceId };
  21. public sealed override void UpdateNodeAfterDeserialization()
  22. {
  23. AddSlot(new Vector1MaterialSlot(OutputSlotCubeFaceId, kOutputSlotCubeFaceName, kOutputSlotCubeFaceName, SlotType.Output, 0));
  24. AddSlot(new Vector1MaterialSlot(OutputSlot3DSliceId, kOutputSlot3DSliceName, kOutputSlot3DSliceName, SlotType.Output, 0));
  25. RemoveSlotsNameNotMatching(validSlots);
  26. }
  27. public override string GetVariableNameForSlot(int slotId)
  28. {
  29. switch (slotId)
  30. {
  31. case OutputSlotCubeFaceId:
  32. return "_CustomRenderTextureCubeFace";
  33. default:
  34. case OutputSlot3DSliceId:
  35. return "_CustomRenderTexture3DSlice";
  36. }
  37. }
  38. public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
  39. {
  40. // For preview only we declare CRT defines
  41. if (generationMode == GenerationMode.Preview)
  42. {
  43. registry.builder.AppendLine("#define _CustomRenderTextureCubeFace 0.0");
  44. registry.builder.AppendLine("#define _CustomRenderTexture3DSlice 0.0");
  45. }
  46. }
  47. }
  48. }