설명 없음
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.

UniversalTarget.cs 88KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317
  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. /// <summary>
  19. /// Options for the material type.
  20. /// </summary>
  21. public enum MaterialType
  22. {
  23. /// <summary>
  24. /// Use this for URP lit.
  25. /// </summary>
  26. Lit,
  27. /// <summary>
  28. /// Use this for URP unlit.
  29. /// </summary>
  30. Unlit,
  31. /// <summary>
  32. /// Use this for sprite lit.
  33. /// </summary>
  34. SpriteLit,
  35. /// <summary>
  36. /// Use this for Sprite unlit.
  37. /// </summary>
  38. SpriteUnlit,
  39. }
  40. /// <summary>
  41. /// Workflow modes for the shader.
  42. /// </summary>
  43. public enum WorkflowMode
  44. {
  45. /// <summary>
  46. /// Use this for specular workflow.
  47. /// </summary>
  48. Specular,
  49. /// <summary>
  50. /// Use this for metallic workflow.
  51. /// </summary>
  52. Metallic,
  53. }
  54. enum SurfaceType
  55. {
  56. Opaque,
  57. Transparent,
  58. }
  59. enum ZWriteControl
  60. {
  61. Auto = 0,
  62. ForceEnabled = 1,
  63. ForceDisabled = 2
  64. }
  65. enum ZTestMode // the values here match UnityEngine.Rendering.CompareFunction
  66. {
  67. Disabled = 0,
  68. Never = 1,
  69. Less = 2,
  70. Equal = 3,
  71. LEqual = 4, // default for most rendering
  72. Greater = 5,
  73. NotEqual = 6,
  74. GEqual = 7,
  75. Always = 8,
  76. }
  77. enum AlphaMode
  78. {
  79. Alpha,
  80. Premultiply,
  81. Additive,
  82. Multiply,
  83. }
  84. internal enum RenderFace
  85. {
  86. Front = 2, // = CullMode.Back -- render front face only
  87. Back = 1, // = CullMode.Front -- render back face only
  88. Both = 0 // = CullMode.Off -- render both faces
  89. }
  90. internal enum AdditionalMotionVectorMode
  91. {
  92. None,
  93. TimeBased,
  94. Custom
  95. }
  96. sealed class UniversalTarget : Target, IHasMetadata, ILegacyTarget, IMaySupportVFX
  97. #if HAS_VFX_GRAPH
  98. , IRequireVFXContext
  99. #endif
  100. {
  101. public override int latestVersion => 1;
  102. // Constants
  103. static readonly GUID kSourceCodeGuid = new GUID("8c72f47fdde33b14a9340e325ce56f4d"); // UniversalTarget.cs
  104. public const string kPipelineTag = "UniversalPipeline";
  105. public const string kComplexLitMaterialTypeTag = "\"UniversalMaterialType\" = \"ComplexLit\"";
  106. public const string kLitMaterialTypeTag = "\"UniversalMaterialType\" = \"Lit\"";
  107. public const string kUnlitMaterialTypeTag = "\"UniversalMaterialType\" = \"Unlit\"";
  108. public const string kAlwaysRenderMotionVectorsTag = "\"AlwaysRenderMotionVectors\" = \"true\"";
  109. public static readonly string[] kSharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories().Union(new string[]
  110. {
  111. "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates"
  112. #if HAS_VFX_GRAPH
  113. , "Packages/com.unity.visualeffectgraph/Editor/ShaderGraph/Templates"
  114. #endif
  115. }).ToArray();
  116. public const string kUberTemplatePath = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/ShaderPass.template";
  117. // SubTarget
  118. List<SubTarget> m_SubTargets;
  119. List<string> m_SubTargetNames;
  120. int activeSubTargetIndex => m_SubTargets.IndexOf(m_ActiveSubTarget);
  121. // Subtarget Data
  122. [SerializeField]
  123. List<JsonData<JsonObject>> m_Datas = new List<JsonData<JsonObject>>();
  124. // View
  125. PopupField<string> m_SubTargetField;
  126. TextField m_CustomGUIField;
  127. #if HAS_VFX_GRAPH
  128. Toggle m_SupportVFXToggle;
  129. #endif
  130. [SerializeField]
  131. JsonData<SubTarget> m_ActiveSubTarget;
  132. // when checked, allows the material to control ALL surface settings (uber shader style)
  133. [SerializeField]
  134. bool m_AllowMaterialOverride = false;
  135. [SerializeField]
  136. SurfaceType m_SurfaceType = SurfaceType.Opaque;
  137. [SerializeField]
  138. ZTestMode m_ZTestMode = ZTestMode.LEqual;
  139. [SerializeField]
  140. ZWriteControl m_ZWriteControl = ZWriteControl.Auto;
  141. [SerializeField]
  142. AlphaMode m_AlphaMode = AlphaMode.Alpha;
  143. [SerializeField]
  144. RenderFace m_RenderFace = RenderFace.Front;
  145. [SerializeField]
  146. bool m_AlphaClip = false;
  147. [SerializeField]
  148. bool m_CastShadows = true;
  149. [SerializeField]
  150. bool m_ReceiveShadows = true;
  151. [SerializeField]
  152. bool m_DisableTint = false;
  153. [SerializeField]
  154. AdditionalMotionVectorMode m_AdditionalMotionVectorMode = AdditionalMotionVectorMode.None;
  155. [SerializeField]
  156. bool m_AlembicMotionVectors = false;
  157. [SerializeField]
  158. bool m_SupportsLODCrossFade = false;
  159. [SerializeField]
  160. string m_CustomEditorGUI;
  161. [SerializeField]
  162. bool m_SupportVFX;
  163. internal override bool ignoreCustomInterpolators => m_ActiveSubTarget.value is UniversalCanvasSubTarget;
  164. internal override int padCustomInterpolatorLimit => 4;
  165. internal override bool prefersSpritePreview =>
  166. activeSubTarget is UniversalSpriteUnlitSubTarget or UniversalSpriteLitSubTarget or
  167. UniversalSpriteCustomLitSubTarget or UniversalCanvasSubTarget;
  168. public UniversalTarget()
  169. {
  170. displayName = "Universal";
  171. m_SubTargets = TargetUtils.GetSubTargets(this);
  172. m_SubTargetNames = m_SubTargets.Select(x => x.displayName).ToList();
  173. TargetUtils.ProcessSubTargetList(ref m_ActiveSubTarget, ref m_SubTargets);
  174. ProcessSubTargetDatas(m_ActiveSubTarget.value);
  175. }
  176. public string renderType
  177. {
  178. get
  179. {
  180. if (surfaceType == SurfaceType.Transparent)
  181. return $"{RenderType.Transparent}";
  182. else
  183. return $"{RenderType.Opaque}";
  184. }
  185. }
  186. // this sets up the default renderQueue -- but it can be overridden by ResetMaterialKeywords()
  187. public string renderQueue
  188. {
  189. get
  190. {
  191. if (surfaceType == SurfaceType.Transparent)
  192. return $"{UnityEditor.ShaderGraph.RenderQueue.Transparent}";
  193. else if (alphaClip)
  194. return $"{UnityEditor.ShaderGraph.RenderQueue.AlphaTest}";
  195. else
  196. return $"{UnityEditor.ShaderGraph.RenderQueue.Geometry}";
  197. }
  198. }
  199. public string disableBatching
  200. {
  201. get
  202. {
  203. if (supportsLodCrossFade)
  204. return $"{UnityEditor.ShaderGraph.DisableBatching.LODFading}";
  205. else
  206. return $"{UnityEditor.ShaderGraph.DisableBatching.False}";
  207. }
  208. }
  209. public SubTarget activeSubTarget
  210. {
  211. get => m_ActiveSubTarget.value;
  212. set => m_ActiveSubTarget = value;
  213. }
  214. public bool allowMaterialOverride
  215. {
  216. get => m_AllowMaterialOverride;
  217. set => m_AllowMaterialOverride = value;
  218. }
  219. public SurfaceType surfaceType
  220. {
  221. get => m_SurfaceType;
  222. set => m_SurfaceType = value;
  223. }
  224. public ZWriteControl zWriteControl
  225. {
  226. get => m_ZWriteControl;
  227. set => m_ZWriteControl = value;
  228. }
  229. public ZTestMode zTestMode
  230. {
  231. get => m_ZTestMode;
  232. set => m_ZTestMode = value;
  233. }
  234. public AlphaMode alphaMode
  235. {
  236. get => m_AlphaMode;
  237. set => m_AlphaMode = value;
  238. }
  239. public RenderFace renderFace
  240. {
  241. get => m_RenderFace;
  242. set => m_RenderFace = value;
  243. }
  244. public bool alphaClip
  245. {
  246. get => m_AlphaClip;
  247. set => m_AlphaClip = value;
  248. }
  249. public bool disableTint
  250. {
  251. get => m_DisableTint;
  252. set => m_DisableTint = value;
  253. }
  254. public bool castShadows
  255. {
  256. get => m_CastShadows;
  257. set => m_CastShadows = value;
  258. }
  259. public bool receiveShadows
  260. {
  261. get => m_ReceiveShadows;
  262. set => m_ReceiveShadows = value;
  263. }
  264. public AdditionalMotionVectorMode additionalMotionVectorMode
  265. {
  266. get => m_AdditionalMotionVectorMode;
  267. set => m_AdditionalMotionVectorMode = value;
  268. }
  269. public bool alembicMotionVectors
  270. {
  271. get => m_AlembicMotionVectors;
  272. set => m_AlembicMotionVectors = value;
  273. }
  274. public bool alwaysRenderMotionVectors
  275. {
  276. get => additionalMotionVectorMode != AdditionalMotionVectorMode.None || alembicMotionVectors;
  277. }
  278. public bool supportsLodCrossFade
  279. {
  280. get => m_SupportsLODCrossFade;
  281. set => m_SupportsLODCrossFade = value;
  282. }
  283. public string customEditorGUI
  284. {
  285. get => m_CustomEditorGUI;
  286. set => m_CustomEditorGUI = value;
  287. }
  288. // generally used to know if we need to build a depth pass
  289. public bool mayWriteDepth
  290. {
  291. get
  292. {
  293. if (allowMaterialOverride)
  294. {
  295. // material may or may not choose to write depth... we should create the depth pass
  296. return true;
  297. }
  298. else
  299. {
  300. switch (zWriteControl)
  301. {
  302. case ZWriteControl.Auto:
  303. return (surfaceType == SurfaceType.Opaque);
  304. case ZWriteControl.ForceDisabled:
  305. return false;
  306. default:
  307. return true;
  308. }
  309. }
  310. }
  311. }
  312. public override bool IsActive()
  313. {
  314. bool isUniversalRenderPipeline = GraphicsSettings.currentRenderPipeline is UniversalRenderPipelineAsset;
  315. return isUniversalRenderPipeline && activeSubTarget.IsActive();
  316. }
  317. public override bool IsNodeAllowedByTarget(Type nodeType)
  318. {
  319. SRPFilterAttribute srpFilter = NodeClassCache.GetAttributeOnNodeType<SRPFilterAttribute>(nodeType);
  320. bool worksWithThisSrp = srpFilter == null || srpFilter.srpTypes.Contains(typeof(UniversalRenderPipeline));
  321. SubTargetFilterAttribute subTargetFilter = NodeClassCache.GetAttributeOnNodeType<SubTargetFilterAttribute>(nodeType);
  322. bool worksWithThisSubTarget = subTargetFilter == null || subTargetFilter.subTargetTypes.Contains(activeSubTarget.GetType());
  323. if (activeSubTarget.IsActive())
  324. worksWithThisSubTarget &= activeSubTarget.IsNodeAllowedBySubTarget(nodeType);
  325. return worksWithThisSrp && worksWithThisSubTarget && base.IsNodeAllowedByTarget(nodeType);
  326. }
  327. public override void Setup(ref TargetSetupContext context)
  328. {
  329. // Setup the Target
  330. context.AddAssetDependency(kSourceCodeGuid, AssetCollection.Flags.SourceDependency);
  331. // Override EditorGUI (replaces the URP material editor by a custom one)
  332. if (!string.IsNullOrEmpty(m_CustomEditorGUI))
  333. context.AddCustomEditorForRenderPipeline(m_CustomEditorGUI, typeof(UniversalRenderPipelineAsset));
  334. // Setup the active SubTarget
  335. TargetUtils.ProcessSubTargetList(ref m_ActiveSubTarget, ref m_SubTargets);
  336. m_ActiveSubTarget.value.target = this;
  337. ProcessSubTargetDatas(m_ActiveSubTarget.value);
  338. m_ActiveSubTarget.value.Setup(ref context);
  339. }
  340. public override void OnAfterMultiDeserialize(string json)
  341. {
  342. TargetUtils.ProcessSubTargetList(ref m_ActiveSubTarget, ref m_SubTargets);
  343. m_ActiveSubTarget.value.target = this;
  344. // OnAfterMultiDeserialize order is not guaranteed to be hierarchical (target->subtarget).
  345. // Update active subTarget (only, since the target is shared and non-active subTargets could override active settings)
  346. // after Target has been deserialized and target <-> subtarget references are intact.
  347. m_ActiveSubTarget.value.OnAfterParentTargetDeserialized();
  348. }
  349. public override void GetFields(ref TargetFieldContext context)
  350. {
  351. var descs = context.blocks.Select(x => x.descriptor);
  352. // Core fields
  353. context.AddField(Fields.GraphVertex, descs.Contains(BlockFields.VertexDescription.Position) ||
  354. descs.Contains(BlockFields.VertexDescription.Normal) ||
  355. descs.Contains(BlockFields.VertexDescription.Tangent));
  356. context.AddField(Fields.GraphPixel);
  357. // SubTarget fields
  358. m_ActiveSubTarget.value.GetFields(ref context);
  359. }
  360. public override void GetActiveBlocks(ref TargetActiveBlockContext context)
  361. {
  362. // Core blocks
  363. bool useCoreBlocks = !(m_ActiveSubTarget.value is UnityEditor.Rendering.Fullscreen.ShaderGraph.FullscreenSubTarget<UniversalTarget> | m_ActiveSubTarget.value is UnityEditor.Rendering.Canvas.ShaderGraph.CanvasSubTarget<UniversalTarget>);
  364. // Core blocks
  365. if (useCoreBlocks)
  366. {
  367. context.AddBlock(BlockFields.VertexDescription.Position);
  368. context.AddBlock(BlockFields.VertexDescription.Normal);
  369. context.AddBlock(BlockFields.VertexDescription.Tangent);
  370. context.AddBlock(BlockFields.SurfaceDescription.BaseColor);
  371. }
  372. // SubTarget blocks
  373. m_ActiveSubTarget.value.GetActiveBlocks(ref context);
  374. }
  375. public override void ProcessPreviewMaterial(Material material)
  376. {
  377. m_ActiveSubTarget.value.ProcessPreviewMaterial(material);
  378. }
  379. public override object saveContext => m_ActiveSubTarget.value?.saveContext;
  380. public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode)
  381. {
  382. base.CollectShaderProperties(collector, generationMode);
  383. activeSubTarget.CollectShaderProperties(collector, generationMode);
  384. collector.AddShaderProperty(LightmappingShaderProperties.kLightmapsArray);
  385. collector.AddShaderProperty(LightmappingShaderProperties.kLightmapsIndirectionArray);
  386. collector.AddShaderProperty(LightmappingShaderProperties.kShadowMasksArray);
  387. collector.AddShaderProperty(MipmapStreamingShaderProperties.kDebugTex);
  388. // SubTarget blocks
  389. m_ActiveSubTarget.value.CollectShaderProperties(collector, generationMode);
  390. }
  391. public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
  392. {
  393. // Core properties
  394. m_SubTargetField = new PopupField<string>(m_SubTargetNames, activeSubTargetIndex);
  395. context.AddProperty("Material", m_SubTargetField, (evt) =>
  396. {
  397. if (Equals(activeSubTargetIndex, m_SubTargetField.index))
  398. return;
  399. registerUndo("Change Material");
  400. m_ActiveSubTarget = m_SubTargets[m_SubTargetField.index];
  401. ProcessSubTargetDatas(m_ActiveSubTarget.value);
  402. onChange();
  403. });
  404. // SubTarget properties
  405. m_ActiveSubTarget.value.GetPropertiesGUI(ref context, onChange, registerUndo);
  406. // Custom Editor GUI
  407. // Requires FocusOutEvent
  408. m_CustomGUIField = new TextField("") { value = customEditorGUI };
  409. m_CustomGUIField.RegisterCallback<FocusOutEvent>(s =>
  410. {
  411. if (Equals(customEditorGUI, m_CustomGUIField.value))
  412. return;
  413. registerUndo("Change Custom Editor GUI");
  414. customEditorGUI = m_CustomGUIField.value;
  415. onChange();
  416. });
  417. context.AddProperty("Custom Editor GUI", m_CustomGUIField, (evt) => { });
  418. #if HAS_VFX_GRAPH
  419. if (m_ActiveSubTarget.value is UniversalSubTarget universalSubTarget && universalSubTarget.target.CanSupportVFX())
  420. {
  421. m_SupportVFXToggle = new Toggle("") { value = m_SupportVFX };
  422. context.AddProperty("Support VFX Graph", m_SupportVFXToggle, (evt) =>
  423. {
  424. m_SupportVFX = m_SupportVFXToggle.value;
  425. });
  426. }
  427. else
  428. {
  429. context.AddHelpBox(MessageType.Info, $"The {m_ActiveSubTarget.value.displayName} target does not support VFX Graph.");
  430. }
  431. #endif
  432. }
  433. // this is a copy of ZTestMode, but hides the "Disabled" option, which is invalid
  434. enum ZTestModeForUI
  435. {
  436. Never = 1,
  437. Less = 2,
  438. Equal = 3,
  439. LEqual = 4, // default for most rendering
  440. Greater = 5,
  441. NotEqual = 6,
  442. GEqual = 7,
  443. Always = 8,
  444. };
  445. public void AddDefaultMaterialOverrideGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
  446. {
  447. // At some point we may want to convert this to be a per-property control
  448. // or Unify the UX with the upcoming "lock" feature of the Material Variant properties
  449. context.AddProperty("Allow Material Override", new Toggle() { value = allowMaterialOverride }, (evt) =>
  450. {
  451. if (Equals(allowMaterialOverride, evt.newValue))
  452. return;
  453. registerUndo("Change Allow Material Override");
  454. allowMaterialOverride = evt.newValue;
  455. onChange();
  456. });
  457. }
  458. public void AddDefaultSurfacePropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo, bool showReceiveShadows)
  459. {
  460. context.AddProperty("Surface Type", new EnumField(SurfaceType.Opaque) { value = surfaceType }, (evt) =>
  461. {
  462. if (Equals(surfaceType, evt.newValue))
  463. return;
  464. registerUndo("Change Surface");
  465. surfaceType = (SurfaceType)evt.newValue;
  466. onChange();
  467. });
  468. context.AddProperty("Blending Mode", new EnumField(AlphaMode.Alpha) { value = alphaMode }, surfaceType == SurfaceType.Transparent, (evt) =>
  469. {
  470. if (Equals(alphaMode, evt.newValue))
  471. return;
  472. registerUndo("Change Blend");
  473. alphaMode = (AlphaMode)evt.newValue;
  474. onChange();
  475. });
  476. context.AddProperty("Render Face", new EnumField(RenderFace.Front) { value = renderFace }, (evt) =>
  477. {
  478. if (Equals(renderFace, evt.newValue))
  479. return;
  480. registerUndo("Change Render Face");
  481. renderFace = (RenderFace)evt.newValue;
  482. onChange();
  483. });
  484. context.AddProperty("Depth Write", new EnumField(ZWriteControl.Auto) { value = zWriteControl }, (evt) =>
  485. {
  486. if (Equals(zWriteControl, evt.newValue))
  487. return;
  488. registerUndo("Change Depth Write Control");
  489. zWriteControl = (ZWriteControl)evt.newValue;
  490. onChange();
  491. });
  492. context.AddProperty("Depth Test", new EnumField(ZTestModeForUI.LEqual) { value = (ZTestModeForUI)zTestMode }, (evt) =>
  493. {
  494. if (Equals(zTestMode, evt.newValue))
  495. return;
  496. registerUndo("Change Depth Test");
  497. zTestMode = (ZTestMode)evt.newValue;
  498. onChange();
  499. });
  500. context.AddProperty("Alpha Clipping", "Avoid using when Alpha and AlphaThreshold are constant for the entire material as enabling in this case could introduce visual artifacts and will add an unnecessary performance cost when used with MSAA (due to AlphaToMask)", 0, new Toggle() { value = alphaClip }, (evt) =>
  501. {
  502. if (Equals(alphaClip, evt.newValue))
  503. return;
  504. registerUndo("Change Alpha Clip");
  505. alphaClip = evt.newValue;
  506. onChange();
  507. });
  508. context.AddProperty("Cast Shadows", new Toggle() { value = castShadows }, (evt) =>
  509. {
  510. if (Equals(castShadows, evt.newValue))
  511. return;
  512. registerUndo("Change Cast Shadows");
  513. castShadows = evt.newValue;
  514. onChange();
  515. });
  516. if (showReceiveShadows)
  517. context.AddProperty("Receive Shadows", new Toggle() { value = receiveShadows }, (evt) =>
  518. {
  519. if (Equals(receiveShadows, evt.newValue))
  520. return;
  521. registerUndo("Change Receive Shadows");
  522. receiveShadows = evt.newValue;
  523. onChange();
  524. });
  525. context.AddProperty("Supports LOD Cross Fade", new Toggle() { value = supportsLodCrossFade }, (evt) =>
  526. {
  527. if (Equals(supportsLodCrossFade, evt.newValue))
  528. return;
  529. registerUndo("Change Supports LOD Cross Fade");
  530. supportsLodCrossFade = evt.newValue;
  531. onChange();
  532. });
  533. context.AddProperty("Additional Motion Vectors", "Specifies how motion vectors for local Shader Graph position modifications are handled (on top of camera, transform, skeletal and Alembic motion vectors).", 0, new EnumField(AdditionalMotionVectorMode.None) { value = additionalMotionVectorMode }, (evt) =>
  534. {
  535. if (Equals(additionalMotionVectorMode, evt.newValue))
  536. return;
  537. registerUndo("Change Additional Motion Vectors");
  538. additionalMotionVectorMode = (AdditionalMotionVectorMode)evt.newValue;
  539. onChange();
  540. });
  541. context.AddProperty(EditorUtils.Styles.alembicMotionVectors.text, EditorUtils.Styles.alembicMotionVectors.tooltip, 0, new Toggle() {value = alembicMotionVectors}, (evt) =>
  542. {
  543. if (Equals(alembicMotionVectors, evt.newValue))
  544. return;
  545. registerUndo("Change Alembic Motion Vectors");
  546. alembicMotionVectors = evt.newValue;
  547. onChange();
  548. });
  549. }
  550. public bool TrySetActiveSubTarget(Type subTargetType)
  551. {
  552. if (!subTargetType.IsSubclassOf(typeof(SubTarget)))
  553. return false;
  554. foreach (var subTarget in m_SubTargets)
  555. {
  556. if (subTarget.GetType().Equals(subTargetType))
  557. {
  558. m_ActiveSubTarget = subTarget;
  559. ProcessSubTargetDatas(m_ActiveSubTarget);
  560. return true;
  561. }
  562. }
  563. return false;
  564. }
  565. void ProcessSubTargetDatas(SubTarget subTarget)
  566. {
  567. var typeCollection = TypeCache.GetTypesDerivedFrom<JsonObject>();
  568. foreach (var type in typeCollection)
  569. {
  570. if (type.IsGenericType)
  571. continue;
  572. // Data requirement interfaces need generic type arguments
  573. // Therefore we need to use reflections to call the method
  574. var methodInfo = typeof(UniversalTarget).GetMethod(nameof(SetDataOnSubTarget));
  575. var genericMethodInfo = methodInfo.MakeGenericMethod(type);
  576. genericMethodInfo.Invoke(this, new object[] { subTarget });
  577. }
  578. }
  579. void ClearUnusedData()
  580. {
  581. for (int i = 0; i < m_Datas.Count; i++)
  582. {
  583. var data = m_Datas[i];
  584. if (data.value is null)
  585. continue;
  586. var type = data.value.GetType();
  587. // Data requirement interfaces need generic type arguments
  588. // Therefore we need to use reflections to call the method
  589. var methodInfo = typeof(UniversalTarget).GetMethod(nameof(ValidateDataForSubTarget));
  590. var genericMethodInfo = methodInfo.MakeGenericMethod(type);
  591. genericMethodInfo.Invoke(this, new object[] { m_ActiveSubTarget.value, data.value });
  592. }
  593. }
  594. public void SetDataOnSubTarget<T>(SubTarget subTarget) where T : JsonObject
  595. {
  596. if (!(subTarget is IRequiresData<T> requiresData))
  597. return;
  598. // Ensure data object exists in list
  599. T data = null;
  600. foreach (var x in m_Datas.SelectValue())
  601. {
  602. if (x.GetType().Equals(typeof(T)))
  603. {
  604. data = x as T;
  605. continue;
  606. }
  607. }
  608. if (data == null)
  609. {
  610. data = Activator.CreateInstance(typeof(T)) as T;
  611. m_Datas.Add(data);
  612. }
  613. // Apply data object to SubTarget
  614. requiresData.data = data;
  615. }
  616. public void ValidateDataForSubTarget<T>(SubTarget subTarget, T data) where T : JsonObject
  617. {
  618. if (!(subTarget is IRequiresData<T> requiresData))
  619. {
  620. m_Datas.Remove(data);
  621. }
  622. }
  623. public override void OnBeforeSerialize()
  624. {
  625. ClearUnusedData();
  626. }
  627. public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<BlockFieldDescriptor, int> blockMap)
  628. {
  629. void UpgradeAlphaClip()
  630. {
  631. var clipThresholdId = 8;
  632. var node = masterNode as AbstractMaterialNode;
  633. var clipThresholdSlot = node.FindSlot<Vector1MaterialSlot>(clipThresholdId);
  634. if (clipThresholdSlot == null)
  635. return;
  636. clipThresholdSlot.owner = node;
  637. if (clipThresholdSlot.isConnected || clipThresholdSlot.value > 0.0f)
  638. {
  639. m_AlphaClip = true;
  640. }
  641. }
  642. // Upgrade Target
  643. allowMaterialOverride = false;
  644. switch (masterNode)
  645. {
  646. case PBRMasterNode1 pbrMasterNode:
  647. m_SurfaceType = (SurfaceType)pbrMasterNode.m_SurfaceType;
  648. m_AlphaMode = (AlphaMode)pbrMasterNode.m_AlphaMode;
  649. m_RenderFace = pbrMasterNode.m_TwoSided ? RenderFace.Both : RenderFace.Front;
  650. UpgradeAlphaClip();
  651. m_CustomEditorGUI = pbrMasterNode.m_OverrideEnabled ? pbrMasterNode.m_ShaderGUIOverride : "";
  652. break;
  653. case UnlitMasterNode1 unlitMasterNode:
  654. m_SurfaceType = (SurfaceType)unlitMasterNode.m_SurfaceType;
  655. m_AlphaMode = (AlphaMode)unlitMasterNode.m_AlphaMode;
  656. m_RenderFace = unlitMasterNode.m_TwoSided ? RenderFace.Both : RenderFace.Front;
  657. UpgradeAlphaClip();
  658. m_CustomEditorGUI = unlitMasterNode.m_OverrideEnabled ? unlitMasterNode.m_ShaderGUIOverride : "";
  659. break;
  660. case SpriteLitMasterNode1 spriteLitMasterNode:
  661. m_CustomEditorGUI = spriteLitMasterNode.m_OverrideEnabled ? spriteLitMasterNode.m_ShaderGUIOverride : "";
  662. break;
  663. case SpriteUnlitMasterNode1 spriteUnlitMasterNode:
  664. m_CustomEditorGUI = spriteUnlitMasterNode.m_OverrideEnabled ? spriteUnlitMasterNode.m_ShaderGUIOverride : "";
  665. break;
  666. }
  667. // Upgrade SubTarget
  668. foreach (var subTarget in m_SubTargets)
  669. {
  670. if (!(subTarget is ILegacyTarget legacySubTarget))
  671. continue;
  672. if (legacySubTarget.TryUpgradeFromMasterNode(masterNode, out blockMap))
  673. {
  674. m_ActiveSubTarget = subTarget;
  675. return true;
  676. }
  677. }
  678. blockMap = null;
  679. return false;
  680. }
  681. public override bool WorksWithSRP(RenderPipelineAsset scriptableRenderPipeline)
  682. {
  683. return scriptableRenderPipeline?.GetType() == typeof(UniversalRenderPipelineAsset);
  684. }
  685. #if HAS_VFX_GRAPH
  686. public void ConfigureContextData(VFXContext context, VFXTaskCompiledData data)
  687. {
  688. if (!(m_ActiveSubTarget.value is IRequireVFXContext vfxSubtarget))
  689. return;
  690. vfxSubtarget.ConfigureContextData(context, data);
  691. }
  692. #endif
  693. public bool CanSupportVFX()
  694. {
  695. if (m_ActiveSubTarget.value == null)
  696. return false;
  697. if (m_ActiveSubTarget.value is UniversalUnlitSubTarget)
  698. return true;
  699. if (m_ActiveSubTarget.value is UniversalSixWaySubTarget)
  700. return true;
  701. if (m_ActiveSubTarget.value is UniversalLitSubTarget)
  702. return true;
  703. if (m_ActiveSubTarget.value is UniversalSpriteLitSubTarget)
  704. return true;
  705. if (m_ActiveSubTarget.value is UniversalSpriteUnlitSubTarget)
  706. return true;
  707. if (m_ActiveSubTarget.value is UniversalSpriteCustomLitSubTarget)
  708. return true;
  709. //It excludes:
  710. // - UniversalDecalSubTarget
  711. return false;
  712. }
  713. public bool SupportsVFX() => CanSupportVFX() && m_SupportVFX;
  714. [Serializable]
  715. class UniversalTargetLegacySerialization
  716. {
  717. [SerializeField]
  718. public bool m_TwoSided = false;
  719. }
  720. public override void OnAfterDeserialize(string json)
  721. {
  722. base.OnAfterDeserialize(json);
  723. if (this.sgVersion < latestVersion)
  724. {
  725. if (this.sgVersion == 0)
  726. {
  727. // deserialize the old settings to upgrade
  728. var oldSettings = JsonUtility.FromJson<UniversalTargetLegacySerialization>(json);
  729. this.m_RenderFace = oldSettings.m_TwoSided ? RenderFace.Both : RenderFace.Front;
  730. }
  731. ChangeVersion(latestVersion);
  732. }
  733. }
  734. #region Metadata
  735. string IHasMetadata.identifier
  736. {
  737. get
  738. {
  739. // defer to subtarget
  740. if (m_ActiveSubTarget.value is IHasMetadata subTargetHasMetaData)
  741. return subTargetHasMetaData.identifier;
  742. return null;
  743. }
  744. }
  745. ScriptableObject IHasMetadata.GetMetadataObject(GraphDataReadOnly graph)
  746. {
  747. // defer to subtarget
  748. if (m_ActiveSubTarget.value is IHasMetadata subTargetHasMetaData)
  749. return subTargetHasMetaData.GetMetadataObject(graph);
  750. return null;
  751. }
  752. #endregion
  753. }
  754. #region Passes
  755. static class CorePasses
  756. {
  757. /// <summary>
  758. /// Automatically enables Alpha-To-Coverage in the provided opaque pass targets using alpha clipping
  759. /// </summary>
  760. /// <param name="pass">The pass to modify</param>
  761. /// <param name="target">The target to query</param>
  762. internal static void AddAlphaToMaskControlToPass(ref PassDescriptor pass, UniversalTarget target)
  763. {
  764. if (target.allowMaterialOverride)
  765. {
  766. // When material overrides are allowed, we have to rely on the _AlphaToMask material property since we can't be
  767. // sure of the surface type and alpha clip state based on the target alone.
  768. pass.renderStates.Add(RenderState.AlphaToMask("[_AlphaToMask]"));
  769. }
  770. else if (target.alphaClip && (target.surfaceType == SurfaceType.Opaque))
  771. {
  772. pass.renderStates.Add(RenderState.AlphaToMask("On"));
  773. }
  774. }
  775. internal static void AddAlphaClipControlToPass(ref PassDescriptor pass, UniversalTarget target)
  776. {
  777. if (target.allowMaterialOverride)
  778. pass.keywords.Add(CoreKeywordDescriptors.AlphaTestOn);
  779. else if (target.alphaClip)
  780. pass.defines.Add(CoreKeywordDescriptors.AlphaTestOn, 1);
  781. }
  782. internal static void AddLODCrossFadeControlToPass(ref PassDescriptor pass, UniversalTarget target)
  783. {
  784. if (target.supportsLodCrossFade)
  785. {
  786. pass.includes.Add(CoreIncludes.LODCrossFade);
  787. pass.keywords.Add(CoreKeywordDescriptors.LODFadeCrossFade);
  788. pass.defines.Add(CoreKeywordDescriptors.UseUnityCrossFade, 1);
  789. }
  790. }
  791. internal static void AddTargetSurfaceControlsToPass(ref PassDescriptor pass, UniversalTarget target, bool blendModePreserveSpecular = false)
  792. {
  793. // the surface settings can either be material controlled or target controlled
  794. if (target.allowMaterialOverride)
  795. {
  796. // setup material control of via keyword
  797. pass.keywords.Add(CoreKeywordDescriptors.SurfaceTypeTransparent);
  798. pass.keywords.Add(CoreKeywordDescriptors.AlphaPremultiplyOn);
  799. pass.keywords.Add(CoreKeywordDescriptors.AlphaModulateOn);
  800. }
  801. else
  802. {
  803. // setup target control via define
  804. if (target.surfaceType == SurfaceType.Transparent)
  805. {
  806. pass.defines.Add(CoreKeywordDescriptors.SurfaceTypeTransparent, 1);
  807. // alpha premultiply in shader only needed when alpha is different for diffuse & specular
  808. if ((target.alphaMode == AlphaMode.Alpha || target.alphaMode == AlphaMode.Additive) && blendModePreserveSpecular)
  809. pass.defines.Add(CoreKeywordDescriptors.AlphaPremultiplyOn, 1);
  810. else if (target.alphaMode == AlphaMode.Multiply)
  811. pass.defines.Add(CoreKeywordDescriptors.AlphaModulateOn, 1);
  812. }
  813. }
  814. AddAlphaClipControlToPass(ref pass, target);
  815. }
  816. // used by lit/unlit subtargets
  817. public static PassDescriptor DepthOnly(UniversalTarget target)
  818. {
  819. var result = new PassDescriptor()
  820. {
  821. // Definition
  822. displayName = "DepthOnly",
  823. referenceName = "SHADERPASS_DEPTHONLY",
  824. lightMode = "DepthOnly",
  825. useInPreview = true,
  826. // Template
  827. passTemplatePath = UniversalTarget.kUberTemplatePath,
  828. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  829. // Port Mask
  830. validVertexBlocks = CoreBlockMasks.Vertex,
  831. validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly,
  832. // Fields
  833. structs = CoreStructCollections.Default,
  834. fieldDependencies = CoreFieldDependencies.Default,
  835. // Conditional State
  836. renderStates = CoreRenderStates.DepthOnly(target),
  837. pragmas = CorePragmas.Instanced,
  838. defines = new DefineCollection(),
  839. keywords = new KeywordCollection(),
  840. includes = new IncludeCollection { CoreIncludes.DepthOnly },
  841. // Custom Interpolator Support
  842. customInterpolators = CoreCustomInterpDescriptors.Common
  843. };
  844. AddAlphaClipControlToPass(ref result, target);
  845. AddLODCrossFadeControlToPass(ref result, target);
  846. return result;
  847. }
  848. // used by lit/unlit subtargets
  849. public static PassDescriptor DepthNormal(UniversalTarget target)
  850. {
  851. var result = new PassDescriptor()
  852. {
  853. // Definition
  854. displayName = "DepthNormals",
  855. referenceName = "SHADERPASS_DEPTHNORMALS",
  856. lightMode = "DepthNormals",
  857. useInPreview = true,
  858. // Template
  859. passTemplatePath = UniversalTarget.kUberTemplatePath,
  860. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  861. // Port Mask
  862. validVertexBlocks = CoreBlockMasks.Vertex,
  863. validPixelBlocks = CoreBlockMasks.FragmentDepthNormals,
  864. // Fields
  865. structs = CoreStructCollections.Default,
  866. requiredFields = CoreRequiredFields.DepthNormals,
  867. fieldDependencies = CoreFieldDependencies.Default,
  868. // Conditional State
  869. renderStates = CoreRenderStates.DepthNormalsOnly(target),
  870. pragmas = CorePragmas.Instanced,
  871. defines = new DefineCollection(),
  872. keywords = new KeywordCollection(),
  873. includes = new IncludeCollection { CoreIncludes.DepthNormalsOnly },
  874. // Custom Interpolator Support
  875. customInterpolators = CoreCustomInterpDescriptors.Common
  876. };
  877. AddAlphaClipControlToPass(ref result, target);
  878. AddLODCrossFadeControlToPass(ref result, target);
  879. return result;
  880. }
  881. // used by lit/unlit subtargets
  882. public static PassDescriptor DepthNormalOnly(UniversalTarget target)
  883. {
  884. var result = new PassDescriptor()
  885. {
  886. // Definition
  887. displayName = "DepthNormalsOnly",
  888. referenceName = "SHADERPASS_DEPTHNORMALSONLY",
  889. lightMode = "DepthNormalsOnly",
  890. useInPreview = true,
  891. // Template
  892. passTemplatePath = UniversalTarget.kUberTemplatePath,
  893. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  894. // Port Mask
  895. validVertexBlocks = CoreBlockMasks.Vertex,
  896. validPixelBlocks = CoreBlockMasks.FragmentDepthNormals,
  897. // Fields
  898. structs = CoreStructCollections.Default,
  899. requiredFields = CoreRequiredFields.DepthNormals,
  900. fieldDependencies = CoreFieldDependencies.Default,
  901. // Conditional State
  902. renderStates = CoreRenderStates.DepthNormalsOnly(target),
  903. pragmas = CorePragmas.Instanced,
  904. defines = new DefineCollection(),
  905. keywords = new KeywordCollection { CoreKeywordDescriptors.GBufferNormalsOct },
  906. includes = new IncludeCollection { CoreIncludes.DepthNormalsOnly },
  907. // Custom Interpolator Support
  908. customInterpolators = CoreCustomInterpDescriptors.Common
  909. };
  910. AddAlphaClipControlToPass(ref result, target);
  911. AddLODCrossFadeControlToPass(ref result, target);
  912. return result;
  913. }
  914. // used by lit/unlit targets
  915. public static PassDescriptor ShadowCaster(UniversalTarget target)
  916. {
  917. var result = new PassDescriptor()
  918. {
  919. // Definition
  920. displayName = "ShadowCaster",
  921. referenceName = "SHADERPASS_SHADOWCASTER",
  922. lightMode = "ShadowCaster",
  923. // Template
  924. passTemplatePath = UniversalTarget.kUberTemplatePath,
  925. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  926. // Port Mask
  927. validVertexBlocks = CoreBlockMasks.Vertex,
  928. validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly,
  929. // Fields
  930. structs = CoreStructCollections.Default,
  931. requiredFields = CoreRequiredFields.ShadowCaster,
  932. fieldDependencies = CoreFieldDependencies.Default,
  933. // Conditional State
  934. renderStates = CoreRenderStates.ShadowCaster(target),
  935. pragmas = CorePragmas.Instanced,
  936. defines = new DefineCollection(),
  937. keywords = new KeywordCollection { CoreKeywords.ShadowCaster },
  938. includes = new IncludeCollection { CoreIncludes.ShadowCaster },
  939. // Custom Interpolator Support
  940. customInterpolators = CoreCustomInterpDescriptors.Common
  941. };
  942. AddAlphaClipControlToPass(ref result, target);
  943. AddLODCrossFadeControlToPass(ref result, target);
  944. return result;
  945. }
  946. public static PassDescriptor MotionVectors(UniversalTarget target)
  947. {
  948. var result = new PassDescriptor()
  949. {
  950. // Definition
  951. displayName = "MotionVectors",
  952. referenceName = "SHADERPASS_MOTION_VECTORS",
  953. lightMode = "MotionVectors",
  954. useInPreview = false,
  955. // Template
  956. passTemplatePath = UniversalTarget.kUberTemplatePath,
  957. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  958. // Port Mask
  959. validVertexBlocks = target.additionalMotionVectorMode == AdditionalMotionVectorMode.Custom ? CoreBlockMasks.CustomMotionVectorVertex : CoreBlockMasks.MotionVectorVertex,
  960. validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly,
  961. // Fields
  962. structs = CoreStructCollections.Default,
  963. requiredFields = new FieldCollection(),
  964. fieldDependencies = CoreFieldDependencies.Default,
  965. // Conditional State
  966. renderStates = CoreRenderStates.MotionVector(target),
  967. pragmas = CorePragmas.MotionVectors,
  968. defines = new DefineCollection(),
  969. keywords = new KeywordCollection(),
  970. includes = CoreIncludes.MotionVectors,
  971. // Custom Interpolator Support
  972. customInterpolators = CoreCustomInterpDescriptors.Common
  973. };
  974. if (target.additionalMotionVectorMode == AdditionalMotionVectorMode.TimeBased)
  975. result.defines.Add(CoreKeywordDescriptors.AutomaticTimeBasedMotionVectors, 1);
  976. if (target.alembicMotionVectors)
  977. result.defines.Add(CoreKeywordDescriptors.AddPrecomputedVelocity, 1);
  978. AddAlphaClipControlToPass(ref result, target);
  979. AddLODCrossFadeControlToPass(ref result, target);
  980. return result;
  981. }
  982. public static PassDescriptor SceneSelection(UniversalTarget target)
  983. {
  984. var result = new PassDescriptor()
  985. {
  986. // Definition
  987. displayName = "SceneSelectionPass",
  988. referenceName = "SHADERPASS_DEPTHONLY",
  989. lightMode = "SceneSelectionPass",
  990. useInPreview = false,
  991. // Template
  992. passTemplatePath = UniversalTarget.kUberTemplatePath,
  993. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  994. // Port Mask
  995. validVertexBlocks = CoreBlockMasks.Vertex,
  996. validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly,
  997. // Fields
  998. structs = CoreStructCollections.Default,
  999. fieldDependencies = CoreFieldDependencies.Default,
  1000. // Conditional State
  1001. renderStates = CoreRenderStates.SceneSelection(target),
  1002. pragmas = CorePragmas.Instanced,
  1003. defines = new DefineCollection { CoreDefines.SceneSelection, { CoreKeywordDescriptors.AlphaClipThreshold, 1 } },
  1004. keywords = new KeywordCollection(),
  1005. includes = CoreIncludes.SceneSelection,
  1006. // Custom Interpolator Support
  1007. customInterpolators = CoreCustomInterpDescriptors.Common
  1008. };
  1009. AddAlphaClipControlToPass(ref result, target);
  1010. return result;
  1011. }
  1012. public static PassDescriptor ScenePicking(UniversalTarget target)
  1013. {
  1014. var result = new PassDescriptor()
  1015. {
  1016. // Definition
  1017. displayName = "ScenePickingPass",
  1018. referenceName = "SHADERPASS_DEPTHONLY",
  1019. lightMode = "Picking",
  1020. useInPreview = false,
  1021. // Template
  1022. passTemplatePath = UniversalTarget.kUberTemplatePath,
  1023. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  1024. // Port Mask
  1025. validVertexBlocks = CoreBlockMasks.Vertex,
  1026. // NB Color is not strickly needed for scene picking but adding it here so that there are nodes to be
  1027. // collected for the pixel shader. Some packages might use this to customize the scene picking rendering.
  1028. validPixelBlocks = CoreBlockMasks.FragmentColorAlpha,
  1029. // Fields
  1030. structs = CoreStructCollections.Default,
  1031. fieldDependencies = CoreFieldDependencies.Default,
  1032. // Conditional State
  1033. renderStates = CoreRenderStates.ScenePicking(target),
  1034. pragmas = CorePragmas.Instanced,
  1035. defines = new DefineCollection { CoreDefines.ScenePicking, { CoreKeywordDescriptors.AlphaClipThreshold, 1 } },
  1036. keywords = new KeywordCollection(),
  1037. includes = CoreIncludes.ScenePicking,
  1038. // Custom Interpolator Support
  1039. customInterpolators = CoreCustomInterpDescriptors.Common
  1040. };
  1041. AddAlphaClipControlToPass(ref result, target);
  1042. return result;
  1043. }
  1044. public static PassDescriptor _2DSceneSelection(UniversalTarget target)
  1045. {
  1046. var result = new PassDescriptor()
  1047. {
  1048. // Definition
  1049. displayName = "SceneSelectionPass",
  1050. referenceName = "SHADERPASS_DEPTHONLY",
  1051. lightMode = "SceneSelectionPass",
  1052. useInPreview = false,
  1053. // Template
  1054. passTemplatePath = UniversalTarget.kUberTemplatePath,
  1055. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  1056. // Port Mask
  1057. validVertexBlocks = CoreBlockMasks.Vertex,
  1058. validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly,
  1059. // Fields
  1060. structs = CoreStructCollections.Default,
  1061. fieldDependencies = CoreFieldDependencies.Default,
  1062. // Conditional State
  1063. renderStates = CoreRenderStates.SceneSelection(target),
  1064. pragmas = CorePragmas._2DDefault,
  1065. defines = new DefineCollection { CoreDefines.SceneSelection, { CoreKeywordDescriptors.AlphaClipThreshold, 0 } },
  1066. keywords = new KeywordCollection(),
  1067. includes = CoreIncludes.ScenePicking,
  1068. // Custom Interpolator Support
  1069. customInterpolators = CoreCustomInterpDescriptors.Common
  1070. };
  1071. AddAlphaClipControlToPass(ref result, target);
  1072. return result;
  1073. }
  1074. public static PassDescriptor _2DScenePicking(UniversalTarget target)
  1075. {
  1076. var result = new PassDescriptor()
  1077. {
  1078. // Definition
  1079. displayName = "ScenePickingPass",
  1080. referenceName = "SHADERPASS_DEPTHONLY",
  1081. lightMode = "Picking",
  1082. useInPreview = false,
  1083. // Template
  1084. passTemplatePath = UniversalTarget.kUberTemplatePath,
  1085. sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories,
  1086. // Port Mask
  1087. validVertexBlocks = CoreBlockMasks.Vertex,
  1088. validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly,
  1089. // Fields
  1090. structs = CoreStructCollections.Default,
  1091. fieldDependencies = CoreFieldDependencies.Default,
  1092. // Conditional State
  1093. renderStates = CoreRenderStates.ScenePicking(target),
  1094. pragmas = CorePragmas._2DDefault,
  1095. defines = new DefineCollection { CoreDefines.ScenePicking, { CoreKeywordDescriptors.AlphaClipThreshold, 0 } },
  1096. keywords = new KeywordCollection(),
  1097. includes = CoreIncludes.SceneSelection,
  1098. // Custom Interpolator Support
  1099. customInterpolators = CoreCustomInterpDescriptors.Common
  1100. };
  1101. AddAlphaClipControlToPass(ref result, target);
  1102. return result;
  1103. }
  1104. }
  1105. #endregion
  1106. #region PortMasks
  1107. class CoreBlockMasks
  1108. {
  1109. public static readonly BlockFieldDescriptor[] MotionVectorVertex = new BlockFieldDescriptor[]
  1110. {
  1111. BlockFields.VertexDescription.Position,
  1112. };
  1113. public static readonly BlockFieldDescriptor[] CustomMotionVectorVertex = new BlockFieldDescriptor[]
  1114. {
  1115. BlockFields.VertexDescription.Position,
  1116. UniversalBlockFields.VertexDescription.MotionVector,
  1117. };
  1118. public static readonly BlockFieldDescriptor[] Vertex = new BlockFieldDescriptor[]
  1119. {
  1120. BlockFields.VertexDescription.Position,
  1121. BlockFields.VertexDescription.Normal,
  1122. BlockFields.VertexDescription.Tangent,
  1123. };
  1124. public static readonly BlockFieldDescriptor[] FragmentAlphaOnly = new BlockFieldDescriptor[]
  1125. {
  1126. BlockFields.SurfaceDescription.Alpha,
  1127. BlockFields.SurfaceDescription.AlphaClipThreshold,
  1128. };
  1129. public static readonly BlockFieldDescriptor[] FragmentColorAlpha = new BlockFieldDescriptor[]
  1130. {
  1131. BlockFields.SurfaceDescription.BaseColor,
  1132. BlockFields.SurfaceDescription.Alpha,
  1133. BlockFields.SurfaceDescription.AlphaClipThreshold,
  1134. };
  1135. public static readonly BlockFieldDescriptor[] FragmentDepthNormals = new BlockFieldDescriptor[]
  1136. {
  1137. BlockFields.SurfaceDescription.NormalOS,
  1138. BlockFields.SurfaceDescription.NormalTS,
  1139. BlockFields.SurfaceDescription.NormalWS,
  1140. BlockFields.SurfaceDescription.Alpha,
  1141. BlockFields.SurfaceDescription.AlphaClipThreshold,
  1142. };
  1143. }
  1144. #endregion
  1145. #region StructCollections
  1146. static class CoreStructCollections
  1147. {
  1148. public static readonly StructCollection Default = new StructCollection
  1149. {
  1150. { Structs.Attributes },
  1151. { UniversalStructs.Varyings },
  1152. { Structs.SurfaceDescriptionInputs },
  1153. { Structs.VertexDescriptionInputs },
  1154. };
  1155. }
  1156. #endregion
  1157. #region RequiredFields
  1158. static class CoreRequiredFields
  1159. {
  1160. public static readonly FieldCollection ShadowCaster = new FieldCollection()
  1161. {
  1162. StructFields.Varyings.normalWS,
  1163. };
  1164. public static readonly FieldCollection DepthNormals = new FieldCollection()
  1165. {
  1166. StructFields.Attributes.uv1, // needed for meta vertex position
  1167. StructFields.Varyings.normalWS,
  1168. StructFields.Varyings.tangentWS, // needed for vertex lighting
  1169. };
  1170. }
  1171. #endregion
  1172. #region FieldDependencies
  1173. static class CoreFieldDependencies
  1174. {
  1175. public static readonly DependencyCollection Default = new DependencyCollection()
  1176. {
  1177. { FieldDependencies.Default },
  1178. new FieldDependency(UniversalStructFields.Varyings.stereoTargetEyeIndexAsRTArrayIdx, StructFields.Attributes.instanceID),
  1179. new FieldDependency(UniversalStructFields.Varyings.stereoTargetEyeIndexAsBlendIdx0, StructFields.Attributes.instanceID),
  1180. };
  1181. }
  1182. #endregion
  1183. #region RenderStates
  1184. static class CoreRenderStates
  1185. {
  1186. public static class Uniforms
  1187. {
  1188. public static readonly string srcBlend = "[" + Property.SrcBlend + "]";
  1189. public static readonly string dstBlend = "[" + Property.DstBlend + "]";
  1190. public static readonly string cullMode = "[" + Property.CullMode + "]";
  1191. public static readonly string zWrite = "[" + Property.ZWrite + "]";
  1192. public static readonly string zTest = "[" + Property.ZTest + "]";
  1193. }
  1194. // used by sprite targets, NOT used by lit/unlit anymore
  1195. public static readonly RenderStateCollection Default = new RenderStateCollection
  1196. {
  1197. { RenderState.ZTest(ZTest.LEqual) },
  1198. { RenderState.ZWrite(ZWrite.On), new FieldCondition(UniversalFields.SurfaceOpaque, true) },
  1199. { RenderState.ZWrite(ZWrite.Off), new FieldCondition(UniversalFields.SurfaceTransparent, true) },
  1200. { RenderState.Cull(Cull.Back), new FieldCondition(Fields.DoubleSided, false) },
  1201. { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) },
  1202. { RenderState.Blend(Blend.One, Blend.Zero), new FieldCondition(UniversalFields.SurfaceOpaque, true) },
  1203. { RenderState.Blend(Blend.SrcAlpha, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition(Fields.BlendAlpha, true) },
  1204. { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition(UniversalFields.BlendPremultiply, true) },
  1205. { RenderState.Blend(Blend.SrcAlpha, Blend.One, Blend.One, Blend.One), new FieldCondition(UniversalFields.BlendAdd, true) },
  1206. { RenderState.Blend(Blend.DstColor, Blend.Zero), new FieldCondition(UniversalFields.BlendMultiply, true) },
  1207. };
  1208. public static Cull RenderFaceToCull(RenderFace renderFace)
  1209. {
  1210. switch (renderFace)
  1211. {
  1212. case RenderFace.Back:
  1213. return Cull.Front;
  1214. case RenderFace.Front:
  1215. return Cull.Back;
  1216. case RenderFace.Both:
  1217. return Cull.Off;
  1218. }
  1219. return Cull.Back;
  1220. }
  1221. // used by lit/unlit subtargets
  1222. public static RenderStateCollection UberSwitchedRenderState(UniversalTarget target, bool blendModePreserveSpecular = false)
  1223. {
  1224. if (target.allowMaterialOverride)
  1225. {
  1226. return new RenderStateCollection
  1227. {
  1228. RenderState.ZTest(Uniforms.zTest),
  1229. RenderState.ZWrite(Uniforms.zWrite),
  1230. RenderState.Cull(Uniforms.cullMode),
  1231. RenderState.Blend(Uniforms.srcBlend, Uniforms.dstBlend),
  1232. };
  1233. }
  1234. else
  1235. {
  1236. var result = new RenderStateCollection();
  1237. result.Add(RenderState.ZTest(target.zTestMode.ToString()));
  1238. if (target.zWriteControl == ZWriteControl.Auto)
  1239. {
  1240. if (target.surfaceType == SurfaceType.Opaque)
  1241. result.Add(RenderState.ZWrite(ZWrite.On));
  1242. else
  1243. result.Add(RenderState.ZWrite(ZWrite.Off));
  1244. }
  1245. else if (target.zWriteControl == ZWriteControl.ForceEnabled)
  1246. result.Add(RenderState.ZWrite(ZWrite.On));
  1247. else
  1248. result.Add(RenderState.ZWrite(ZWrite.Off));
  1249. result.Add(RenderState.Cull(RenderFaceToCull(target.renderFace)));
  1250. if (target.surfaceType == SurfaceType.Opaque)
  1251. {
  1252. result.Add(RenderState.Blend(Blend.One, Blend.Zero));
  1253. }
  1254. else
  1255. {
  1256. // Lift alpha multiply from ROP to shader in preserve spec for different diffuse and specular blends.
  1257. Blend blendSrcRGB = blendModePreserveSpecular ? Blend.One : Blend.SrcAlpha;
  1258. switch (target.alphaMode)
  1259. {
  1260. case AlphaMode.Alpha:
  1261. result.Add(RenderState.Blend(blendSrcRGB, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha));
  1262. break;
  1263. case AlphaMode.Premultiply:
  1264. result.Add(RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha));
  1265. break;
  1266. case AlphaMode.Additive:
  1267. result.Add(RenderState.Blend(blendSrcRGB, Blend.One, Blend.One, Blend.One));
  1268. break;
  1269. case AlphaMode.Multiply:
  1270. result.Add(RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.Zero, Blend.One)); // Multiply RGB only, keep A
  1271. break;
  1272. }
  1273. }
  1274. return result;
  1275. }
  1276. }
  1277. // used by lit target ONLY
  1278. public static readonly RenderStateCollection Meta = new RenderStateCollection
  1279. {
  1280. { RenderState.Cull(Cull.Off) },
  1281. };
  1282. public static RenderStateDescriptor UberSwitchedCullRenderState(UniversalTarget target)
  1283. {
  1284. if (target.allowMaterialOverride)
  1285. return RenderState.Cull(Uniforms.cullMode);
  1286. else
  1287. return RenderState.Cull(RenderFaceToCull(target.renderFace));
  1288. }
  1289. public static RenderStateCollection MotionVector(UniversalTarget target)
  1290. {
  1291. var result = new RenderStateCollection
  1292. {
  1293. { RenderState.ZTest(ZTest.LEqual) },
  1294. { RenderState.ZWrite(ZWrite.On) },
  1295. { UberSwitchedCullRenderState(target) },
  1296. { RenderState.ColorMask("ColorMask RG") },
  1297. };
  1298. return result;
  1299. }
  1300. // used by lit/unlit targets
  1301. public static RenderStateCollection ShadowCaster(UniversalTarget target)
  1302. {
  1303. var result = new RenderStateCollection
  1304. {
  1305. { RenderState.ZTest(ZTest.LEqual) },
  1306. { RenderState.ZWrite(ZWrite.On) },
  1307. { UberSwitchedCullRenderState(target) },
  1308. { RenderState.ColorMask("ColorMask 0") },
  1309. };
  1310. return result;
  1311. }
  1312. // used by lit/unlit targets
  1313. public static RenderStateCollection DepthOnly(UniversalTarget target)
  1314. {
  1315. var result = new RenderStateCollection
  1316. {
  1317. { RenderState.ZTest(ZTest.LEqual) },
  1318. { RenderState.ZWrite(ZWrite.On) },
  1319. { UberSwitchedCullRenderState(target) },
  1320. { RenderState.ColorMask("ColorMask R") },
  1321. };
  1322. return result;
  1323. }
  1324. // used by lit target ONLY
  1325. public static RenderStateCollection DepthNormalsOnly(UniversalTarget target)
  1326. {
  1327. var result = new RenderStateCollection
  1328. {
  1329. { RenderState.ZTest(ZTest.LEqual) },
  1330. { RenderState.ZWrite(ZWrite.On) },
  1331. { UberSwitchedCullRenderState(target) }
  1332. };
  1333. return result;
  1334. }
  1335. // Used by all targets
  1336. public static RenderStateCollection SceneSelection(UniversalTarget target)
  1337. {
  1338. var result = new RenderStateCollection
  1339. {
  1340. { RenderState.Cull(Cull.Off) },
  1341. };
  1342. return result;
  1343. }
  1344. public static RenderStateCollection ScenePicking(UniversalTarget target)
  1345. {
  1346. var result = new RenderStateCollection
  1347. {
  1348. { UberSwitchedCullRenderState(target) }
  1349. };
  1350. return result;
  1351. }
  1352. }
  1353. #endregion
  1354. #region Pragmas
  1355. static class CorePragmas
  1356. {
  1357. public static readonly PragmaCollection Default = new PragmaCollection
  1358. {
  1359. { Pragma.Target(ShaderModel.Target20) },
  1360. { Pragma.Vertex("vert") },
  1361. { Pragma.Fragment("frag") },
  1362. };
  1363. public static readonly PragmaCollection Instanced = new PragmaCollection
  1364. {
  1365. { Pragma.Target(ShaderModel.Target20) },
  1366. { Pragma.MultiCompileInstancing },
  1367. { Pragma.Vertex("vert") },
  1368. { Pragma.Fragment("frag") },
  1369. };
  1370. public static readonly PragmaCollection MotionVectors = new PragmaCollection
  1371. {
  1372. { Pragma.Target(ShaderModel.Target35) },
  1373. { Pragma.MultiCompileInstancing },
  1374. { Pragma.Vertex("vert") },
  1375. { Pragma.Fragment("frag") },
  1376. };
  1377. public static readonly PragmaCollection Forward = new PragmaCollection
  1378. {
  1379. { Pragma.Target(ShaderModel.Target20) },
  1380. { Pragma.MultiCompileInstancing },
  1381. { Pragma.MultiCompileFog },
  1382. { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) },
  1383. { Pragma.Vertex("vert") },
  1384. { Pragma.Fragment("frag") },
  1385. };
  1386. public static readonly PragmaCollection _2DDefault = new PragmaCollection
  1387. {
  1388. { Pragma.Target(ShaderModel.Target20) },
  1389. { Pragma.ExcludeRenderers(new[] { Platform.D3D9 }) },
  1390. { Pragma.Vertex("vert") },
  1391. { Pragma.Fragment("frag") },
  1392. };
  1393. public static readonly PragmaCollection GBuffer = new PragmaCollection
  1394. {
  1395. { Pragma.Target(ShaderModel.Target45) },
  1396. { Pragma.ExcludeRenderers(new[] { Platform.GLES3, Platform.GLCore }) },
  1397. { Pragma.MultiCompileInstancing },
  1398. { Pragma.MultiCompileFog },
  1399. { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) },
  1400. { Pragma.Vertex("vert") },
  1401. { Pragma.Fragment("frag") },
  1402. };
  1403. }
  1404. #endregion
  1405. #region Includes
  1406. static class CoreIncludes
  1407. {
  1408. const string kColor = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl";
  1409. const string kTexture = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl";
  1410. const string kCore = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl";
  1411. const string kInput = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl";
  1412. const string kLighting = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl";
  1413. const string kGraphFunctions = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl";
  1414. const string kVaryings = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/Varyings.hlsl";
  1415. const string kShaderPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl";
  1416. const string kDepthOnlyPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthOnlyPass.hlsl";
  1417. const string kDepthNormalsOnlyPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthNormalsOnlyPass.hlsl";
  1418. const string kShadowCasterPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl";
  1419. const string kMotionVectorPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/MotionVectorPass.hlsl";
  1420. const string kTextureStack = "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl";
  1421. const string kDBuffer = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl";
  1422. const string kSelectionPickingPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SelectionPickingPass.hlsl";
  1423. const string kLODCrossFade = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl";
  1424. const string kFoveatedRenderingKeywords = "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl";
  1425. const string kFoveatedRendering = "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl";
  1426. const string kMipmapDebugMacros = "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl";
  1427. // Files that are included with #include_with_pragmas
  1428. const string kDOTS = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl";
  1429. const string kRenderingLayers = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl";
  1430. const string kProbeVolumes = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ProbeVolumeVariants.hlsl";
  1431. public static readonly IncludeCollection CorePregraph = new IncludeCollection
  1432. {
  1433. { kColor, IncludeLocation.Pregraph },
  1434. { kTexture, IncludeLocation.Pregraph },
  1435. { kCore, IncludeLocation.Pregraph },
  1436. { kLighting, IncludeLocation.Pregraph },
  1437. { kInput, IncludeLocation.Pregraph },
  1438. { kTextureStack, IncludeLocation.Pregraph }, // TODO: put this on a conditional
  1439. { kFoveatedRenderingKeywords, IncludeLocation.Pregraph, true },
  1440. { kFoveatedRendering, IncludeLocation.Pregraph },
  1441. { kMipmapDebugMacros, IncludeLocation.Pregraph}
  1442. };
  1443. public static readonly IncludeCollection DOTSPregraph = new IncludeCollection
  1444. {
  1445. { kDOTS, IncludeLocation.Pregraph, true },
  1446. };
  1447. public static readonly IncludeCollection WriteRenderLayersPregraph = new IncludeCollection
  1448. {
  1449. { kRenderingLayers, IncludeLocation.Pregraph, true },
  1450. };
  1451. public static readonly IncludeCollection ProbeVolumePregraph = new IncludeCollection
  1452. {
  1453. { kProbeVolumes, IncludeLocation.Pregraph, true },
  1454. };
  1455. public static readonly IncludeCollection ShaderGraphPregraph = new IncludeCollection
  1456. {
  1457. { kGraphFunctions, IncludeLocation.Pregraph },
  1458. };
  1459. public static readonly IncludeCollection CorePostgraph = new IncludeCollection
  1460. {
  1461. { kShaderPass, IncludeLocation.Pregraph },
  1462. { kVaryings, IncludeLocation.Postgraph },
  1463. };
  1464. public static readonly IncludeCollection DepthOnly = new IncludeCollection
  1465. {
  1466. // Pre-graph
  1467. { DOTSPregraph },
  1468. { CorePregraph },
  1469. { ShaderGraphPregraph },
  1470. // Post-graph
  1471. { CorePostgraph },
  1472. { kDepthOnlyPass, IncludeLocation.Postgraph },
  1473. };
  1474. public static readonly IncludeCollection DepthNormalsOnly = new IncludeCollection
  1475. {
  1476. // Pre-graph
  1477. { DOTSPregraph },
  1478. { WriteRenderLayersPregraph },
  1479. { CorePregraph },
  1480. { ShaderGraphPregraph },
  1481. // Post-graph
  1482. { CorePostgraph },
  1483. { kDepthNormalsOnlyPass, IncludeLocation.Postgraph },
  1484. };
  1485. public static readonly IncludeCollection MotionVectors = new IncludeCollection
  1486. {
  1487. // Pre-graph
  1488. { DOTSPregraph },
  1489. { WriteRenderLayersPregraph },
  1490. { CorePregraph },
  1491. { ShaderGraphPregraph },
  1492. //Post-graph
  1493. { CorePostgraph },
  1494. { kMotionVectorPass, IncludeLocation.Postgraph },
  1495. };
  1496. public static readonly IncludeCollection ShadowCaster = new IncludeCollection
  1497. {
  1498. // Pre-graph
  1499. { DOTSPregraph },
  1500. { CorePregraph },
  1501. { ShaderGraphPregraph },
  1502. // Post-graph
  1503. { CorePostgraph },
  1504. { kShadowCasterPass, IncludeLocation.Postgraph },
  1505. };
  1506. public static readonly IncludeCollection DBufferPregraph = new IncludeCollection
  1507. {
  1508. { kDBuffer, IncludeLocation.Pregraph },
  1509. };
  1510. public static readonly IncludeCollection SceneSelection = new IncludeCollection
  1511. {
  1512. // Pre-graph
  1513. { CorePregraph },
  1514. { ShaderGraphPregraph },
  1515. { DOTSPregraph },
  1516. // Post-graph
  1517. { CorePostgraph },
  1518. { kSelectionPickingPass, IncludeLocation.Postgraph },
  1519. };
  1520. public static readonly IncludeCollection ScenePicking = new IncludeCollection
  1521. {
  1522. // Pre-graph
  1523. { CorePregraph },
  1524. { ShaderGraphPregraph },
  1525. { DOTSPregraph },
  1526. // Post-graph
  1527. { CorePostgraph },
  1528. { kSelectionPickingPass, IncludeLocation.Postgraph },
  1529. };
  1530. public static readonly IncludeCollection LODCrossFade = new IncludeCollection
  1531. {
  1532. { kLODCrossFade, IncludeLocation.Pregraph }
  1533. };
  1534. }
  1535. #endregion
  1536. #region Defines
  1537. static class CoreDefines
  1538. {
  1539. public static readonly DefineCollection UseLegacySpriteBlocks = new DefineCollection
  1540. {
  1541. { CoreKeywordDescriptors.UseLegacySpriteBlocks, 1, new FieldCondition(CoreFields.UseLegacySpriteBlocks, true) },
  1542. };
  1543. public static readonly DefineCollection UseFragmentFog = new DefineCollection()
  1544. {
  1545. {CoreKeywordDescriptors.UseFragmentFog, 1},
  1546. };
  1547. public static readonly DefineCollection SceneSelection = new DefineCollection
  1548. {
  1549. { CoreKeywordDescriptors.SceneSelectionPass, 1 },
  1550. };
  1551. public static readonly DefineCollection ScenePicking = new DefineCollection
  1552. {
  1553. { CoreKeywordDescriptors.ScenePickingPass, 1 },
  1554. };
  1555. }
  1556. #endregion
  1557. #region KeywordDescriptors
  1558. static class CoreKeywordDescriptors
  1559. {
  1560. public static readonly KeywordDescriptor StaticLightmap = new KeywordDescriptor()
  1561. {
  1562. displayName = "Static Lightmap",
  1563. referenceName = "LIGHTMAP_ON",
  1564. type = KeywordType.Boolean,
  1565. definition = KeywordDefinition.MultiCompile,
  1566. scope = KeywordScope.Global,
  1567. };
  1568. public static readonly KeywordDescriptor DynamicLightmap = new KeywordDescriptor()
  1569. {
  1570. displayName = "Dynamic Lightmap",
  1571. referenceName = "DYNAMICLIGHTMAP_ON",
  1572. type = KeywordType.Boolean,
  1573. definition = KeywordDefinition.MultiCompile,
  1574. scope = KeywordScope.Global,
  1575. };
  1576. public static readonly KeywordDescriptor DirectionalLightmapCombined = new KeywordDescriptor()
  1577. {
  1578. displayName = "Directional Lightmap Combined",
  1579. referenceName = "DIRLIGHTMAP_COMBINED",
  1580. type = KeywordType.Boolean,
  1581. definition = KeywordDefinition.MultiCompile,
  1582. scope = KeywordScope.Global,
  1583. };
  1584. public static readonly KeywordDescriptor SampleGI = new KeywordDescriptor()
  1585. {
  1586. displayName = "Sample GI",
  1587. referenceName = "_SAMPLE_GI",
  1588. type = KeywordType.Boolean,
  1589. definition = KeywordDefinition.ShaderFeature,
  1590. scope = KeywordScope.Global,
  1591. };
  1592. public static readonly KeywordDescriptor AlphaTestOn = new KeywordDescriptor()
  1593. {
  1594. displayName = ShaderKeywordStrings._ALPHATEST_ON,
  1595. referenceName = ShaderKeywordStrings._ALPHATEST_ON,
  1596. type = KeywordType.Boolean,
  1597. definition = KeywordDefinition.ShaderFeature,
  1598. scope = KeywordScope.Local,
  1599. stages = KeywordShaderStage.Fragment,
  1600. };
  1601. public static readonly KeywordDescriptor SurfaceTypeTransparent = new KeywordDescriptor()
  1602. {
  1603. displayName = ShaderKeywordStrings._SURFACE_TYPE_TRANSPARENT,
  1604. referenceName = ShaderKeywordStrings._SURFACE_TYPE_TRANSPARENT,
  1605. type = KeywordType.Boolean,
  1606. definition = KeywordDefinition.ShaderFeature,
  1607. scope = KeywordScope.Global, // needs to match HDRP
  1608. stages = KeywordShaderStage.Fragment,
  1609. };
  1610. public static readonly KeywordDescriptor AlphaPremultiplyOn = new KeywordDescriptor()
  1611. {
  1612. displayName = ShaderKeywordStrings._ALPHAPREMULTIPLY_ON,
  1613. referenceName = ShaderKeywordStrings._ALPHAPREMULTIPLY_ON,
  1614. type = KeywordType.Boolean,
  1615. definition = KeywordDefinition.ShaderFeature,
  1616. scope = KeywordScope.Local,
  1617. stages = KeywordShaderStage.Fragment,
  1618. };
  1619. public static readonly KeywordDescriptor AlphaModulateOn = new KeywordDescriptor()
  1620. {
  1621. displayName = ShaderKeywordStrings._ALPHAMODULATE_ON,
  1622. referenceName = ShaderKeywordStrings._ALPHAMODULATE_ON,
  1623. type = KeywordType.Boolean,
  1624. definition = KeywordDefinition.ShaderFeature,
  1625. scope = KeywordScope.Local,
  1626. stages = KeywordShaderStage.Fragment,
  1627. };
  1628. public static readonly KeywordDescriptor EvaluateSh = new KeywordDescriptor()
  1629. {
  1630. displayName = "Evaluate SH",
  1631. referenceName = "EVALUATE_SH",
  1632. type = KeywordType.Enum,
  1633. definition = KeywordDefinition.MultiCompile,
  1634. scope = KeywordScope.Global,
  1635. entries = new KeywordEntry[]
  1636. {
  1637. new KeywordEntry() { displayName = "Off", referenceName = "" },
  1638. new KeywordEntry() { displayName = "Evaluate SH Mixed", referenceName = "MIXED" },
  1639. new KeywordEntry() { displayName = "Evaluate SH Vertex", referenceName = "VERTEX" },
  1640. }
  1641. };
  1642. public static readonly KeywordDescriptor MainLightShadows = new KeywordDescriptor()
  1643. {
  1644. displayName = "Main Light Shadows",
  1645. referenceName = "",
  1646. type = KeywordType.Enum,
  1647. definition = KeywordDefinition.MultiCompile,
  1648. scope = KeywordScope.Global,
  1649. entries = new KeywordEntry[]
  1650. {
  1651. new KeywordEntry() { displayName = "Off", referenceName = "" },
  1652. new KeywordEntry() { displayName = "No Cascade", referenceName = "MAIN_LIGHT_SHADOWS" },
  1653. new KeywordEntry() { displayName = "Cascade", referenceName = "MAIN_LIGHT_SHADOWS_CASCADE" },
  1654. new KeywordEntry() { displayName = "Screen", referenceName = "MAIN_LIGHT_SHADOWS_SCREEN" },
  1655. }
  1656. };
  1657. public static readonly KeywordDescriptor CastingPunctualLightShadow = new KeywordDescriptor()
  1658. {
  1659. displayName = "Casting Punctual Light Shadow",
  1660. referenceName = "_CASTING_PUNCTUAL_LIGHT_SHADOW",
  1661. type = KeywordType.Boolean,
  1662. definition = KeywordDefinition.MultiCompile,
  1663. scope = KeywordScope.Global,
  1664. stages = KeywordShaderStage.Vertex,
  1665. };
  1666. public static readonly KeywordDescriptor AutomaticTimeBasedMotionVectors = new KeywordDescriptor()
  1667. {
  1668. displayName = "Automatic Time-Based Motion Vectors",
  1669. referenceName = "AUTOMATIC_TIME_BASED_MOTION_VECTORS",
  1670. type = KeywordType.Boolean,
  1671. definition = KeywordDefinition.Predefined,
  1672. scope = KeywordScope.Local,
  1673. stages = KeywordShaderStage.Vertex,
  1674. };
  1675. public static readonly KeywordDescriptor AddPrecomputedVelocity = new KeywordDescriptor()
  1676. {
  1677. displayName = "Add Precomputed Velocity",
  1678. referenceName = ShaderKeywordStrings._ADD_PRECOMPUTED_VELOCITY,
  1679. type = KeywordType.Boolean,
  1680. definition = KeywordDefinition.Predefined,
  1681. scope = KeywordScope.Local,
  1682. stages = KeywordShaderStage.Vertex,
  1683. };
  1684. public static readonly KeywordDescriptor AdditionalLights = new KeywordDescriptor()
  1685. {
  1686. displayName = "Additional Lights",
  1687. referenceName = "",
  1688. type = KeywordType.Enum,
  1689. definition = KeywordDefinition.MultiCompile,
  1690. scope = KeywordScope.Global,
  1691. entries = new KeywordEntry[]
  1692. {
  1693. new KeywordEntry() { displayName = "Off", referenceName = "" },
  1694. new KeywordEntry() { displayName = "Vertex", referenceName = "ADDITIONAL_LIGHTS_VERTEX" },
  1695. new KeywordEntry() { displayName = "Fragment", referenceName = "ADDITIONAL_LIGHTS" },
  1696. }
  1697. };
  1698. public static readonly KeywordDescriptor AdditionalLightShadows = new KeywordDescriptor()
  1699. {
  1700. displayName = "Additional Light Shadows",
  1701. referenceName = "_ADDITIONAL_LIGHT_SHADOWS",
  1702. type = KeywordType.Boolean,
  1703. definition = KeywordDefinition.MultiCompile,
  1704. scope = KeywordScope.Global,
  1705. stages = KeywordShaderStage.Fragment,
  1706. };
  1707. public static readonly KeywordDescriptor ReflectionProbeBlending = new KeywordDescriptor()
  1708. {
  1709. displayName = "Reflection Probe Blending",
  1710. referenceName = "_REFLECTION_PROBE_BLENDING",
  1711. type = KeywordType.Boolean,
  1712. definition = KeywordDefinition.MultiCompile,
  1713. scope = KeywordScope.Global,
  1714. stages = KeywordShaderStage.Fragment,
  1715. };
  1716. public static readonly KeywordDescriptor ReflectionProbeBoxProjection = new KeywordDescriptor()
  1717. {
  1718. displayName = "Reflection Probe Box Projection",
  1719. referenceName = "_REFLECTION_PROBE_BOX_PROJECTION",
  1720. type = KeywordType.Boolean,
  1721. definition = KeywordDefinition.MultiCompile,
  1722. scope = KeywordScope.Global,
  1723. stages = KeywordShaderStage.Fragment,
  1724. };
  1725. public static readonly KeywordDescriptor ShadowsSoft = new KeywordDescriptor()
  1726. {
  1727. displayName = "Soft Shadows",
  1728. referenceName = "",
  1729. type = KeywordType.Enum,
  1730. definition = KeywordDefinition.MultiCompile,
  1731. scope = KeywordScope.Global,
  1732. stages = KeywordShaderStage.Fragment,
  1733. entries = new KeywordEntry[]
  1734. {
  1735. new KeywordEntry() { displayName = "Off", referenceName = "" },
  1736. new KeywordEntry() { displayName = "Soft Shadows Per Light", referenceName = "SHADOWS_SOFT" },
  1737. new KeywordEntry() { displayName = "Soft Shadows Low", referenceName = "SHADOWS_SOFT_LOW" },
  1738. new KeywordEntry() { displayName = "Soft Shadows Medium", referenceName = "SHADOWS_SOFT_MEDIUM" },
  1739. new KeywordEntry() { displayName = "Soft Shadows High", referenceName = "SHADOWS_SOFT_HIGH" },
  1740. }
  1741. };
  1742. public static readonly KeywordDescriptor MixedLightingSubtractive = new KeywordDescriptor()
  1743. {
  1744. displayName = "Mixed Lighting Subtractive",
  1745. referenceName = "_MIXED_LIGHTING_SUBTRACTIVE",
  1746. type = KeywordType.Boolean,
  1747. definition = KeywordDefinition.MultiCompile,
  1748. scope = KeywordScope.Global,
  1749. };
  1750. public static readonly KeywordDescriptor LightmapShadowMixing = new KeywordDescriptor()
  1751. {
  1752. displayName = "Lightmap Shadow Mixing",
  1753. referenceName = "LIGHTMAP_SHADOW_MIXING",
  1754. type = KeywordType.Boolean,
  1755. definition = KeywordDefinition.MultiCompile,
  1756. scope = KeywordScope.Global,
  1757. };
  1758. public static readonly KeywordDescriptor ShadowsShadowmask = new KeywordDescriptor()
  1759. {
  1760. displayName = "Shadows Shadowmask",
  1761. referenceName = "SHADOWS_SHADOWMASK",
  1762. type = KeywordType.Boolean,
  1763. definition = KeywordDefinition.MultiCompile,
  1764. scope = KeywordScope.Global,
  1765. };
  1766. public static readonly KeywordDescriptor LightLayers = new KeywordDescriptor()
  1767. {
  1768. displayName = "Light Layers",
  1769. referenceName = "_LIGHT_LAYERS",
  1770. type = KeywordType.Boolean,
  1771. definition = KeywordDefinition.MultiCompile,
  1772. scope = KeywordScope.Global,
  1773. stages = KeywordShaderStage.Fragment,
  1774. };
  1775. public static readonly KeywordDescriptor RenderPassEnabled = new KeywordDescriptor()
  1776. {
  1777. displayName = "Render Pass Enabled",
  1778. referenceName = "_RENDER_PASS_ENABLED",
  1779. type = KeywordType.Boolean,
  1780. definition = KeywordDefinition.MultiCompile,
  1781. scope = KeywordScope.Global,
  1782. stages = KeywordShaderStage.Fragment,
  1783. };
  1784. public static readonly KeywordDescriptor ShapeLightType0 = new KeywordDescriptor()
  1785. {
  1786. displayName = "Shape Light Type 0",
  1787. referenceName = "USE_SHAPE_LIGHT_TYPE_0",
  1788. type = KeywordType.Boolean,
  1789. definition = KeywordDefinition.MultiCompile,
  1790. scope = KeywordScope.Global,
  1791. };
  1792. public static readonly KeywordDescriptor ShapeLightType1 = new KeywordDescriptor()
  1793. {
  1794. displayName = "Shape Light Type 1",
  1795. referenceName = "USE_SHAPE_LIGHT_TYPE_1",
  1796. type = KeywordType.Boolean,
  1797. definition = KeywordDefinition.MultiCompile,
  1798. scope = KeywordScope.Global,
  1799. };
  1800. public static readonly KeywordDescriptor ShapeLightType2 = new KeywordDescriptor()
  1801. {
  1802. displayName = "Shape Light Type 2",
  1803. referenceName = "USE_SHAPE_LIGHT_TYPE_2",
  1804. type = KeywordType.Boolean,
  1805. definition = KeywordDefinition.MultiCompile,
  1806. scope = KeywordScope.Global,
  1807. };
  1808. public static readonly KeywordDescriptor ShapeLightType3 = new KeywordDescriptor()
  1809. {
  1810. displayName = "Shape Light Type 3",
  1811. referenceName = "USE_SHAPE_LIGHT_TYPE_3",
  1812. type = KeywordType.Boolean,
  1813. definition = KeywordDefinition.MultiCompile,
  1814. scope = KeywordScope.Global,
  1815. };
  1816. public static readonly KeywordDescriptor UseLegacySpriteBlocks = new KeywordDescriptor()
  1817. {
  1818. displayName = "UseLegacySpriteBlocks",
  1819. referenceName = "USELEGACYSPRITEBLOCKS",
  1820. type = KeywordType.Boolean,
  1821. };
  1822. public static readonly KeywordDescriptor UseFragmentFog = new KeywordDescriptor()
  1823. {
  1824. displayName = "UseFragmentFog",
  1825. referenceName = "_FOG_FRAGMENT",
  1826. type = KeywordType.Boolean,
  1827. };
  1828. public static readonly KeywordDescriptor GBufferNormalsOct = new KeywordDescriptor()
  1829. {
  1830. displayName = "GBuffer normal octahedron encoding",
  1831. referenceName = "_GBUFFER_NORMALS_OCT",
  1832. type = KeywordType.Boolean,
  1833. definition = KeywordDefinition.MultiCompile,
  1834. scope = KeywordScope.Global,
  1835. stages = KeywordShaderStage.Fragment,
  1836. };
  1837. public static readonly KeywordDescriptor DBuffer = new KeywordDescriptor()
  1838. {
  1839. displayName = "Decals",
  1840. referenceName = "",
  1841. type = KeywordType.Enum,
  1842. definition = KeywordDefinition.MultiCompile,
  1843. scope = KeywordScope.Global,
  1844. entries = new KeywordEntry[]
  1845. {
  1846. new KeywordEntry() { displayName = "Off", referenceName = "" },
  1847. new KeywordEntry() { displayName = "DBuffer Mrt1", referenceName = "DBUFFER_MRT1" },
  1848. new KeywordEntry() { displayName = "DBuffer Mrt2", referenceName = "DBUFFER_MRT2" },
  1849. new KeywordEntry() { displayName = "DBuffer Mrt3", referenceName = "DBUFFER_MRT3" },
  1850. },
  1851. stages = KeywordShaderStage.Fragment,
  1852. };
  1853. public static readonly KeywordDescriptor DebugDisplay = new KeywordDescriptor()
  1854. {
  1855. displayName = "Debug Display",
  1856. referenceName = "DEBUG_DISPLAY",
  1857. type = KeywordType.Boolean,
  1858. definition = KeywordDefinition.MultiCompile,
  1859. scope = KeywordScope.Global,
  1860. stages = KeywordShaderStage.Fragment,
  1861. };
  1862. public static readonly KeywordDescriptor SceneSelectionPass = new KeywordDescriptor()
  1863. {
  1864. displayName = "Scene Selection Pass",
  1865. referenceName = "SCENESELECTIONPASS",
  1866. type = KeywordType.Boolean,
  1867. };
  1868. public static readonly KeywordDescriptor ScenePickingPass = new KeywordDescriptor()
  1869. {
  1870. displayName = "Scene Picking Pass",
  1871. referenceName = "SCENEPICKINGPASS",
  1872. type = KeywordType.Boolean,
  1873. };
  1874. public static readonly KeywordDescriptor AlphaClipThreshold = new KeywordDescriptor()
  1875. {
  1876. displayName = "AlphaClipThreshold",
  1877. referenceName = "ALPHA_CLIP_THRESHOLD",
  1878. type = KeywordType.Boolean,
  1879. definition = KeywordDefinition.Predefined,
  1880. };
  1881. public static readonly KeywordDescriptor LightCookies = new KeywordDescriptor()
  1882. {
  1883. displayName = "Light Cookies",
  1884. referenceName = "_LIGHT_COOKIES",
  1885. type = KeywordType.Boolean,
  1886. definition = KeywordDefinition.MultiCompile,
  1887. scope = KeywordScope.Global,
  1888. stages = KeywordShaderStage.Fragment,
  1889. };
  1890. public static readonly KeywordDescriptor ForwardPlus = new KeywordDescriptor()
  1891. {
  1892. displayName = "Forward+",
  1893. referenceName = "_FORWARD_PLUS",
  1894. type = KeywordType.Boolean,
  1895. definition = KeywordDefinition.MultiCompile,
  1896. scope = KeywordScope.Global,
  1897. };
  1898. public static readonly KeywordDescriptor EditorVisualization = new KeywordDescriptor()
  1899. {
  1900. displayName = "Editor Visualization",
  1901. referenceName = "EDITOR_VISUALIZATION",
  1902. type = KeywordType.Boolean,
  1903. definition = KeywordDefinition.ShaderFeature,
  1904. scope = KeywordScope.Global,
  1905. };
  1906. public static readonly KeywordDescriptor LODFadeCrossFade = new KeywordDescriptor()
  1907. {
  1908. displayName = ShaderKeywordStrings.LOD_FADE_CROSSFADE,
  1909. referenceName = ShaderKeywordStrings.LOD_FADE_CROSSFADE,
  1910. type = KeywordType.Boolean,
  1911. definition = KeywordDefinition.MultiCompile,
  1912. // Note: SpeedTree shaders used to have their own PS-based Crossfade,
  1913. // as well as a VS-based smooth LOD transition effect.
  1914. // These shaders need the LOD_FADE_CROSSFADE keyword in the VS
  1915. // to skip the VS-based effect.
  1916. // Note: DOTS instancing uses a different instance index encoding
  1917. // when crossfade is active, so all stages are affected by the
  1918. // LOD_FADE_CROSSFADE keyword.
  1919. scope = KeywordScope.Global
  1920. };
  1921. public static readonly KeywordDescriptor UseUnityCrossFade = new KeywordDescriptor()
  1922. {
  1923. displayName = ShaderKeywordStrings.USE_UNITY_CROSSFADE,
  1924. referenceName = ShaderKeywordStrings.USE_UNITY_CROSSFADE,
  1925. type = KeywordType.Boolean,
  1926. definition = KeywordDefinition.MultiCompile,
  1927. scope = KeywordScope.Global,
  1928. stages = KeywordShaderStage.Fragment,
  1929. };
  1930. public static readonly KeywordDescriptor ScreenSpaceAmbientOcclusion = new KeywordDescriptor()
  1931. {
  1932. displayName = "Screen Space Ambient Occlusion",
  1933. referenceName = "_SCREEN_SPACE_OCCLUSION",
  1934. type = KeywordType.Boolean,
  1935. definition = KeywordDefinition.MultiCompile,
  1936. scope = KeywordScope.Global,
  1937. stages = KeywordShaderStage.Fragment,
  1938. };
  1939. public static readonly KeywordDescriptor UseLegacyLightmaps = new KeywordDescriptor()
  1940. {
  1941. displayName = "Use Legacy Lightmaps",
  1942. referenceName = ShaderKeywordStrings.USE_LEGACY_LIGHTMAPS,
  1943. type = KeywordType.Boolean,
  1944. definition = KeywordDefinition.MultiCompile,
  1945. scope = KeywordScope.Global
  1946. };
  1947. }
  1948. #endregion
  1949. #region Keywords
  1950. static class CoreKeywords
  1951. {
  1952. public static readonly KeywordCollection ShadowCaster = new KeywordCollection
  1953. {
  1954. { CoreKeywordDescriptors.CastingPunctualLightShadow },
  1955. };
  1956. }
  1957. #endregion
  1958. #region FieldDescriptors
  1959. static class CoreFields
  1960. {
  1961. public static readonly FieldDescriptor UseLegacySpriteBlocks = new FieldDescriptor("Universal", "UseLegacySpriteBlocks", "UNIVERSAL_USELEGACYSPRITEBLOCKS");
  1962. }
  1963. #endregion
  1964. #region CustomInterpolators
  1965. static class CoreCustomInterpDescriptors
  1966. {
  1967. public static readonly CustomInterpSubGen.Collection Common = new CustomInterpSubGen.Collection
  1968. {
  1969. // Custom interpolators are not explicitly defined in the SurfaceDescriptionInputs template.
  1970. // This entry point will let us generate a block of pass-through assignments for each field.
  1971. CustomInterpSubGen.Descriptor.MakeBlock(CustomInterpSubGen.Splice.k_spliceCopyToSDI, "output", "input"),
  1972. // sgci_PassThroughFunc is called from BuildVaryings in Varyings.hlsl to copy custom interpolators from vertex descriptions.
  1973. // this entry point allows for the function to be defined before it is used.
  1974. CustomInterpSubGen.Descriptor.MakeFunc(CustomInterpSubGen.Splice.k_splicePreSurface, "CustomInterpolatorPassThroughFunc", "Varyings", "VertexDescription", "CUSTOMINTERPOLATOR_VARYPASSTHROUGH_FUNC", "FEATURES_GRAPH_VERTEX")
  1975. };
  1976. }
  1977. #endregion
  1978. }