暫無描述
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.

PreviewTarget.cs 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Rendering;
  5. using UnityEngine.UIElements;
  6. namespace UnityEditor.ShaderGraph
  7. {
  8. sealed class PreviewTarget : Target
  9. {
  10. static readonly GUID kSourceCodeGuid = new GUID("7464b9fcde08e5645a16b9b8ae1e573c"); // PreviewTarget.cs
  11. public PreviewTarget()
  12. {
  13. displayName = "Preview";
  14. isHidden = true;
  15. }
  16. public override bool IsActive() => false;
  17. internal override bool ignoreCustomInterpolators => false;
  18. public override void Setup(ref TargetSetupContext context)
  19. {
  20. context.AddAssetDependency(kSourceCodeGuid, AssetCollection.Flags.SourceDependency);
  21. context.AddSubShader(SubShaders.Preview);
  22. }
  23. public override void GetFields(ref TargetFieldContext context)
  24. {
  25. }
  26. public override void GetActiveBlocks(ref TargetActiveBlockContext context)
  27. {
  28. }
  29. public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
  30. {
  31. }
  32. public override bool WorksWithSRP(RenderPipelineAsset scriptableRenderPipeline) => true;
  33. static class SubShaders
  34. {
  35. public static SubShaderDescriptor Preview = new SubShaderDescriptor()
  36. {
  37. renderQueue = "Geometry",
  38. renderType = "Opaque",
  39. generatesPreview = true,
  40. passes = new PassCollection { Passes.Preview },
  41. };
  42. }
  43. static class Passes
  44. {
  45. public static PassDescriptor Preview = new PassDescriptor()
  46. {
  47. // Definition
  48. referenceName = "SHADERPASS_PREVIEW",
  49. useInPreview = true,
  50. // Templates
  51. passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"),
  52. sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(),
  53. // Collections
  54. structs = new StructCollection
  55. {
  56. { Structs.Attributes },
  57. { StructDescriptors.PreviewVaryings },
  58. { Structs.SurfaceDescriptionInputs },
  59. { Structs.VertexDescriptionInputs },
  60. },
  61. fieldDependencies = FieldDependencies.Default,
  62. pragmas = new PragmaCollection
  63. {
  64. { Pragma.Vertex("vert") },
  65. { Pragma.Fragment("frag") },
  66. },
  67. defines = new DefineCollection
  68. {
  69. { KeywordDescriptors.PreviewKeyword, 1 },
  70. },
  71. includes = new IncludeCollection
  72. {
  73. // Pre-graph
  74. { "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl", IncludeLocation.Pregraph },
  75. { "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl", IncludeLocation.Pregraph },
  76. { "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl", IncludeLocation.Pregraph }, // TODO: put this on a conditional
  77. { "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl", IncludeLocation.Pregraph },
  78. { "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl", IncludeLocation.Pregraph },
  79. { "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl", IncludeLocation.Pregraph },
  80. { "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl", IncludeLocation.Pregraph },
  81. { "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl", IncludeLocation.Pregraph },
  82. { "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariables.hlsl", IncludeLocation.Pregraph },
  83. { "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl", IncludeLocation.Pregraph },
  84. { "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl", IncludeLocation.Pregraph },
  85. // Post-graph
  86. { "Packages/com.unity.shadergraph/ShaderGraphLibrary/PreviewVaryings.hlsl", IncludeLocation.Postgraph },
  87. { "Packages/com.unity.shadergraph/ShaderGraphLibrary/PreviewPass.hlsl", IncludeLocation.Postgraph },
  88. }
  89. };
  90. }
  91. static class StructDescriptors
  92. {
  93. public static StructDescriptor PreviewVaryings = new StructDescriptor()
  94. {
  95. name = "Varyings",
  96. packFields = true,
  97. fields = new[]
  98. {
  99. StructFields.Varyings.positionCS,
  100. StructFields.Varyings.positionWS,
  101. StructFields.Varyings.positionPredisplacementWS,
  102. StructFields.Varyings.normalWS,
  103. StructFields.Varyings.tangentWS,
  104. StructFields.Varyings.texCoord0,
  105. StructFields.Varyings.texCoord1,
  106. StructFields.Varyings.texCoord2,
  107. StructFields.Varyings.texCoord3,
  108. StructFields.Varyings.color,
  109. StructFields.Varyings.screenPosition,
  110. StructFields.Varyings.instanceID,
  111. StructFields.Varyings.vertexID,
  112. StructFields.Varyings.cullFace,
  113. }
  114. };
  115. }
  116. static class KeywordDescriptors
  117. {
  118. public static KeywordDescriptor PreviewKeyword = new KeywordDescriptor()
  119. {
  120. displayName = "Preview",
  121. referenceName = "SHADERGRAPH_PREVIEW",
  122. type = KeywordType.Boolean,
  123. definition = KeywordDefinition.MultiCompile,
  124. scope = KeywordScope.Global,
  125. stages = KeywordShaderStage.All,
  126. };
  127. }
  128. }
  129. }