説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CustomTextureSelf.cs 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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", "Self")]
  8. [SubTargetFilter(typeof(CustomTextureSubTarget))]
  9. class CustomTextureSelf : AbstractMaterialNode, IGeneratesFunction
  10. {
  11. private const string kOutputSlotSelf2DName = "Self Texture 2D";
  12. private const string kOutputSlotSelfCubeName = "Self Texture Cube";
  13. private const string kOutputSlotSelf3DName = "Self Texture 3D";
  14. public const int OutputSlotSelf2DId = 5;
  15. public const int OutputSlotSelfCubeId = 6;
  16. public const int OutputSlotSelf3DId = 7;
  17. public CustomTextureSelf()
  18. {
  19. name = "Custom Render Texture Self";
  20. UpdateNodeAfterDeserialization();
  21. }
  22. protected int[] validSlots => new[] { OutputSlotSelf2DId, OutputSlotSelfCubeId, OutputSlotSelf3DId };
  23. public sealed override void UpdateNodeAfterDeserialization()
  24. {
  25. AddSlot(new Texture2DMaterialSlot(OutputSlotSelf2DId, kOutputSlotSelf2DName, kOutputSlotSelf2DName, SlotType.Output, ShaderStageCapability.Fragment, false) { bareResource = true });
  26. AddSlot(new CubemapMaterialSlot(OutputSlotSelfCubeId, kOutputSlotSelfCubeName, kOutputSlotSelfCubeName, SlotType.Output, ShaderStageCapability.Fragment, false) { bareResource = true });
  27. AddSlot(new Texture3DMaterialSlot(OutputSlotSelf3DId, kOutputSlotSelf3DName, kOutputSlotSelf3DName, SlotType.Output, ShaderStageCapability.Fragment, false) { bareResource = true });
  28. RemoveSlotsNameNotMatching(validSlots);
  29. }
  30. public override string GetVariableNameForSlot(int slotId)
  31. {
  32. switch (slotId)
  33. {
  34. case OutputSlotSelf2DId:
  35. return "UnityBuildTexture2DStructNoScale(_SelfTexture2D)";
  36. case OutputSlotSelfCubeId:
  37. return "UnityBuildTextureCubeStruct(_SelfTextureCube)";
  38. default:
  39. return "UnityBuildTexture3DStruct(_SelfTexture3D)";
  40. }
  41. }
  42. public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
  43. {
  44. // For preview only we declare CRT defines
  45. if (generationMode == GenerationMode.Preview)
  46. {
  47. registry.builder.AppendLine("#if !defined(UNITY_CRT_PREVIEW_TEXTURE) && !defined(UNITY_CUSTOM_TEXTURE_INCLUDED)");
  48. registry.builder.AppendLine("#define UNITY_CRT_PREVIEW_TEXTURE");
  49. registry.builder.AppendLine("TEXTURE2D(_SelfTexture2D);");
  50. registry.builder.AppendLine("SAMPLER(sampler_SelfTexture2D);");
  51. registry.builder.AppendLine("float4 _SelfTexture2D_TexelSize;");
  52. registry.builder.AppendLine("TEXTURECUBE(_SelfTextureCube);");
  53. registry.builder.AppendLine("SAMPLER(sampler_SelfTextureCube);");
  54. registry.builder.AppendLine("float4 _SelfTextureCube_TexelSize;");
  55. registry.builder.AppendLine("TEXTURE3D(_SelfTexture3D);");
  56. registry.builder.AppendLine("SAMPLER(sampler_SelfTexture3D);");
  57. registry.builder.AppendLine("float4 sampler_SelfTexture3D_TexelSize;");
  58. registry.builder.AppendLine("#endif");
  59. }
  60. }
  61. }
  62. }