UniversalShaderGraphResources.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 UniversalShaderGraphResources
  14. {
  15. public static string s_ResourceClassName => typeof(UniversalShaderGraphResources).FullName;
  16. public static string s_AssemblyName => typeof(UniversalShaderGraphResources).Assembly.FullName.ToString();
  17. struct UInt32_4
  18. { }
  19. internal struct Attributes
  20. {
  21. [Semantic("POSITION")]
  22. Vector3 positionOS;
  23. [Semantic("NORMAL")][Optional]
  24. Vector3 normalOS;
  25. [Semantic("TANGENT")][Optional]
  26. Vector4 tangentOS;
  27. [Semantic("TEXCOORD0")][Optional]
  28. Vector4 uv0;
  29. [Semantic("TEXCOORD1")][Optional]
  30. Vector4 uv1;
  31. [Semantic("TEXCOORD2")][Optional]
  32. Vector4 uv2;
  33. [Semantic("TEXCOORD3")][Optional]
  34. Vector4 uv3;
  35. [Semantic("COLOR")][Optional]
  36. Vector4 color;
  37. [Semantic("BLENDWEIGHTS")][Optional]
  38. Vector4 weights;
  39. [Semantic("BLENDINDICES")][Optional]
  40. UInt32_4 indices;
  41. [Semantic("INSTANCEID_SEMANTIC")] [PreprocessorIf("UNITY_ANY_INSTANCING_ENABLED")]
  42. uint instanceID;
  43. };
  44. [InterpolatorPack]
  45. internal struct Varyings
  46. {
  47. [Semantic("SV_POSITION")]
  48. Vector4 positionCS;
  49. [Optional]
  50. Vector3 positionWS;
  51. [Optional]
  52. Vector3 normalWS;
  53. [Optional]
  54. Vector4 tangentWS;
  55. [Optional]
  56. Vector4 texCoord0;
  57. [Optional]
  58. Vector4 texCoord1;
  59. [Optional]
  60. Vector4 texCoord2;
  61. [Optional]
  62. Vector4 texCoord3;
  63. [Optional]
  64. Vector4 color;
  65. [Optional]
  66. Vector3 viewDirectionWS;
  67. [Optional]
  68. Vector4 screenPosition;
  69. [Optional][PreprocessorIf("defined(LIGHTMAP_ON)")]
  70. Vector2 lightmapUV;
  71. [Optional][PreprocessorIf("!defined(LIGHTMAP_ON)")]
  72. Vector3 sh;
  73. [Optional]
  74. Vector4 fogFactorAndVertexLight;
  75. [Optional]
  76. Vector4 shadowCoord;
  77. [Semantic("CUSTOM_INSTANCE_ID")] [PreprocessorIf("UNITY_ANY_INSTANCING_ENABLED")]
  78. uint instanceID;
  79. [Semantic("SV_RenderTargetArrayIndex")]
  80. [SystemGenerated]
  81. [PreprocessorIf("(defined(UNITY_STEREO_INSTANCING_ENABLED))")]
  82. uint stereoTargetEyeIndexAsRTArrayIdx;
  83. [Semantic("BLENDINDICES0")]
  84. [SystemGenerated]
  85. [PreprocessorIf("(defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || " +
  86. "(defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))")]
  87. uint stereoTargetEyeIndexAsBlendIdx0;
  88. [Semantic("FRONT_FACE_SEMANTIC")]
  89. [SystemGenerated]
  90. [OverrideType("FRONT_FACE_TYPE")]
  91. [PreprocessorIf("defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)")]
  92. bool cullFace;
  93. };
  94. internal struct VertexDescriptionInputs
  95. {
  96. [Optional] Vector3 ObjectSpaceNormal;
  97. [Optional] Vector3 ViewSpaceNormal;
  98. [Optional] Vector3 WorldSpaceNormal;
  99. [Optional] Vector3 TangentSpaceNormal;
  100. [Optional] Vector3 ObjectSpaceTangent;
  101. [Optional] Vector3 ViewSpaceTangent;
  102. [Optional] Vector3 WorldSpaceTangent;
  103. [Optional] Vector3 TangentSpaceTangent;
  104. [Optional] Vector3 ObjectSpaceBiTangent;
  105. [Optional] Vector3 ViewSpaceBiTangent;
  106. [Optional] Vector3 WorldSpaceBiTangent;
  107. [Optional] Vector3 TangentSpaceBiTangent;
  108. [Optional] Vector3 ObjectSpaceViewDirection;
  109. [Optional] Vector3 ViewSpaceViewDirection;
  110. [Optional] Vector3 WorldSpaceViewDirection;
  111. [Optional] Vector3 TangentSpaceViewDirection;
  112. [Optional] Vector3 ObjectSpacePosition;
  113. [Optional] Vector3 ViewSpacePosition;
  114. [Optional] Vector3 WorldSpacePosition;
  115. [Optional] Vector3 TangentSpacePosition;
  116. [Optional] Vector3 AbsoluteWorldSpacePosition;
  117. [Optional] Vector4 ScreenPosition;
  118. [Optional] Vector4 uv0;
  119. [Optional] Vector4 uv1;
  120. [Optional] Vector4 uv2;
  121. [Optional] Vector4 uv3;
  122. [Optional] Vector4 VertexColor;
  123. [Optional] Vector3 TimeParameters;
  124. [Optional] Vector4 BoneWeights;
  125. [Optional] UInt32_4 BoneIndices;
  126. };
  127. internal struct SurfaceDescriptionInputs
  128. {
  129. [Optional] Vector3 ObjectSpaceNormal;
  130. [Optional] Vector3 ViewSpaceNormal;
  131. [Optional] Vector3 WorldSpaceNormal;
  132. [Optional] Vector3 TangentSpaceNormal;
  133. [Optional] Vector3 ObjectSpaceTangent;
  134. [Optional] Vector3 ViewSpaceTangent;
  135. [Optional] Vector3 WorldSpaceTangent;
  136. [Optional] Vector3 TangentSpaceTangent;
  137. [Optional] Vector3 ObjectSpaceBiTangent;
  138. [Optional] Vector3 ViewSpaceBiTangent;
  139. [Optional] Vector3 WorldSpaceBiTangent;
  140. [Optional] Vector3 TangentSpaceBiTangent;
  141. [Optional] Vector3 ObjectSpaceViewDirection;
  142. [Optional] Vector3 ViewSpaceViewDirection;
  143. [Optional] Vector3 WorldSpaceViewDirection;
  144. [Optional] Vector3 TangentSpaceViewDirection;
  145. [Optional] Vector3 ObjectSpacePosition;
  146. [Optional] Vector3 ViewSpacePosition;
  147. [Optional] Vector3 WorldSpacePosition;
  148. [Optional] Vector3 TangentSpacePosition;
  149. [Optional] Vector3 AbsoluteWorldSpacePosition;
  150. [Optional] Vector4 ScreenPosition;
  151. [Optional] Vector4 uv0;
  152. [Optional] Vector4 uv1;
  153. [Optional] Vector4 uv2;
  154. [Optional] Vector4 uv3;
  155. [Optional] Vector4 VertexColor;
  156. [Optional] Vector3 TimeParameters;
  157. [Optional] float FaceSign;
  158. };
  159. public static List<Dependency[]> s_Dependencies = new List<Dependency[]>()
  160. {
  161. // Varyings
  162. new Dependency[]
  163. {
  164. new Dependency("Varyings.positionWS", "Attributes.positionOS"),
  165. new Dependency("Varyings.normalWS", "Attributes.normalOS"),
  166. new Dependency("Varyings.tangentWS", "Attributes.tangentOS"),
  167. new Dependency("Varyings.texCoord0", "Attributes.uv0"),
  168. new Dependency("Varyings.texCoord1", "Attributes.uv1"),
  169. new Dependency("Varyings.texCoord2", "Attributes.uv2"),
  170. new Dependency("Varyings.texCoord3", "Attributes.uv3"),
  171. new Dependency("Varyings.color", "Attributes.color"),
  172. new Dependency("Varyings.instanceID", "Attributes.instanceID"),
  173. new Dependency("Varyings.stereoTargetEyeIndexAsBlendIdx0", "Attributes.instanceID"),
  174. new Dependency("Varyings.stereoTargetEyeIndexAsRTArrayIdx", "Attributes.instanceID"),
  175. },
  176. // Vertex DescriptionInputs
  177. new Dependency[]
  178. {
  179. new Dependency("VertexDescriptionInputs.ObjectSpaceNormal", "Attributes.normalOS"),
  180. new Dependency("VertexDescriptionInputs.WorldSpaceNormal", "Attributes.normalOS"),
  181. new Dependency("VertexDescriptionInputs.ViewSpaceNormal", "VertexDescriptionInputs.WorldSpaceNormal"),
  182. new Dependency("VertexDescriptionInputs.ObjectSpaceTangent", "Attributes.tangentOS"),
  183. new Dependency("VertexDescriptionInputs.WorldSpaceTangent", "Attributes.tangentOS"),
  184. new Dependency("VertexDescriptionInputs.ViewSpaceTangent", "VertexDescriptionInputs.WorldSpaceTangent"),
  185. new Dependency("VertexDescriptionInputs.ObjectSpaceBiTangent", "Attributes.normalOS"),
  186. new Dependency("VertexDescriptionInputs.ObjectSpaceBiTangent", "Attributes.tangentOS"),
  187. new Dependency("VertexDescriptionInputs.WorldSpaceBiTangent", "VertexDescriptionInputs.ObjectSpaceBiTangent"),
  188. new Dependency("VertexDescriptionInputs.ViewSpaceBiTangent", "VertexDescriptionInputs.WorldSpaceBiTangent"),
  189. new Dependency("VertexDescriptionInputs.ObjectSpacePosition", "Attributes.positionOS"),
  190. new Dependency("VertexDescriptionInputs.WorldSpacePosition", "Attributes.positionOS"),
  191. new Dependency("VertexDescriptionInputs.AbsoluteWorldSpacePosition","Attributes.positionOS"),
  192. new Dependency("VertexDescriptionInputs.ViewSpacePosition", "VertexDescriptionInputs.WorldSpacePosition"),
  193. new Dependency("VertexDescriptionInputs.WorldSpaceViewDirection", "VertexDescriptionInputs.WorldSpacePosition"),
  194. new Dependency("VertexDescriptionInputs.ObjectSpaceViewDirection", "VertexDescriptionInputs.WorldSpaceViewDirection"),
  195. new Dependency("VertexDescriptionInputs.ViewSpaceViewDirection", "VertexDescriptionInputs.WorldSpaceViewDirection"),
  196. new Dependency("VertexDescriptionInputs.TangentSpaceViewDirection", "VertexDescriptionInputs.WorldSpaceViewDirection"),
  197. new Dependency("VertexDescriptionInputs.TangentSpaceViewDirection", "VertexDescriptionInputs.WorldSpaceTangent"),
  198. new Dependency("VertexDescriptionInputs.TangentSpaceViewDirection", "VertexDescriptionInputs.WorldSpaceBiTangent"),
  199. new Dependency("VertexDescriptionInputs.TangentSpaceViewDirection", "VertexDescriptionInputs.WorldSpaceNormal"),
  200. new Dependency("VertexDescriptionInputs.ScreenPosition", "VertexDescriptionInputs.WorldSpacePosition"),
  201. new Dependency("VertexDescriptionInputs.uv0", "Attributes.uv0"),
  202. new Dependency("VertexDescriptionInputs.uv1", "Attributes.uv1"),
  203. new Dependency("VertexDescriptionInputs.uv2", "Attributes.uv2"),
  204. new Dependency("VertexDescriptionInputs.uv3", "Attributes.uv3"),
  205. new Dependency("VertexDescriptionInputs.VertexColor", "Attributes.color"),
  206. new Dependency("VertexDescriptionInputs.BoneWeights", "Attributes.weights"),
  207. new Dependency("VertexDescriptionInputs.BoneIndices", "Attributes.indices")
  208. },
  209. // SurfaceDescriptionInputs
  210. new Dependency[]
  211. {
  212. new Dependency("SurfaceDescriptionInputs.WorldSpaceNormal", "Varyings.normalWS"),
  213. new Dependency("SurfaceDescriptionInputs.ObjectSpaceNormal", "SurfaceDescriptionInputs.WorldSpaceNormal"),
  214. new Dependency("SurfaceDescriptionInputs.ViewSpaceNormal", "SurfaceDescriptionInputs.WorldSpaceNormal"),
  215. new Dependency("SurfaceDescriptionInputs.WorldSpaceTangent", "Varyings.tangentWS"),
  216. new Dependency("SurfaceDescriptionInputs.WorldSpaceTangent", "SurfaceDescriptionInputs.WorldSpaceNormal"),
  217. new Dependency("SurfaceDescriptionInputs.ObjectSpaceTangent", "SurfaceDescriptionInputs.WorldSpaceTangent"),
  218. new Dependency("SurfaceDescriptionInputs.ViewSpaceTangent", "SurfaceDescriptionInputs.WorldSpaceTangent"),
  219. new Dependency("SurfaceDescriptionInputs.WorldSpaceBiTangent", "SurfaceDescriptionInputs.WorldSpaceNormal"),
  220. new Dependency("SurfaceDescriptionInputs.WorldSpaceBiTangent", "SurfaceDescriptionInputs.WorldSpaceTangent"),
  221. new Dependency("SurfaceDescriptionInputs.ObjectSpaceBiTangent", "SurfaceDescriptionInputs.WorldSpaceBiTangent"),
  222. new Dependency("SurfaceDescriptionInputs.ViewSpaceBiTangent", "SurfaceDescriptionInputs.WorldSpaceBiTangent"),
  223. new Dependency("SurfaceDescriptionInputs.WorldSpacePosition", "Varyings.positionWS"),
  224. new Dependency("SurfaceDescriptionInputs.AbsoluteWorldSpacePosition","Varyings.positionWS"),
  225. new Dependency("SurfaceDescriptionInputs.ObjectSpacePosition", "Varyings.positionWS"),
  226. new Dependency("SurfaceDescriptionInputs.ViewSpacePosition", "Varyings.positionWS"),
  227. new Dependency("SurfaceDescriptionInputs.WorldSpaceViewDirection", "Varyings.viewDirectionWS"), // we build WorldSpaceViewDirection using Varyings.positionWS in GetWorldSpaceNormalizeViewDir()
  228. new Dependency("SurfaceDescriptionInputs.ObjectSpaceViewDirection", "SurfaceDescriptionInputs.WorldSpaceViewDirection"),
  229. new Dependency("SurfaceDescriptionInputs.ViewSpaceViewDirection", "SurfaceDescriptionInputs.WorldSpaceViewDirection"),
  230. new Dependency("SurfaceDescriptionInputs.TangentSpaceViewDirection", "SurfaceDescriptionInputs.WorldSpaceViewDirection"),
  231. new Dependency("SurfaceDescriptionInputs.TangentSpaceViewDirection", "SurfaceDescriptionInputs.WorldSpaceTangent"),
  232. new Dependency("SurfaceDescriptionInputs.TangentSpaceViewDirection", "SurfaceDescriptionInputs.WorldSpaceBiTangent"),
  233. new Dependency("SurfaceDescriptionInputs.TangentSpaceViewDirection", "SurfaceDescriptionInputs.WorldSpaceNormal"),
  234. new Dependency("SurfaceDescriptionInputs.ScreenPosition", "SurfaceDescriptionInputs.WorldSpacePosition"),
  235. new Dependency("SurfaceDescriptionInputs.uv0", "Varyings.texCoord0"),
  236. new Dependency("SurfaceDescriptionInputs.uv1", "Varyings.texCoord1"),
  237. new Dependency("SurfaceDescriptionInputs.uv2", "Varyings.texCoord2"),
  238. new Dependency("SurfaceDescriptionInputs.uv3", "Varyings.texCoord3"),
  239. new Dependency("SurfaceDescriptionInputs.VertexColor", "Varyings.color"),
  240. new Dependency("SurfaceDescriptionInputs.FaceSign", "Varyings.cullFace"),
  241. new Dependency("DepthOffset", "Varyings.positionWS"),
  242. },
  243. };
  244. };
  245. }