UniversalTarget.cs 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.Rendering;
  6. using UnityEngine.Rendering.Universal;
  7. using UnityEngine.UIElements;
  8. using UnityEditor.ShaderGraph;
  9. using UnityEditor.ShaderGraph.Internal;
  10. using UnityEditor.UIElements;
  11. using UnityEditor.ShaderGraph.Serialization;
  12. using UnityEditor.ShaderGraph.Legacy;
  13. #if HAS_VFX_GRAPH
  14. using UnityEditor.VFX;
  15. #endif
  16. namespace UnityEditor.Rendering.Universal.ShaderGraph
  17. {
  18. public enum MaterialType
  19. {
  20. Lit,
  21. Unlit,
  22. SpriteLit,
  23. SpriteUnlit,
  24. }
  25. public enum WorkflowMode
  26. {
  27. Specular,
  28. Metallic,
  29. }
  30. enum SurfaceType
  31. {
  32. Opaque,
  33. Transparent,
  34. }
  35. enum ZWriteControl
  36. {
  37. Auto = 0,
  38. ForceEnabled = 1,
  39. ForceDisabled = 2
  40. }
  41. enum ZTestMode // the values here match UnityEngine.Rendering.CompareFunction
  42. {
  43. Disabled = 0,
  44. Never = 1,
  45. Less = 2,
  46. Equal = 3,
  47. LEqual = 4, // default for most rendering
  48. Greater = 5,
  49. NotEqual = 6,
  50. GEqual = 7,
  51. Always = 8,
  52. }
  53. enum AlphaMode
  54. {
  55. Alpha,
  56. Premultiply,
  57. Additive,
  58. Multiply,
  59. }
  60. internal enum RenderFace
  61. {
  62. Front = 2, // = CullMode.Back -- render front face only
  63. Back = 1, // = CullMode.Front -- render back face only
  64. Both = 0 // = CullMode.Off -- render both faces
  65. }
  66. sealed class UniversalTarget : Target, IHasMetadata, ILegacyTarget
  67. #if HAS_VFX_GRAPH
  68. , IMaySupportVFX, IRequireVFXContext
  69. #endif
  70. {
  71. public override int latestVersion => 1;
  72. // Constants
  73. static readonly GUID kSourceCodeGuid = new GUID("8c72f47fdde33b14a9340e325ce56f4d"); // UniversalTarget.cs
  74. public const string kPipelineTag = "UniversalPipeline";
  75. public const string kLitMaterialTypeTag = "\"UniversalMaterialType\" = \"Lit\"";
  76. public const string kUnlitMaterialTypeTag = "\"UniversalMaterialType\" = \"Unlit\"";
  77. public static readonly string[] kSharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories().Union(new string[]
  78. {
  79. "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates"
  80. #if HAS_VFX_GRAPH
  81. , "Packages/com.unity.visualeffectgraph/Editor/ShaderGraph/Templates"
  82. #endif
  83. }).ToArray();
  84. public const string kUberTemplatePath = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/ShaderPass.template";
  85. // SubTarget
  86. List<SubTarget> m_SubTargets;
  87. List<string> m_SubTargetNames;
  88. int activeSubTargetIndex => m_SubTargets.IndexOf(m_ActiveSubTarget);
  89. // View
  90. PopupField<string> m_SubTargetField;
  91. TextField m_CustomGUIField;
  92. #if HAS_VFX_GRAPH
  93. Toggle m_SupportVFXToggle;
  94. #endif
  95. [SerializeField]
  96. JsonData<SubTarget> m_ActiveSubTarget;
  97. // when checked, allows the material to control ALL surface settings (uber shader style)
  98. [SerializeField]
  99. bool m_AllowMaterialOverride = false;
  100. [SerializeField]
  101. SurfaceType m_SurfaceType = SurfaceType.Opaque;
  102. [SerializeField]
  103. ZTestMode m_ZTestMode = ZTestMode.LEqual;
  104. [SerializeField]
  105. ZWriteControl m_ZWriteControl = ZWriteControl.Auto;
  106. [SerializeField]
  107. AlphaMode m_AlphaMode = AlphaMode.Alpha;
  108. [SerializeField]
  109. RenderFace m_RenderFace = RenderFace.Front;
  110. [SerializeField]
  111. bool m_AlphaClip = false;
  112. [SerializeField]
  113. bool m_CastShadows = true;
  114. [SerializeField]
  115. bool m_ReceiveShadows = true;
  116. [SerializeField]
  117. string m_CustomEditorGUI;
  118. [SerializeField]
  119. bool m_SupportVFX;
  120. internal override bool ignoreCustomInterpolators => false;
  121. internal override int padCustomInterpolatorLimit => 4;
  122. internal override bool prefersSpritePreview =>
  123. activeSubTarget is UniversalSpriteUnlitSubTarget or UniversalSpriteLitSubTarget or
  124. UniversalSpriteCustomLitSubTarget;
  125. public UniversalTarget()
  126. {
  127. displayName = "Universal";
  128. m_SubTargets = TargetUtils.GetSubTargets(this);
  129. m_SubTargetNames = m_SubTargets.Select(x => x.displayName).ToList();
  130. TargetUtils.ProcessSubTargetList(ref m_ActiveSubTarget, ref m_SubTargets);
  131. }
  132. public string renderType
  133. {
  134. get
  135. {
  136. if (surfaceType == SurfaceType.Transparent)
  137. return $"{RenderType.Transparent}";
  138. else
  139. return $"{RenderType.Opaque}";
  140. }
  141. }
  142. // this sets up the default renderQueue -- but it can be overridden by ResetMaterialKeywords()
  143. public string renderQueue
  144. {
  145. get
  146. {
  147. if (surfaceType == SurfaceType.Transparent)
  148. return $"{UnityEditor.ShaderGraph.RenderQueue.Transparent}";
  149. else if (alphaClip)
  150. return $"{UnityEditor.ShaderGraph.RenderQueue.AlphaTest}";
  151. else
  152. return $"{UnityEditor.ShaderGraph.RenderQueue.Geometry}";
  153. }
  154. }
  155. public SubTarget activeSubTarget
  156. {
  157. get => m_ActiveSubTarget.value;
  158. set => m_ActiveSubTarget = value;
  159. }
  160. public bool allowMaterialOverride
  161. {
  162. get => m_AllowMaterialOverride;
  163. set => m_AllowMaterialOverride = value;
  164. }
  165. public SurfaceType surfaceType
  166. {
  167. get => m_SurfaceType;
  168. set => m_SurfaceType = value;
  169. }
  170. public ZWriteControl zWriteControl
  171. {
  172. get => m_ZWriteControl;
  173. set => m_ZWriteControl = value;
  174. }
  175. public ZTestMode zTestMode
  176. {
  177. get => m_ZTestMode;
  178. set => m_ZTestMode = value;
  179. }
  180. public AlphaMode alphaMode
  181. {
  182. get => m_AlphaMode;
  183. set => m_AlphaMode = value;
  184. }
  185. public RenderFace renderFace
  186. {
  187. get => m_RenderFace;
  188. set => m_RenderFace = value;
  189. }
  190. public bool alphaClip
  191. {
  192. get => m_AlphaClip;
  193. set => m_AlphaClip = value;
  194. }
  195. public bool castShadows
  196. {
  197. get => m_CastShadows;
  198. set => m_CastShadows = value;
  199. }
  200. public bool receiveShadows
  201. {
  202. get => m_ReceiveShadows;
  203. set => m_ReceiveShadows = value;
  204. }
  205. public string customEditorGUI
  206. {
  207. get => m_CustomEditorGUI;
  208. set => m_CustomEditorGUI = value;
  209. }
  210. // generally used to know if we need to build a depth pass
  211. public bool mayWriteDepth
  212. {
  213. get
  214. {
  215. if (allowMaterialOverride)
  216. {
  217. // material may or may not choose to write depth... we should create the depth pass
  218. return true;
  219. }
  220. else
  221. {
  222. switch (zWriteControl)
  223. {
  224. case ZWriteControl.Auto:
  225. return (surfaceType == SurfaceType.Opaque);
  226. case ZWriteControl.ForceDisabled:
  227. return false;
  228. default:
  229. return true;
  230. }
  231. }
  232. }
  233. }
  234. public override bool IsActive()
  235. {
  236. bool isUniversalRenderPipeline = GraphicsSettings.currentRenderPipeline is UniversalRenderPipelineAsset;
  237. return isUniversalRenderPipeline && activeSubTarget.IsActive();
  238. }
  239. public override bool IsNodeAllowedByTarget(Type nodeType)
  240. {
  241. SRPFilterAttribute srpFilter = NodeClassCache.GetAttributeOnNodeType<SRPFilterAttribute>(nodeType);
  242. bool worksWithThisSrp = srpFilter == null || srpFilter.srpTypes.Contains(typeof(UniversalRenderPipeline));
  243. SubTargetFilterAttribute subTargetFilter = NodeClassCache.GetAttributeOnNodeType<SubTargetFilterAttribute>(nodeType);
  244. bool worksWithThisSubTarget = subTargetFilter == null || subTargetFilter.subTargetTypes.Contains(activeSubTarget.GetType());
  245. return worksWithThisSrp && worksWithThisSubTarget && base.IsNodeAllowedByTarget(nodeType);
  246. }
  247. public override void Setup(ref TargetSetupContext context)
  248. {
  249. // Setup the Target
  250. context.AddAssetDependency(kSourceCodeGuid, AssetCollection.Flags.SourceDependency);
  251. // Override EditorGUI (replaces the URP material editor by a custom one)
  252. if (!string.IsNullOrEmpty(m_CustomEditorGUI))
  253. context.AddCustomEditorForRenderPipeline(m_CustomEditorGUI, typeof(UniversalRenderPipelineAsset));
  254. // Setup the active SubTarget
  255. TargetUtils.ProcessSubTargetList(ref m_ActiveSubTarget, ref m_SubTargets);
  256. m_ActiveSubTarget.value.target = this;
  257. m_ActiveSubTarget.value.Setup(ref context);
  258. }
  259. public override void OnAfterMultiDeserialize(string json)
  260. {
  261. TargetUtils.ProcessSubTargetList(ref m_ActiveSubTarget, ref m_SubTargets);
  262. m_ActiveSubTarget.value.target = this;
  263. }
  264. public override void GetFields(ref TargetFieldContext context)
  265. {
  266. var descs = context.blocks.Select(x => x.descriptor);
  267. // Core fields
  268. context.AddField(Fields.GraphVertex, descs.Contains(BlockFields.VertexDescription.Position) ||
  269. descs.Contains(BlockFields.VertexDescription.Normal) ||
  270. descs.Contains(BlockFields.VertexDescription.Tangent));
  271. context.AddField(Fields.GraphPixel);
  272. // SubTarget fields
  273. m_ActiveSubTarget.value.GetFields(ref context);
  274. }
  275. public override void GetActiveBlocks(ref TargetActiveBlockContext context)
  276. {
  277. // Core blocks
  278. context.AddBlock(BlockFields.VertexDescription.Position);
  279. context.AddBlock(BlockFields.VertexDescription.Normal);
  280. context.AddBlock(BlockFields.VertexDescription.Tangent);
  281. context.AddBlock(BlockFields.SurfaceDescription.BaseColor);
  282. // SubTarget blocks
  283. m_ActiveSubTarget.value.GetActiveBlocks(ref context);
  284. }
  285. public override void ProcessPreviewMaterial(Material material)
  286. {
  287. m_ActiveSubTarget.value.ProcessPreviewMaterial(material);
  288. }
  289. public override object saveContext => m_ActiveSubTarget.value?.saveContext;
  290. public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode)
  291. {
  292. base.CollectShaderProperties(collector, generationMode);
  293. activeSubTarget.CollectShaderProperties(collector, generationMode);
  294. collector.AddShaderProperty(LightmappingShaderProperties.kLightmapsArray);
  295. collector.AddShaderProperty(LightmappingShaderProperties.kLightmapsIndirectionArray);
  296. collector.AddShaderProperty(LightmappingShaderProperties.kShadowMasksArray);
  297. // SubTarget blocks
  298. m_ActiveSubTarget.value.CollectShaderProperties(collector, generationMode);
  299. }
  300. public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
  301. {
  302. // Core properties
  303. m_SubTargetField = new PopupField<string>(m_SubTargetNames, activeSubTargetIndex);
  304. context.AddProperty("Material", m_SubTargetField, (evt) =>
  305. {
  306. if (Equals(activeSubTargetIndex, m_SubTargetField.index))
  307. return;
  308. registerUndo("Change Material");
  309. m_ActiveSubTarget = m_SubTargets[m_SubTargetField.index];
  310. onChange();
  311. });
  312. // SubTarget properties
  313. m_ActiveSubTarget.value.GetPropertiesGUI(ref context, onChange, registerUndo);
  314. // Custom Editor GUI
  315. // Requires FocusOutEvent
  316. m_CustomGUIField = new TextField("") { value = customEditorGUI };
  317. m_CustomGUIField.RegisterCallback<FocusOutEvent>(s =>
  318. {
  319. if (Equals(customEditorGUI, m_CustomGUIField.value))
  320. return;
  321. registerUndo("Change Custom Editor GUI");
  322. customEditorGUI = m_CustomGUIField.value;
  323. onChange();
  324. });
  325. context.AddProperty("Custom Editor GUI", m_CustomGUIField, (evt) => { });
  326. #if HAS_VFX_GRAPH
  327. if (VFXViewPreference.generateOutputContextWithShaderGraph)
  328. {
  329. // VFX Support
  330. if (!(m_ActiveSubTarget.value is UniversalSubTarget))
  331. context.AddHelpBox(MessageType.Info, $"The {m_ActiveSubTarget.value.displayName} target does not support VFX Graph.");
  332. else
  333. {
  334. m_SupportVFXToggle = new Toggle("") { value = m_SupportVFX };
  335. context.AddProperty("Support VFX Graph", m_SupportVFXToggle, (evt) =>
  336. {
  337. m_SupportVFX = m_SupportVFXToggle.value;
  338. });
  339. }
  340. }
  341. #endif
  342. }
  343. // this is a copy of ZTestMode, but hides the "Disabled" option, which is invalid
  344. enum ZTestModeForUI
  345. {
  346. Never = 1,
  347. Less = 2,
  348. Equal = 3,
  349. LEqual = 4, // default for most rendering
  350. Greater = 5,
  351. NotEqual = 6,
  352. GEqual = 7,
  353. Always = 8,
  354. };
  355. public void AddDefaultMaterialOverrideGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
  356. {
  357. // At some point we may want to convert this to be a per-property control
  358. // or Unify the UX with the upcoming "lock" feature of the Material Variant properties
  359. context.AddProperty("Allow Material Override", new Toggle() { value = allowMaterialOverride }, (evt) =>
  360. {
  361. if (Equals(allowMaterialOverride, evt.newValue))
  362. return;
  363. registerUndo("Change Allow Material Override");
  364. allowMaterialOverride = evt.newValue;
  365. onChange();
  366. });
  367. }
  368. public void AddDefaultSurfacePropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo, bool showReceiveShadows)
  369. {
  370. context.AddProperty("Surface Type", new EnumField(SurfaceType.Opaque) { value = surfaceType }, (evt) =>
  371. {
  372. if (Equals(surfaceType, evt.newValue))
  373. return;
  374. registerUndo("Change Surface");
  375. surfaceType = (SurfaceType)evt.newValue;
  376. onChange();
  377. });
  378. context.AddProperty("Blending Mode", new EnumField(AlphaMode.Alpha) { value = alphaMode }, surfaceType == SurfaceType.Transparent, (evt) =>
  379. {
  380. if (Equals(alphaMode, evt.newValue))
  381. return;
  382. registerUndo("Change Blend");
  383. alphaMode = (AlphaMode)evt.newValue;
  384. onChange();
  385. });
  386. context.AddProperty("Render Face", new EnumField(RenderFace.Front) { value = renderFace }, (evt) =>
  387. {
  388. if (Equals(renderFace, evt.newValue))
  389. return;
  390. registerUndo("Change Render Face");
  391. renderFace = (RenderFace)evt.newValue;
  392. onChange();
  393. });
  394. context.AddProperty("Depth Write", new EnumField(ZWriteControl.Auto) { value = zWriteControl }, (evt) =>
  395. {
  396. if (Equals(zWriteControl, evt.newValue))
  397. return;
  398. registerUndo("Change Depth Write Control");
  399. zWriteControl = (ZWriteControl)evt.newValue;
  400. onChange();
  401. });
  402. context.AddProperty("Depth Test", new EnumField(ZTestModeForUI.LEqual) { value = (ZTestModeForUI)zTestMode }, (evt) =>
  403. {
  404. if (Equals(zTestMode, evt.newValue))
  405. return;
  406. registerUndo("Change Depth Test");
  407. zTestMode = (ZTestMode)evt.newValue;
  408. onChange();
  409. });
  410. context.AddProperty("Alpha Clipping", new Toggle() { value = alphaClip }, (evt) =>
  411. {
  412. if (Equals(alphaClip, evt.newValue))
  413. return;
  414. registerUndo("Change Alpha Clip");
  415. alphaClip = evt.newValue;
  416. onChange();
  417. });
  418. context.AddProperty("Cast Shadows", new Toggle() { value = castShadows }, (evt) =>
  419. {
  420. if (Equals(castShadows, evt.newValue))
  421. return;
  422. registerUndo("Change Cast Shadows");
  423. castShadows = evt.newValue;
  424. onChange();
  425. });
  426. if (showReceiveShadows)
  427. context.AddProperty("Receive Shadows", new Toggle() { value = receiveShadows }, (evt) =>
  428. {
  429. if (Equals(receiveShadows, evt.newValue))
  430. return;
  431. registerUndo("Change Receive Shadows");
  432. receiveShadows = evt.newValue;
  433. onChange();
  434. });
  435. }
  436. public bool TrySetActiveSubTarget(Type subTargetType)
  437. {
  438. if (!subTargetType.IsSubclassOf(typeof(SubTarget)))
  439. return false;
  440. foreach (var subTarget in m_SubTargets)
  441. {
  442. if (subTarget.GetType().Equals(subTargetType))
  443. {
  444. m_ActiveSubTarget = subTarget;
  445. return true;
  446. }
  447. }
  448. return false;
  449. }
  450. public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<BlockFieldDescriptor, int> blockMap)
  451. {
  452. void UpgradeAlphaClip()
  453. {
  454. var clipThresholdId = 8;
  455. var node = masterNode as AbstractMaterialNode;
  456. var clipThresholdSlot = node.FindSlot<Vector1MaterialSlot>(clipThresholdId);
  457. if (clipThresholdSlot == null)
  458. return;
  459. clipThresholdSlot.owner = node;
  460. if (clipThresholdSlot.isConnected || clipThresholdSlot.value > 0.0f)
  461. {
  462. m_AlphaClip = true;
  463. }
  464. }
  465. // Upgrade Target
  466. allowMaterialOverride = false;
  467. switch (masterNode)
  468. {
  469. case PBRMasterNode1 pbrMasterNode:
  470. m_SurfaceType = (SurfaceType)pbrMasterNode.m_SurfaceType;
  471. m_AlphaMode = (AlphaMode)pbrMasterNode.m_AlphaMode;
  472. m_RenderFace = pbrMasterNode.m_TwoSided ? RenderFace.Both : RenderFace.Front;
  473. UpgradeAlphaClip();
  474. m_CustomEditorGUI = pbrMasterNode.m_OverrideEnabled ? pbrMasterNode.m_ShaderGUIOverride : "";
  475. break;
  476. case UnlitMasterNode1 unlitMasterNode:
  477. m_SurfaceType = (SurfaceType)unlitMasterNode.m_SurfaceType;
  478. m_AlphaMode = (AlphaMode)unlitMasterNode.m_AlphaMode;
  479. m_RenderFace = unlitMasterNode.m_TwoSided ? RenderFace.Both : RenderFace.Front;
  480. UpgradeAlphaClip();
  481. m_CustomEditorGUI = unlitMasterNode.m_OverrideEnabled ? unlitMasterNode.m_ShaderGUIOverride : "";
  482. break;
  483. case SpriteLitMasterNode1 spriteLitMasterNode:
  484. m_CustomEditorGUI = spriteLitMasterNode.m_OverrideEnabled ? spriteLitMasterNode.m_ShaderGUIOverride : "";
  485. break;
  486. case SpriteUnlitMasterNode1 spriteUnlitMasterNode:
  487. m_CustomEditorGUI = spriteUnlitMasterNode.m_OverrideEnabled ? spriteUnlitMasterNode.m_ShaderGUIOverride : "";
  488. break;
  489. }
  490. // Upgrade SubTarget
  491. foreach (var subTarget in m_SubTargets)
  492. {
  493. if (!(subTarget is ILegacyTarget legacySubTarget))
  494. continue;
  495. if (legacySubTarget.TryUpgradeFromMasterNode(masterNode, out blockMap))
  496. {
  497. m_ActiveSubTarget = subTarget;
  498. return true;
  499. }
  500. }
  501. blockMap = null;
  502. return false;
  503. }
  504. public override bool WorksWithSRP(RenderPipelineAsset scriptableRenderPipeline)
  505. {
  506. return scriptableRenderPipeline?.GetType() == typeof(UniversalRenderPipelineAsset);
  507. }
  508. #if HAS_VFX_GRAPH
  509. public void ConfigureContextData(VFXContext context, VFXContextCompiledData data)
  510. {
  511. if (!(m_ActiveSubTarget.value is IRequireVFXContext vfxSubtarget))
  512. return;
  513. vfxSubtarget.ConfigureContextData(context, data);
  514. }
  515. #endif
  516. public bool CanSupportVFX()
  517. {
  518. if (m_ActiveSubTarget.value == null)
  519. return false;
  520. if (m_ActiveSubTarget.value is UniversalUnlitSubTarget)
  521. return true;
  522. if (m_ActiveSubTarget.value is UniversalLitSubTarget)
  523. return true;
  524. //It excludes:
  525. // - UniversalDecalSubTarget
  526. // - UniversalSpriteLitSubTarget
  527. // - UniversalSpriteUnlitSubTarget
  528. // - UniversalSpriteCustomLitSubTarget
  529. return false;
  530. }
  531. public bool SupportsVFX()
  532. {
  533. #if HAS_VFX_GRAPH
  534. if (!CanSupportVFX())
  535. return false;
  536. return m_SupportVFX;
  537. #else
  538. return false;
  539. #endif
  540. }
  541. [Serializable]
  542. class UniversalTargetLegacySerialization
  543. {
  544. [SerializeField]
  545. public bool m_TwoSided = false;
  546. }
  547. public override void OnAfterDeserialize(string json)
  548. {
  549. base.OnAfterDeserialize(json);
  550. if (this.sgVersion < latestVersion)
  551. {
  552. if (this.sgVersion == 0)
  553. {
  554. // deserialize the old settings to upgrade
  555. var oldSettings = JsonUtility.FromJson<UniversalTargetLegacySerialization>(json);
  556. this.m_RenderFace = oldSettings.m_TwoSided ? RenderFace.Both : RenderFace.Front;
  557. }
  558. ChangeVersion(latestVersion);
  559. }
  560. }
  561. #region Metadata
  562. string IHasMetadata.identifier
  563. {
  564. get
  565. {
  566. // defer to subtarget
  567. if (m_ActiveSubTarget.value is IHasMetadata subTargetHasMetaData)
  568. return subTargetHasMetaData.identifier;
  569. return null;
  570. }
  571. }
  572. ScriptableObject IHasMetadata.GetMetadataObject(GraphDataReadOnly graph)
  573. {
  574. // defer to subtarget
  575. if (m_ActiveSubTarget.value is IHasMetadata subTargetHasMetaData)
  576. return subTargetHasMetaData.GetMetadataObject(graph);
  577. return null;
  578. }
  579. #endregion
  580. }
  581. #region Passes
  582. static class CorePasses
  583. {
  584. internal static void AddAlphaClipControlToPass(ref PassDescriptor pass, UniversalTarget target)
  585. {
  586. if (target.allowMaterialOverride)
  587. pass.keywords.Add(CoreKeywordDescriptors.AlphaTestOn);
  588. else if (target.alphaClip)
  589. pass.defines.Add(CoreKeywordDescriptors.AlphaTestOn, 1);
  590. }
  591. internal static void AddTargetSurfaceControlsToPass(ref PassDescriptor pass, UniversalTarget target)
  592. {
  593. // the surface settings can either be material controlled or target controlled
  594. if (target.allowMaterialOverride)
  595. {
  596. // setup material control of via keyword
  597. pass.keywords.Add(CoreKeywordDescriptors.SurfaceTypeTransparent);
  598. pass.keywords.Add(CoreKeywordDescriptors.AlphaPremultiplyOn);
  599. }
  600. else
  601. {
  602. // setup target control via define
  603. if (target.surfaceType == SurfaceType.Transparent)
  604. pass.defines.Add(CoreKeywordDescriptors.SurfaceTypeTransparent, 1);
  605. if (target.alphaMode == AlphaMode.Premultiply)
  606. pass.defines.Add(CoreKeywordDescriptors.AlphaPremultiplyOn, 1);
  607. }
  608. AddAlphaClipControlToPass(ref pass, target);
  609. }
  610. // used by lit/unlit subtargets
  611. public static PassDescriptor DepthOnly(UniversalTarget target)
  612. {
  613. var result = new PassDescriptor()
  614. {
  615. // Definition
  616. displayName = "DepthOnly",
  617. referenceName = "SHADERPASS_DEPTHONLY",
  618. lightMode = "DepthOnly",
  619. useInPreview = true,
  620. // Template
  621. passTemplatePath = UniversalTarget.kUberTemplatePath,
  622. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  623. // Port Mask
  624. validVertexBlocks = CoreBlockMasks.Vertex,
  625. validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly,
  626. // Fields
  627. structs = CoreStructCollections.Default,
  628. fieldDependencies = CoreFieldDependencies.Default,
  629. // Conditional State
  630. renderStates = CoreRenderStates.DepthOnly(target),
  631. pragmas = CorePragmas.Instanced,
  632. defines = new DefineCollection(),
  633. keywords = new KeywordCollection(),
  634. includes = CoreIncludes.DepthOnly,
  635. // Custom Interpolator Support
  636. customInterpolators = CoreCustomInterpDescriptors.Common
  637. };
  638. AddAlphaClipControlToPass(ref result, target);
  639. return result;
  640. }
  641. // used by lit/unlit subtargets
  642. public static PassDescriptor DepthNormal(UniversalTarget target)
  643. {
  644. var result = new PassDescriptor()
  645. {
  646. // Definition
  647. displayName = "DepthNormals",
  648. referenceName = "SHADERPASS_DEPTHNORMALS",
  649. lightMode = "DepthNormals",
  650. useInPreview = false,
  651. // Template
  652. passTemplatePath = UniversalTarget.kUberTemplatePath,
  653. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  654. // Port Mask
  655. validVertexBlocks = CoreBlockMasks.Vertex,
  656. validPixelBlocks = CoreBlockMasks.FragmentDepthNormals,
  657. // Fields
  658. structs = CoreStructCollections.Default,
  659. requiredFields = CoreRequiredFields.DepthNormals,
  660. fieldDependencies = CoreFieldDependencies.Default,
  661. // Conditional State
  662. renderStates = CoreRenderStates.DepthNormalsOnly(target),
  663. pragmas = CorePragmas.Instanced,
  664. defines = new DefineCollection(),
  665. keywords = new KeywordCollection(),
  666. includes = CoreIncludes.DepthNormalsOnly,
  667. // Custom Interpolator Support
  668. customInterpolators = CoreCustomInterpDescriptors.Common
  669. };
  670. AddAlphaClipControlToPass(ref result, target);
  671. return result;
  672. }
  673. // used by lit/unlit subtargets
  674. public static PassDescriptor DepthNormalOnly(UniversalTarget target)
  675. {
  676. var result = new PassDescriptor()
  677. {
  678. // Definition
  679. displayName = "DepthNormalsOnly",
  680. referenceName = "SHADERPASS_DEPTHNORMALSONLY",
  681. lightMode = "DepthNormalsOnly",
  682. useInPreview = false,
  683. // Template
  684. passTemplatePath = UniversalTarget.kUberTemplatePath,
  685. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  686. // Port Mask
  687. validVertexBlocks = CoreBlockMasks.Vertex,
  688. validPixelBlocks = CoreBlockMasks.FragmentDepthNormals,
  689. // Fields
  690. structs = CoreStructCollections.Default,
  691. requiredFields = CoreRequiredFields.DepthNormals,
  692. fieldDependencies = CoreFieldDependencies.Default,
  693. // Conditional State
  694. renderStates = CoreRenderStates.DepthNormalsOnly(target),
  695. pragmas = CorePragmas.Instanced,
  696. defines = new DefineCollection(),
  697. keywords = new KeywordCollection(),
  698. includes = CoreIncludes.DepthNormalsOnly,
  699. // Custom Interpolator Support
  700. customInterpolators = CoreCustomInterpDescriptors.Common
  701. };
  702. AddAlphaClipControlToPass(ref result, target);
  703. return result;
  704. }
  705. // used by lit/unlit targets
  706. public static PassDescriptor ShadowCaster(UniversalTarget target)
  707. {
  708. var result = new PassDescriptor()
  709. {
  710. // Definition
  711. displayName = "ShadowCaster",
  712. referenceName = "SHADERPASS_SHADOWCASTER",
  713. lightMode = "ShadowCaster",
  714. // Template
  715. passTemplatePath = UniversalTarget.kUberTemplatePath,
  716. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  717. // Port Mask
  718. validVertexBlocks = CoreBlockMasks.Vertex,
  719. validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly,
  720. // Fields
  721. structs = CoreStructCollections.Default,
  722. requiredFields = CoreRequiredFields.ShadowCaster,
  723. fieldDependencies = CoreFieldDependencies.Default,
  724. // Conditional State
  725. renderStates = CoreRenderStates.ShadowCaster(target),
  726. pragmas = CorePragmas.Instanced,
  727. defines = new DefineCollection(),
  728. keywords = new KeywordCollection() { CoreKeywords.ShadowCaster },
  729. includes = CoreIncludes.ShadowCaster,
  730. // Custom Interpolator Support
  731. customInterpolators = CoreCustomInterpDescriptors.Common
  732. };
  733. AddAlphaClipControlToPass(ref result, target);
  734. return result;
  735. }
  736. public static PassDescriptor MotionVectors(UniversalTarget target)
  737. {
  738. var result = new PassDescriptor()
  739. {
  740. // Definition
  741. displayName = "MotionVectors",
  742. referenceName = "SHADERPASS_MOTIONVECTORS",
  743. lightMode = "MotionVectors",
  744. // Template
  745. passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"),
  746. sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(),
  747. // Port Mask
  748. validVertexBlocks = CoreBlockMasks.Vertex,
  749. // Fields
  750. structs = CoreStructCollections.Default,
  751. requiredFields = CoreRequiredFields.MotionVectors,
  752. fieldDependencies = CoreFieldDependencies.Default,
  753. // Conditional State
  754. defines = new DefineCollection(),
  755. renderStates = CoreRenderStates.Default,
  756. pragmas = CorePragmas.DOTSInstanced,
  757. includes = CoreIncludes.MotionVectors,
  758. };
  759. AddAlphaClipControlToPass(ref result, target);
  760. return result;
  761. }
  762. public static PassDescriptor SceneSelection(UniversalTarget target)
  763. {
  764. var result = new PassDescriptor()
  765. {
  766. // Definition
  767. displayName = "SceneSelectionPass",
  768. referenceName = "SHADERPASS_DEPTHONLY",
  769. lightMode = "SceneSelectionPass",
  770. useInPreview = false,
  771. // Template
  772. passTemplatePath = UniversalTarget.kUberTemplatePath,
  773. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  774. // Port Mask
  775. validVertexBlocks = CoreBlockMasks.Vertex,
  776. validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly,
  777. // Fields
  778. structs = CoreStructCollections.Default,
  779. fieldDependencies = CoreFieldDependencies.Default,
  780. // Conditional State
  781. renderStates = CoreRenderStates.SceneSelection(target),
  782. pragmas = CorePragmas.Instanced,
  783. defines = new DefineCollection { CoreDefines.SceneSelection, { CoreKeywordDescriptors.AlphaClipThreshold, 1 } },
  784. keywords = new KeywordCollection(),
  785. includes = CoreIncludes.SceneSelection,
  786. // Custom Interpolator Support
  787. customInterpolators = CoreCustomInterpDescriptors.Common
  788. };
  789. AddAlphaClipControlToPass(ref result, target);
  790. return result;
  791. }
  792. public static PassDescriptor ScenePicking(UniversalTarget target)
  793. {
  794. var result = new PassDescriptor()
  795. {
  796. // Definition
  797. displayName = "ScenePickingPass",
  798. referenceName = "SHADERPASS_DEPTHONLY",
  799. lightMode = "Picking",
  800. useInPreview = false,
  801. // Template
  802. passTemplatePath = UniversalTarget.kUberTemplatePath,
  803. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  804. // Port Mask
  805. validVertexBlocks = CoreBlockMasks.Vertex,
  806. validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly,
  807. // Fields
  808. structs = CoreStructCollections.Default,
  809. fieldDependencies = CoreFieldDependencies.Default,
  810. // Conditional State
  811. renderStates = CoreRenderStates.ScenePicking(target),
  812. pragmas = CorePragmas.Instanced,
  813. defines = new DefineCollection { CoreDefines.ScenePicking, { CoreKeywordDescriptors.AlphaClipThreshold, 1 } },
  814. keywords = new KeywordCollection(),
  815. includes = CoreIncludes.ScenePicking,
  816. // Custom Interpolator Support
  817. customInterpolators = CoreCustomInterpDescriptors.Common
  818. };
  819. AddAlphaClipControlToPass(ref result, target);
  820. return result;
  821. }
  822. public static PassDescriptor _2DSceneSelection(UniversalTarget target)
  823. {
  824. var result = new PassDescriptor()
  825. {
  826. // Definition
  827. displayName = "SceneSelectionPass",
  828. referenceName = "SHADERPASS_DEPTHONLY",
  829. lightMode = "SceneSelectionPass",
  830. useInPreview = false,
  831. // Template
  832. passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"),
  833. sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(),
  834. // Port Mask
  835. validVertexBlocks = CoreBlockMasks.Vertex,
  836. validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly,
  837. // Fields
  838. structs = CoreStructCollections.Default,
  839. fieldDependencies = CoreFieldDependencies.Default,
  840. // Conditional State
  841. renderStates = CoreRenderStates.SceneSelection(target),
  842. pragmas = CorePragmas._2DDefault,
  843. defines = new DefineCollection { CoreDefines.SceneSelection, { CoreKeywordDescriptors.AlphaClipThreshold, 0 } },
  844. keywords = new KeywordCollection(),
  845. includes = CoreIncludes.ScenePicking,
  846. // Custom Interpolator Support
  847. customInterpolators = CoreCustomInterpDescriptors.Common
  848. };
  849. AddAlphaClipControlToPass(ref result, target);
  850. return result;
  851. }
  852. public static PassDescriptor _2DScenePicking(UniversalTarget target)
  853. {
  854. var result = new PassDescriptor()
  855. {
  856. // Definition
  857. displayName = "ScenePickingPass",
  858. referenceName = "SHADERPASS_DEPTHONLY",
  859. lightMode = "Picking",
  860. useInPreview = false,
  861. // Template
  862. passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"),
  863. sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(),
  864. // Port Mask
  865. validVertexBlocks = CoreBlockMasks.Vertex,
  866. validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly,
  867. // Fields
  868. structs = CoreStructCollections.Default,
  869. fieldDependencies = CoreFieldDependencies.Default,
  870. // Conditional State
  871. renderStates = CoreRenderStates.ScenePicking(target),
  872. pragmas = CorePragmas._2DDefault,
  873. defines = new DefineCollection { CoreDefines.ScenePicking, { CoreKeywordDescriptors.AlphaClipThreshold, 0 } },
  874. keywords = new KeywordCollection(),
  875. includes = CoreIncludes.SceneSelection,
  876. // Custom Interpolator Support
  877. customInterpolators = CoreCustomInterpDescriptors.Common
  878. };
  879. AddAlphaClipControlToPass(ref result, target);
  880. return result;
  881. }
  882. }
  883. #endregion
  884. #region PortMasks
  885. class CoreBlockMasks
  886. {
  887. public static readonly BlockFieldDescriptor[] Vertex = new BlockFieldDescriptor[]
  888. {
  889. BlockFields.VertexDescription.Position,
  890. BlockFields.VertexDescription.Normal,
  891. BlockFields.VertexDescription.Tangent,
  892. };
  893. public static readonly BlockFieldDescriptor[] FragmentAlphaOnly = new BlockFieldDescriptor[]
  894. {
  895. BlockFields.SurfaceDescription.Alpha,
  896. BlockFields.SurfaceDescription.AlphaClipThreshold,
  897. };
  898. public static readonly BlockFieldDescriptor[] FragmentColorAlpha = new BlockFieldDescriptor[]
  899. {
  900. BlockFields.SurfaceDescription.BaseColor,
  901. BlockFields.SurfaceDescription.Alpha,
  902. BlockFields.SurfaceDescription.AlphaClipThreshold,
  903. };
  904. public static readonly BlockFieldDescriptor[] FragmentDepthNormals = new BlockFieldDescriptor[]
  905. {
  906. BlockFields.SurfaceDescription.NormalOS,
  907. BlockFields.SurfaceDescription.NormalTS,
  908. BlockFields.SurfaceDescription.NormalWS,
  909. BlockFields.SurfaceDescription.Alpha,
  910. BlockFields.SurfaceDescription.AlphaClipThreshold,
  911. };
  912. }
  913. #endregion
  914. #region StructCollections
  915. static class CoreStructCollections
  916. {
  917. public static readonly StructCollection Default = new StructCollection
  918. {
  919. { Structs.Attributes },
  920. { UniversalStructs.Varyings },
  921. { Structs.SurfaceDescriptionInputs },
  922. { Structs.VertexDescriptionInputs },
  923. };
  924. }
  925. #endregion
  926. #region RequiredFields
  927. static class CoreRequiredFields
  928. {
  929. public static readonly FieldCollection ShadowCaster = new FieldCollection()
  930. {
  931. StructFields.Varyings.normalWS,
  932. };
  933. public static readonly FieldCollection DepthNormals = new FieldCollection()
  934. {
  935. StructFields.Attributes.uv1, // needed for meta vertex position
  936. StructFields.Varyings.normalWS,
  937. StructFields.Varyings.tangentWS, // needed for vertex lighting
  938. };
  939. public static readonly FieldCollection MotionVectors = new FieldCollection()
  940. {
  941. StructFields.Attributes.uv4, // needed for previousPositionOS
  942. UniversalStructFields.Varyings.curPositionCS,
  943. UniversalStructFields.Varyings.prevPositionCS,
  944. };
  945. }
  946. #endregion
  947. #region FieldDependencies
  948. static class CoreFieldDependencies
  949. {
  950. public static readonly DependencyCollection Default = new DependencyCollection()
  951. {
  952. { FieldDependencies.Default },
  953. new FieldDependency(UniversalStructFields.Varyings.stereoTargetEyeIndexAsRTArrayIdx, StructFields.Attributes.instanceID),
  954. new FieldDependency(UniversalStructFields.Varyings.stereoTargetEyeIndexAsBlendIdx0, StructFields.Attributes.instanceID),
  955. };
  956. }
  957. #endregion
  958. #region RenderStates
  959. static class CoreRenderStates
  960. {
  961. public static class Uniforms
  962. {
  963. public static readonly string srcBlend = "[" + Property.SrcBlend + "]";
  964. public static readonly string dstBlend = "[" + Property.DstBlend + "]";
  965. public static readonly string cullMode = "[" + Property.CullMode + "]";
  966. public static readonly string zWrite = "[" + Property.ZWrite + "]";
  967. public static readonly string zTest = "[" + Property.ZTest + "]";
  968. }
  969. // used by sprite targets, NOT used by lit/unlit anymore
  970. public static readonly RenderStateCollection Default = new RenderStateCollection
  971. {
  972. { RenderState.ZTest(ZTest.LEqual) },
  973. { RenderState.ZWrite(ZWrite.On), new FieldCondition(UniversalFields.SurfaceOpaque, true) },
  974. { RenderState.ZWrite(ZWrite.Off), new FieldCondition(UniversalFields.SurfaceTransparent, true) },
  975. { RenderState.Cull(Cull.Back), new FieldCondition(Fields.DoubleSided, false) },
  976. { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) },
  977. { RenderState.Blend(Blend.One, Blend.Zero), new FieldCondition(UniversalFields.SurfaceOpaque, true) },
  978. { RenderState.Blend(Blend.SrcAlpha, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition(Fields.BlendAlpha, true) },
  979. { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition(UniversalFields.BlendPremultiply, true) },
  980. { RenderState.Blend(Blend.SrcAlpha, Blend.One, Blend.One, Blend.One), new FieldCondition(UniversalFields.BlendAdd, true) },
  981. { RenderState.Blend(Blend.DstColor, Blend.Zero), new FieldCondition(UniversalFields.BlendMultiply, true) },
  982. };
  983. // used by lit/unlit subtargets
  984. public static readonly RenderStateCollection MaterialControlledRenderState = new RenderStateCollection
  985. {
  986. { RenderState.ZTest(Uniforms.zTest) },
  987. { RenderState.ZWrite(Uniforms.zWrite) },
  988. { RenderState.Cull(Uniforms.cullMode) },
  989. { RenderState.Blend(Uniforms.srcBlend, Uniforms.dstBlend) }, //, Uniforms.alphaSrcBlend, Uniforms.alphaDstBlend) },
  990. };
  991. public static Cull RenderFaceToCull(RenderFace renderFace)
  992. {
  993. switch (renderFace)
  994. {
  995. case RenderFace.Back:
  996. return Cull.Front;
  997. case RenderFace.Front:
  998. return Cull.Back;
  999. case RenderFace.Both:
  1000. return Cull.Off;
  1001. }
  1002. return Cull.Back;
  1003. }
  1004. // used by lit/unlit subtargets
  1005. public static RenderStateCollection UberSwitchedRenderState(UniversalTarget target)
  1006. {
  1007. if (target.allowMaterialOverride)
  1008. return MaterialControlledRenderState;
  1009. else
  1010. {
  1011. var result = new RenderStateCollection();
  1012. result.Add(RenderState.ZTest(target.zTestMode.ToString()));
  1013. if (target.zWriteControl == ZWriteControl.Auto)
  1014. {
  1015. if (target.surfaceType == SurfaceType.Opaque)
  1016. result.Add(RenderState.ZWrite(ZWrite.On));
  1017. else
  1018. result.Add(RenderState.ZWrite(ZWrite.Off));
  1019. }
  1020. else if (target.zWriteControl == ZWriteControl.ForceEnabled)
  1021. result.Add(RenderState.ZWrite(ZWrite.On));
  1022. else
  1023. result.Add(RenderState.ZWrite(ZWrite.Off));
  1024. result.Add(RenderState.Cull(RenderFaceToCull(target.renderFace)));
  1025. if (target.surfaceType == SurfaceType.Opaque)
  1026. {
  1027. result.Add(RenderState.Blend(Blend.One, Blend.Zero));
  1028. }
  1029. else
  1030. switch (target.alphaMode)
  1031. {
  1032. case AlphaMode.Alpha:
  1033. result.Add(RenderState.Blend(Blend.SrcAlpha, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha));
  1034. break;
  1035. case AlphaMode.Premultiply:
  1036. result.Add(RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha));
  1037. break;
  1038. case AlphaMode.Additive:
  1039. result.Add(RenderState.Blend(Blend.SrcAlpha, Blend.One, Blend.One, Blend.One));
  1040. break;
  1041. case AlphaMode.Multiply:
  1042. result.Add(RenderState.Blend(Blend.DstColor, Blend.Zero));
  1043. break;
  1044. }
  1045. return result;
  1046. }
  1047. }
  1048. // used by lit target ONLY
  1049. public static readonly RenderStateCollection Meta = new RenderStateCollection
  1050. {
  1051. { RenderState.Cull(Cull.Off) },
  1052. };
  1053. public static RenderStateDescriptor UberSwitchedCullRenderState(UniversalTarget target)
  1054. {
  1055. if (target.allowMaterialOverride)
  1056. return RenderState.Cull(Uniforms.cullMode);
  1057. else
  1058. return RenderState.Cull(RenderFaceToCull(target.renderFace));
  1059. }
  1060. // used by lit/unlit targets
  1061. public static RenderStateCollection ShadowCaster(UniversalTarget target)
  1062. {
  1063. var result = new RenderStateCollection
  1064. {
  1065. { RenderState.ZTest(ZTest.LEqual) },
  1066. { RenderState.ZWrite(ZWrite.On) },
  1067. { UberSwitchedCullRenderState(target) },
  1068. { RenderState.ColorMask("ColorMask 0") },
  1069. };
  1070. return result;
  1071. }
  1072. // used by lit/unlit targets
  1073. public static RenderStateCollection DepthOnly(UniversalTarget target)
  1074. {
  1075. var result = new RenderStateCollection
  1076. {
  1077. { RenderState.ZTest(ZTest.LEqual) },
  1078. { RenderState.ZWrite(ZWrite.On) },
  1079. { UberSwitchedCullRenderState(target) },
  1080. { RenderState.ColorMask("ColorMask 0") },
  1081. };
  1082. return result;
  1083. }
  1084. // used by lit target ONLY
  1085. public static RenderStateCollection DepthNormalsOnly(UniversalTarget target)
  1086. {
  1087. var result = new RenderStateCollection
  1088. {
  1089. { RenderState.ZTest(ZTest.LEqual) },
  1090. { RenderState.ZWrite(ZWrite.On) },
  1091. { UberSwitchedCullRenderState(target) }
  1092. };
  1093. return result;
  1094. }
  1095. // Used by all targets
  1096. public static RenderStateCollection SceneSelection(UniversalTarget target)
  1097. {
  1098. var result = new RenderStateCollection
  1099. {
  1100. { RenderState.Cull(Cull.Off) },
  1101. };
  1102. return result;
  1103. }
  1104. public static RenderStateCollection ScenePicking(UniversalTarget target)
  1105. {
  1106. var result = new RenderStateCollection
  1107. {
  1108. { UberSwitchedCullRenderState(target) }
  1109. };
  1110. return result;
  1111. }
  1112. }
  1113. #endregion
  1114. #region Pragmas
  1115. static class CorePragmas
  1116. {
  1117. public static readonly PragmaCollection Default = new PragmaCollection
  1118. {
  1119. { Pragma.Target(ShaderModel.Target20) },
  1120. { Pragma.OnlyRenderers(new[] { Platform.GLES, Platform.GLES3, Platform.GLCore, Platform.D3D11 }) },
  1121. { Pragma.Vertex("vert") },
  1122. { Pragma.Fragment("frag") },
  1123. };
  1124. public static readonly PragmaCollection Instanced = new PragmaCollection
  1125. {
  1126. { Pragma.Target(ShaderModel.Target20) },
  1127. { Pragma.OnlyRenderers(new[] { Platform.GLES, Platform.GLES3, Platform.GLCore, Platform.D3D11 }) },
  1128. { Pragma.MultiCompileInstancing },
  1129. { Pragma.Vertex("vert") },
  1130. { Pragma.Fragment("frag") },
  1131. };
  1132. public static readonly PragmaCollection Forward = new PragmaCollection
  1133. {
  1134. { Pragma.Target(ShaderModel.Target20) },
  1135. { Pragma.OnlyRenderers(new[] { Platform.GLES, Platform.GLES3, Platform.GLCore, Platform.D3D11 }) },
  1136. { Pragma.MultiCompileInstancing },
  1137. { Pragma.MultiCompileFog },
  1138. { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) },
  1139. { Pragma.Vertex("vert") },
  1140. { Pragma.Fragment("frag") },
  1141. };
  1142. public static readonly PragmaCollection _2DDefault = new PragmaCollection
  1143. {
  1144. { Pragma.Target(ShaderModel.Target20) },
  1145. { Pragma.ExcludeRenderers(new[] { Platform.D3D9 }) },
  1146. { Pragma.Vertex("vert") },
  1147. { Pragma.Fragment("frag") },
  1148. };
  1149. public static readonly PragmaCollection DOTSDefault = new PragmaCollection
  1150. {
  1151. { Pragma.Target(ShaderModel.Target45) },
  1152. { Pragma.ExcludeRenderers(new[] { Platform.GLES, Platform.GLES3, Platform.GLCore }) },
  1153. { Pragma.Vertex("vert") },
  1154. { Pragma.Fragment("frag") },
  1155. };
  1156. public static readonly PragmaCollection DOTSInstanced = new PragmaCollection
  1157. {
  1158. { Pragma.Target(ShaderModel.Target45) },
  1159. { Pragma.ExcludeRenderers(new[] { Platform.GLES, Platform.GLES3, Platform.GLCore }) },
  1160. { Pragma.MultiCompileInstancing },
  1161. { Pragma.DOTSInstancing },
  1162. { Pragma.Vertex("vert") },
  1163. { Pragma.Fragment("frag") },
  1164. };
  1165. public static readonly PragmaCollection DOTSForward = new PragmaCollection
  1166. {
  1167. { Pragma.Target(ShaderModel.Target45) },
  1168. { Pragma.ExcludeRenderers(new[] { Platform.GLES, Platform.GLES3, Platform.GLCore }) },
  1169. { Pragma.MultiCompileInstancing },
  1170. { Pragma.MultiCompileFog },
  1171. { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) },
  1172. { Pragma.DOTSInstancing },
  1173. { Pragma.Vertex("vert") },
  1174. { Pragma.Fragment("frag") },
  1175. };
  1176. public static readonly PragmaCollection DOTSGBuffer = new PragmaCollection
  1177. {
  1178. { Pragma.Target(ShaderModel.Target45) },
  1179. { Pragma.ExcludeRenderers(new[] { Platform.GLES, Platform.GLES3, Platform.GLCore }) },
  1180. { Pragma.MultiCompileInstancing },
  1181. { Pragma.MultiCompileFog },
  1182. { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) },
  1183. { Pragma.DOTSInstancing },
  1184. { Pragma.Vertex("vert") },
  1185. { Pragma.Fragment("frag") },
  1186. };
  1187. }
  1188. #endregion
  1189. #region Includes
  1190. static class CoreIncludes
  1191. {
  1192. const string kColor = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl";
  1193. const string kTexture = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl";
  1194. const string kCore = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl";
  1195. const string kLighting = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl";
  1196. const string kGraphFunctions = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl";
  1197. const string kVaryings = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/Varyings.hlsl";
  1198. const string kShaderPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl";
  1199. const string kDepthOnlyPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthOnlyPass.hlsl";
  1200. const string kDepthNormalsOnlyPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthNormalsOnlyPass.hlsl";
  1201. const string kShadowCasterPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl";
  1202. const string kTextureStack = "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl";
  1203. const string kDBuffer = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl";
  1204. const string kSelectionPickingPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SelectionPickingPass.hlsl";
  1205. const string kMotionVectors = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/OculusMotionVectors.hlsl";
  1206. public static readonly IncludeCollection CorePregraph = new IncludeCollection
  1207. {
  1208. { kColor, IncludeLocation.Pregraph },
  1209. { kTexture, IncludeLocation.Pregraph },
  1210. { kCore, IncludeLocation.Pregraph },
  1211. { kLighting, IncludeLocation.Pregraph },
  1212. { kTextureStack, IncludeLocation.Pregraph }, // TODO: put this on a conditional
  1213. };
  1214. public static readonly IncludeCollection ShaderGraphPregraph = new IncludeCollection
  1215. {
  1216. { kGraphFunctions, IncludeLocation.Pregraph },
  1217. };
  1218. public static readonly IncludeCollection CorePostgraph = new IncludeCollection
  1219. {
  1220. { kShaderPass, IncludeLocation.Pregraph },
  1221. { kVaryings, IncludeLocation.Postgraph },
  1222. };
  1223. public static readonly IncludeCollection DepthOnly = new IncludeCollection
  1224. {
  1225. // Pre-graph
  1226. { CorePregraph },
  1227. { ShaderGraphPregraph },
  1228. // Post-graph
  1229. { CorePostgraph },
  1230. { kDepthOnlyPass, IncludeLocation.Postgraph },
  1231. };
  1232. public static readonly IncludeCollection DepthNormalsOnly = new IncludeCollection
  1233. {
  1234. // Pre-graph
  1235. { CorePregraph },
  1236. { ShaderGraphPregraph },
  1237. // Post-graph
  1238. { CorePostgraph },
  1239. { kDepthNormalsOnlyPass, IncludeLocation.Postgraph },
  1240. };
  1241. public static readonly IncludeCollection ShadowCaster = new IncludeCollection
  1242. {
  1243. // Pre-graph
  1244. { CorePregraph },
  1245. { ShaderGraphPregraph },
  1246. // Post-graph
  1247. { CorePostgraph },
  1248. { kShadowCasterPass, IncludeLocation.Postgraph },
  1249. };
  1250. public static readonly IncludeCollection DBufferPregraph = new IncludeCollection
  1251. {
  1252. { kDBuffer, IncludeLocation.Pregraph },
  1253. };
  1254. public static readonly IncludeCollection SceneSelection = new IncludeCollection
  1255. {
  1256. // Pre-graph
  1257. { CorePregraph },
  1258. { ShaderGraphPregraph },
  1259. // Post-graph
  1260. { CorePostgraph },
  1261. { kSelectionPickingPass, IncludeLocation.Postgraph },
  1262. };
  1263. public static readonly IncludeCollection ScenePicking = new IncludeCollection
  1264. {
  1265. // Pre-graph
  1266. { CorePregraph },
  1267. { ShaderGraphPregraph },
  1268. // Post-graph
  1269. { CorePostgraph },
  1270. { kSelectionPickingPass, IncludeLocation.Postgraph },
  1271. };
  1272. public static readonly IncludeCollection MotionVectors = new IncludeCollection
  1273. {
  1274. // Pre-graph
  1275. { CoreIncludes.CorePregraph },
  1276. { CoreIncludes.ShaderGraphPregraph },
  1277. // Post-graph
  1278. { CoreIncludes.CorePostgraph },
  1279. { kMotionVectors, IncludeLocation.Postgraph },
  1280. };
  1281. }
  1282. #endregion
  1283. #region Defines
  1284. static class CoreDefines
  1285. {
  1286. public static readonly DefineCollection UseLegacySpriteBlocks = new DefineCollection
  1287. {
  1288. { CoreKeywordDescriptors.UseLegacySpriteBlocks, 1, new FieldCondition(CoreFields.UseLegacySpriteBlocks, true) },
  1289. };
  1290. public static readonly DefineCollection UseFragmentFog = new DefineCollection()
  1291. {
  1292. {CoreKeywordDescriptors.UseFragmentFog, 1},
  1293. };
  1294. public static readonly DefineCollection SceneSelection = new DefineCollection
  1295. {
  1296. { CoreKeywordDescriptors.SceneSelectionPass, 1 },
  1297. };
  1298. public static readonly DefineCollection ScenePicking = new DefineCollection
  1299. {
  1300. { CoreKeywordDescriptors.ScenePickingPass, 1 },
  1301. };
  1302. }
  1303. #endregion
  1304. #region KeywordDescriptors
  1305. static class CoreKeywordDescriptors
  1306. {
  1307. public static readonly KeywordDescriptor StaticLightmap = new KeywordDescriptor()
  1308. {
  1309. displayName = "Static Lightmap",
  1310. referenceName = "LIGHTMAP_ON",
  1311. type = KeywordType.Boolean,
  1312. definition = KeywordDefinition.MultiCompile,
  1313. scope = KeywordScope.Global,
  1314. };
  1315. public static readonly KeywordDescriptor DynamicLightmap = new KeywordDescriptor()
  1316. {
  1317. displayName = "Dynamic Lightmap",
  1318. referenceName = "DYNAMICLIGHTMAP_ON",
  1319. type = KeywordType.Boolean,
  1320. definition = KeywordDefinition.MultiCompile,
  1321. scope = KeywordScope.Global,
  1322. };
  1323. public static readonly KeywordDescriptor DirectionalLightmapCombined = new KeywordDescriptor()
  1324. {
  1325. displayName = "Directional Lightmap Combined",
  1326. referenceName = "DIRLIGHTMAP_COMBINED",
  1327. type = KeywordType.Boolean,
  1328. definition = KeywordDefinition.MultiCompile,
  1329. scope = KeywordScope.Global,
  1330. };
  1331. public static readonly KeywordDescriptor SampleGI = new KeywordDescriptor()
  1332. {
  1333. displayName = "Sample GI",
  1334. referenceName = "_SAMPLE_GI",
  1335. type = KeywordType.Boolean,
  1336. definition = KeywordDefinition.ShaderFeature,
  1337. scope = KeywordScope.Global,
  1338. };
  1339. public static readonly KeywordDescriptor AlphaTestOn = new KeywordDescriptor()
  1340. {
  1341. displayName = ShaderKeywordStrings._ALPHATEST_ON,
  1342. referenceName = ShaderKeywordStrings._ALPHATEST_ON,
  1343. type = KeywordType.Boolean,
  1344. definition = KeywordDefinition.ShaderFeature,
  1345. scope = KeywordScope.Local,
  1346. stages = KeywordShaderStage.Fragment,
  1347. };
  1348. public static readonly KeywordDescriptor SurfaceTypeTransparent = new KeywordDescriptor()
  1349. {
  1350. displayName = ShaderKeywordStrings._SURFACE_TYPE_TRANSPARENT,
  1351. referenceName = ShaderKeywordStrings._SURFACE_TYPE_TRANSPARENT,
  1352. type = KeywordType.Boolean,
  1353. definition = KeywordDefinition.ShaderFeature,
  1354. scope = KeywordScope.Global, // needs to match HDRP
  1355. stages = KeywordShaderStage.Fragment,
  1356. };
  1357. public static readonly KeywordDescriptor AlphaPremultiplyOn = new KeywordDescriptor()
  1358. {
  1359. displayName = ShaderKeywordStrings._ALPHAPREMULTIPLY_ON,
  1360. referenceName = ShaderKeywordStrings._ALPHAPREMULTIPLY_ON,
  1361. type = KeywordType.Boolean,
  1362. definition = KeywordDefinition.ShaderFeature,
  1363. scope = KeywordScope.Local,
  1364. stages = KeywordShaderStage.Fragment,
  1365. };
  1366. public static readonly KeywordDescriptor MainLightShadows = new KeywordDescriptor()
  1367. {
  1368. displayName = "Main Light Shadows",
  1369. referenceName = "",
  1370. type = KeywordType.Enum,
  1371. definition = KeywordDefinition.MultiCompile,
  1372. scope = KeywordScope.Global,
  1373. entries = new KeywordEntry[]
  1374. {
  1375. new KeywordEntry() { displayName = "Off", referenceName = "" },
  1376. new KeywordEntry() { displayName = "No Cascade", referenceName = "MAIN_LIGHT_SHADOWS" },
  1377. new KeywordEntry() { displayName = "Cascade", referenceName = "MAIN_LIGHT_SHADOWS_CASCADE" },
  1378. new KeywordEntry() { displayName = "Screen", referenceName = "MAIN_LIGHT_SHADOWS_SCREEN" },
  1379. }
  1380. };
  1381. public static readonly KeywordDescriptor CastingPunctualLightShadow = new KeywordDescriptor()
  1382. {
  1383. displayName = "Casting Punctual Light Shadow",
  1384. referenceName = "_CASTING_PUNCTUAL_LIGHT_SHADOW",
  1385. type = KeywordType.Boolean,
  1386. definition = KeywordDefinition.MultiCompile,
  1387. scope = KeywordScope.Global,
  1388. stages = KeywordShaderStage.Vertex,
  1389. };
  1390. public static readonly KeywordDescriptor AdditionalLights = new KeywordDescriptor()
  1391. {
  1392. displayName = "Additional Lights",
  1393. referenceName = "",
  1394. type = KeywordType.Enum,
  1395. definition = KeywordDefinition.MultiCompile,
  1396. scope = KeywordScope.Global,
  1397. entries = new KeywordEntry[]
  1398. {
  1399. new KeywordEntry() { displayName = "Off", referenceName = "" },
  1400. new KeywordEntry() { displayName = "Vertex", referenceName = "ADDITIONAL_LIGHTS_VERTEX" },
  1401. new KeywordEntry() { displayName = "Fragment", referenceName = "ADDITIONAL_LIGHTS" },
  1402. }
  1403. };
  1404. public static readonly KeywordDescriptor AdditionalLightShadows = new KeywordDescriptor()
  1405. {
  1406. displayName = "Additional Light Shadows",
  1407. referenceName = "_ADDITIONAL_LIGHT_SHADOWS",
  1408. type = KeywordType.Boolean,
  1409. definition = KeywordDefinition.MultiCompile,
  1410. scope = KeywordScope.Global,
  1411. stages = KeywordShaderStage.Fragment,
  1412. };
  1413. public static readonly KeywordDescriptor ReflectionProbeBlending = new KeywordDescriptor()
  1414. {
  1415. displayName = "Reflection Probe Blending",
  1416. referenceName = "_REFLECTION_PROBE_BLENDING",
  1417. type = KeywordType.Boolean,
  1418. definition = KeywordDefinition.MultiCompile,
  1419. scope = KeywordScope.Global,
  1420. stages = KeywordShaderStage.Fragment,
  1421. };
  1422. public static readonly KeywordDescriptor ReflectionProbeBoxProjection = new KeywordDescriptor()
  1423. {
  1424. displayName = "Reflection Probe Box Projection",
  1425. referenceName = "_REFLECTION_PROBE_BOX_PROJECTION",
  1426. type = KeywordType.Boolean,
  1427. definition = KeywordDefinition.MultiCompile,
  1428. scope = KeywordScope.Global,
  1429. stages = KeywordShaderStage.Fragment,
  1430. };
  1431. public static readonly KeywordDescriptor ShadowsSoft = new KeywordDescriptor()
  1432. {
  1433. displayName = "Shadows Soft",
  1434. referenceName = "_SHADOWS_SOFT",
  1435. type = KeywordType.Boolean,
  1436. definition = KeywordDefinition.MultiCompile,
  1437. scope = KeywordScope.Global,
  1438. stages = KeywordShaderStage.Fragment,
  1439. };
  1440. public static readonly KeywordDescriptor MixedLightingSubtractive = new KeywordDescriptor()
  1441. {
  1442. displayName = "Mixed Lighting Subtractive",
  1443. referenceName = "_MIXED_LIGHTING_SUBTRACTIVE",
  1444. type = KeywordType.Boolean,
  1445. definition = KeywordDefinition.MultiCompile,
  1446. scope = KeywordScope.Global,
  1447. };
  1448. public static readonly KeywordDescriptor LightmapShadowMixing = new KeywordDescriptor()
  1449. {
  1450. displayName = "Lightmap Shadow Mixing",
  1451. referenceName = "LIGHTMAP_SHADOW_MIXING",
  1452. type = KeywordType.Boolean,
  1453. definition = KeywordDefinition.MultiCompile,
  1454. scope = KeywordScope.Global,
  1455. };
  1456. public static readonly KeywordDescriptor ShadowsShadowmask = new KeywordDescriptor()
  1457. {
  1458. displayName = "Shadows Shadowmask",
  1459. referenceName = "SHADOWS_SHADOWMASK",
  1460. type = KeywordType.Boolean,
  1461. definition = KeywordDefinition.MultiCompile,
  1462. scope = KeywordScope.Global,
  1463. };
  1464. public static readonly KeywordDescriptor LightLayers = new KeywordDescriptor()
  1465. {
  1466. displayName = "Light Layers",
  1467. referenceName = "_LIGHT_LAYERS",
  1468. type = KeywordType.Boolean,
  1469. definition = KeywordDefinition.MultiCompile,
  1470. scope = KeywordScope.Global,
  1471. stages = KeywordShaderStage.Fragment,
  1472. };
  1473. public static readonly KeywordDescriptor RenderPassEnabled = new KeywordDescriptor()
  1474. {
  1475. displayName = "Render Pass Enabled",
  1476. referenceName = "_RENDER_PASS_ENABLED",
  1477. type = KeywordType.Boolean,
  1478. definition = KeywordDefinition.MultiCompile,
  1479. scope = KeywordScope.Global,
  1480. stages = KeywordShaderStage.Fragment,
  1481. };
  1482. public static readonly KeywordDescriptor ShapeLightType0 = new KeywordDescriptor()
  1483. {
  1484. displayName = "Shape Light Type 0",
  1485. referenceName = "USE_SHAPE_LIGHT_TYPE_0",
  1486. type = KeywordType.Boolean,
  1487. definition = KeywordDefinition.MultiCompile,
  1488. scope = KeywordScope.Global,
  1489. };
  1490. public static readonly KeywordDescriptor ShapeLightType1 = new KeywordDescriptor()
  1491. {
  1492. displayName = "Shape Light Type 1",
  1493. referenceName = "USE_SHAPE_LIGHT_TYPE_1",
  1494. type = KeywordType.Boolean,
  1495. definition = KeywordDefinition.MultiCompile,
  1496. scope = KeywordScope.Global,
  1497. };
  1498. public static readonly KeywordDescriptor ShapeLightType2 = new KeywordDescriptor()
  1499. {
  1500. displayName = "Shape Light Type 2",
  1501. referenceName = "USE_SHAPE_LIGHT_TYPE_2",
  1502. type = KeywordType.Boolean,
  1503. definition = KeywordDefinition.MultiCompile,
  1504. scope = KeywordScope.Global,
  1505. };
  1506. public static readonly KeywordDescriptor ShapeLightType3 = new KeywordDescriptor()
  1507. {
  1508. displayName = "Shape Light Type 3",
  1509. referenceName = "USE_SHAPE_LIGHT_TYPE_3",
  1510. type = KeywordType.Boolean,
  1511. definition = KeywordDefinition.MultiCompile,
  1512. scope = KeywordScope.Global,
  1513. };
  1514. public static readonly KeywordDescriptor UseLegacySpriteBlocks = new KeywordDescriptor()
  1515. {
  1516. displayName = "UseLegacySpriteBlocks",
  1517. referenceName = "USELEGACYSPRITEBLOCKS",
  1518. type = KeywordType.Boolean,
  1519. };
  1520. public static readonly KeywordDescriptor UseFragmentFog = new KeywordDescriptor()
  1521. {
  1522. displayName = "UseFragmentFog",
  1523. referenceName = "_FOG_FRAGMENT",
  1524. type = KeywordType.Boolean,
  1525. };
  1526. public static readonly KeywordDescriptor GBufferNormalsOct = new KeywordDescriptor()
  1527. {
  1528. displayName = "GBuffer normal octahedron encoding",
  1529. referenceName = "_GBUFFER_NORMALS_OCT",
  1530. type = KeywordType.Boolean,
  1531. definition = KeywordDefinition.MultiCompile,
  1532. scope = KeywordScope.Global,
  1533. stages = KeywordShaderStage.Fragment,
  1534. };
  1535. public static readonly KeywordDescriptor DBuffer = new KeywordDescriptor()
  1536. {
  1537. displayName = "Decals",
  1538. referenceName = "",
  1539. type = KeywordType.Enum,
  1540. definition = KeywordDefinition.MultiCompile,
  1541. scope = KeywordScope.Global,
  1542. entries = new KeywordEntry[]
  1543. {
  1544. new KeywordEntry() { displayName = "Off", referenceName = "" },
  1545. new KeywordEntry() { displayName = "DBuffer Mrt1", referenceName = "DBUFFER_MRT1" },
  1546. new KeywordEntry() { displayName = "DBuffer Mrt2", referenceName = "DBUFFER_MRT2" },
  1547. new KeywordEntry() { displayName = "DBuffer Mrt3", referenceName = "DBUFFER_MRT3" },
  1548. },
  1549. stages = KeywordShaderStage.Fragment,
  1550. };
  1551. public static readonly KeywordDescriptor DebugDisplay = new KeywordDescriptor()
  1552. {
  1553. displayName = "Debug Display",
  1554. referenceName = "DEBUG_DISPLAY",
  1555. type = KeywordType.Boolean,
  1556. definition = KeywordDefinition.MultiCompile,
  1557. scope = KeywordScope.Global,
  1558. stages = KeywordShaderStage.Fragment,
  1559. };
  1560. public static readonly KeywordDescriptor SceneSelectionPass = new KeywordDescriptor()
  1561. {
  1562. displayName = "Scene Selection Pass",
  1563. referenceName = "SCENESELECTIONPASS",
  1564. type = KeywordType.Boolean,
  1565. };
  1566. public static readonly KeywordDescriptor ScenePickingPass = new KeywordDescriptor()
  1567. {
  1568. displayName = "Scene Picking Pass",
  1569. referenceName = "SCENEPICKINGPASS",
  1570. type = KeywordType.Boolean,
  1571. };
  1572. public static readonly KeywordDescriptor AlphaClipThreshold = new KeywordDescriptor()
  1573. {
  1574. displayName = "AlphaClipThreshold",
  1575. referenceName = "ALPHA_CLIP_THRESHOLD",
  1576. type = KeywordType.Boolean,
  1577. definition = KeywordDefinition.Predefined,
  1578. };
  1579. public static readonly KeywordDescriptor LightCookies = new KeywordDescriptor()
  1580. {
  1581. displayName = "Light Cookies",
  1582. referenceName = "_LIGHT_COOKIES",
  1583. type = KeywordType.Boolean,
  1584. definition = KeywordDefinition.MultiCompile,
  1585. scope = KeywordScope.Global,
  1586. stages = KeywordShaderStage.Fragment,
  1587. };
  1588. public static readonly KeywordDescriptor ClusteredRendering = new KeywordDescriptor()
  1589. {
  1590. displayName = "Clustered Rendering",
  1591. referenceName = "_CLUSTERED_RENDERING",
  1592. type = KeywordType.Boolean,
  1593. definition = KeywordDefinition.MultiCompile,
  1594. scope = KeywordScope.Global,
  1595. };
  1596. public static readonly KeywordDescriptor EditorVisualization = new KeywordDescriptor()
  1597. {
  1598. displayName = "Editor Visualization",
  1599. referenceName = "EDITOR_VISUALIZATION",
  1600. type = KeywordType.Boolean,
  1601. definition = KeywordDefinition.ShaderFeature,
  1602. scope = KeywordScope.Global,
  1603. };
  1604. }
  1605. #endregion
  1606. #region Keywords
  1607. static class CoreKeywords
  1608. {
  1609. public static readonly KeywordCollection ShadowCaster = new KeywordCollection
  1610. {
  1611. { CoreKeywordDescriptors.CastingPunctualLightShadow },
  1612. };
  1613. }
  1614. #endregion
  1615. #region FieldDescriptors
  1616. static class CoreFields
  1617. {
  1618. public static readonly FieldDescriptor UseLegacySpriteBlocks = new FieldDescriptor("Universal", "UseLegacySpriteBlocks", "UNIVERSAL_USELEGACYSPRITEBLOCKS");
  1619. }
  1620. #endregion
  1621. #region CustomInterpolators
  1622. static class CoreCustomInterpDescriptors
  1623. {
  1624. public static readonly CustomInterpSubGen.Collection Common = new CustomInterpSubGen.Collection
  1625. {
  1626. // Custom interpolators are not explicitly defined in the SurfaceDescriptionInputs template.
  1627. // This entry point will let us generate a block of pass-through assignments for each field.
  1628. CustomInterpSubGen.Descriptor.MakeBlock(CustomInterpSubGen.Splice.k_spliceCopyToSDI, "output", "input"),
  1629. // sgci_PassThroughFunc is called from BuildVaryings in Varyings.hlsl to copy custom interpolators from vertex descriptions.
  1630. // this entry point allows for the function to be defined before it is used.
  1631. CustomInterpSubGen.Descriptor.MakeFunc(CustomInterpSubGen.Splice.k_splicePreSurface, "CustomInterpolatorPassThroughFunc", "Varyings", "VertexDescription", "CUSTOMINTERPOLATOR_VARYPASSTHROUGH_FUNC", "FEATURES_GRAPH_VERTEX")
  1632. };
  1633. }
  1634. #endregion
  1635. }