No Description
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.

MaterialPostprocessor.cs 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEditor.Callbacks;
  5. using UnityEditor.Rendering.Analytics;
  6. using UnityEditor.Rendering.Universal.Analytics;
  7. using UnityEditor.Rendering.Universal.ShaderGUI;
  8. using UnityEditor.ShaderGraph;
  9. using UnityEngine;
  10. using UnityEngine.Rendering;
  11. using UnityEngine.Rendering.Universal;
  12. using static Unity.Rendering.Universal.ShaderUtils;
  13. using BlendMode = UnityEngine.Rendering.BlendMode;
  14. namespace UnityEditor.Rendering.Universal
  15. {
  16. class MaterialModificationProcessor : AssetModificationProcessor
  17. {
  18. const string k_MaterialExtension = ".mat";
  19. static void OnWillCreateAsset(string asset)
  20. {
  21. if (!asset.HasExtension(k_MaterialExtension))
  22. {
  23. return;
  24. }
  25. MaterialPostprocessor.s_CreatedAssets.Add(asset);
  26. }
  27. }
  28. class MaterialReimporter : Editor
  29. {
  30. static bool s_NeedToCheckProjSettingExistence = true;
  31. static void ReimportAllMaterials()
  32. {
  33. AssetReimportUtils.ReimportAll<Material>(out var duration, out var numberOfAssetsReimported);
  34. AssetReimporterAnalytic.Send<Material>(duration, numberOfAssetsReimported);
  35. MaterialPostprocessor.s_NeedsSavingAssets = true;
  36. }
  37. [InitializeOnLoadMethod]
  38. static void RegisterUpgraderReimport()
  39. {
  40. EditorApplication.update += () =>
  41. {
  42. if (GraphicsSettings.currentRenderPipeline is not UniversalRenderPipelineAsset universalRenderPipeline)
  43. return;
  44. if (Time.renderedFrameCount > 0)
  45. {
  46. bool fileExist = true;
  47. // We check the file existence only once to avoid IO operations every frame.
  48. if (s_NeedToCheckProjSettingExistence)
  49. {
  50. fileExist = System.IO.File.Exists(UniversalProjectSettings.filePath);
  51. s_NeedToCheckProjSettingExistence = false;
  52. }
  53. //This method is called at opening and when URP package change (update of manifest.json)
  54. var curUpgradeVersion = UniversalProjectSettings.materialVersionForUpgrade;
  55. if (curUpgradeVersion != MaterialPostprocessor.k_Upgraders.Length)
  56. {
  57. string commandLineOptions = Environment.CommandLine;
  58. bool inTestSuite = commandLineOptions.Contains("-testResults");
  59. bool isTemplate = EditorApplication.isCreateFromTemplate;
  60. if (!inTestSuite && fileExist && !isTemplate)
  61. {
  62. EditorUtility.DisplayDialog("URP Material upgrade", "The Materials in your Project were created using an older version of the Universal Render Pipeline (URP)." +
  63. " Unity must upgrade them to be compatible with your current version of URP. \n" +
  64. " Unity will re-import all of the Materials in your project, save the upgraded Materials to disk, and check them out in source control if needed.\n" +
  65. " Please see the Material upgrade guide in the URP documentation for more information.", "Ok");
  66. }
  67. ReimportAllMaterials();
  68. }
  69. if (MaterialPostprocessor.s_NeedsSavingAssets)
  70. MaterialPostprocessor.SaveAssetsToDisk();
  71. }
  72. };
  73. }
  74. }
  75. class MaterialPostprocessor : AssetPostprocessor
  76. {
  77. public static List<string> s_CreatedAssets = new List<string>();
  78. internal static List<string> s_ImportedAssetThatNeedSaving = new List<string>();
  79. internal static bool s_NeedsSavingAssets = false;
  80. internal static readonly Action<Material, ShaderID>[] k_Upgraders = { UpgradeV1, UpgradeV2, UpgradeV3, UpgradeV4, UpgradeV5, UpgradeV6, UpgradeV7, UpgradeV8, UpgradeV9 };
  81. static internal void SaveAssetsToDisk()
  82. {
  83. string commandLineOptions = System.Environment.CommandLine;
  84. bool inTestSuite = commandLineOptions.Contains("-testResults");
  85. if (inTestSuite)
  86. {
  87. // Need to update material version to prevent infinite loop in the upgrader
  88. // when running tests.
  89. UniversalProjectSettings.materialVersionForUpgrade = k_Upgraders.Length;
  90. return;
  91. }
  92. foreach (var asset in s_ImportedAssetThatNeedSaving)
  93. {
  94. AssetDatabase.MakeEditable(asset);
  95. }
  96. AssetDatabase.SaveAssets();
  97. //to prevent data loss, only update the saved version if user applied change and assets are written to
  98. UniversalProjectSettings.materialVersionForUpgrade = k_Upgraders.Length;
  99. UniversalProjectSettings.Save();
  100. s_ImportedAssetThatNeedSaving.Clear();
  101. s_NeedsSavingAssets = false;
  102. }
  103. [RunAfterClass(typeof(UniversalRenderPipelineGlobalSettingsPostprocessor))]
  104. static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
  105. {
  106. string upgradeLog = "";
  107. var upgradeCount = 0;
  108. foreach (var asset in importedAssets)
  109. {
  110. // we only care about materials
  111. if (!asset.EndsWith(".mat", StringComparison.InvariantCultureIgnoreCase))
  112. continue;
  113. // load the material and look for it's Universal ShaderID
  114. // we only care about versioning materials using a known Universal ShaderID
  115. // this skips any materials that only target other render pipelines, are user shaders,
  116. // or are shaders we don't care to version
  117. var material = (Material)AssetDatabase.LoadAssetAtPath(asset, typeof(Material));
  118. var shaderID = GetShaderID(material.shader);
  119. if (shaderID == ShaderID.Unknown)
  120. continue;
  121. var wasUpgraded = false;
  122. var debug = "\n" + material.name + "(" + shaderID + ")";
  123. // look for the Universal AssetVersion
  124. AssetVersion assetVersion = null;
  125. var allAssets = AssetDatabase.LoadAllAssetsAtPath(asset);
  126. foreach (var subAsset in allAssets)
  127. {
  128. if (subAsset is AssetVersion sub)
  129. {
  130. assetVersion = sub;
  131. }
  132. }
  133. if (!assetVersion)
  134. {
  135. wasUpgraded = true;
  136. assetVersion = ScriptableObject.CreateInstance<AssetVersion>();
  137. if (s_CreatedAssets.Contains(asset))
  138. {
  139. assetVersion.version = k_Upgraders.Length;
  140. s_CreatedAssets.Remove(asset);
  141. InitializeLatest(material, shaderID);
  142. debug += " initialized.";
  143. }
  144. else
  145. {
  146. if (shaderID.IsShaderGraph())
  147. {
  148. // ShaderGraph materials NEVER had asset versioning applied prior to version 5.
  149. // so if we see a ShaderGraph material with no assetVersion, set it to 5 to ensure we apply all necessary versions.
  150. assetVersion.version = 5;
  151. debug += $" shadergraph material assumed to be version 5 due to missing version.";
  152. }
  153. else
  154. {
  155. assetVersion.version = UniversalProjectSettings.materialVersionForUpgrade;
  156. debug += $" assumed to be version {UniversalProjectSettings.materialVersionForUpgrade} due to missing version.";
  157. }
  158. }
  159. assetVersion.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable;
  160. AssetDatabase.AddObjectToAsset(assetVersion, asset);
  161. }
  162. while (assetVersion.version >= 0 && assetVersion.version < k_Upgraders.Length)
  163. {
  164. k_Upgraders[assetVersion.version](material, shaderID);
  165. debug += $" upgrading:v{assetVersion.version} to v{assetVersion.version + 1}";
  166. assetVersion.version++;
  167. wasUpgraded = true;
  168. }
  169. if (wasUpgraded)
  170. {
  171. upgradeLog += debug;
  172. upgradeCount++;
  173. EditorUtility.SetDirty(assetVersion);
  174. s_ImportedAssetThatNeedSaving.Add(asset);
  175. s_NeedsSavingAssets = true;
  176. }
  177. }
  178. // Uncomment to show upgrade debug logs
  179. //if (!string.IsNullOrEmpty(upgradeLog))
  180. // Debug.Log("UniversalRP Material log: " + upgradeLog);
  181. }
  182. static void InitializeLatest(Material material, ShaderID id)
  183. {
  184. // newly created materials should reset their keywords immediately (in case inspector doesn't get invoked)
  185. Unity.Rendering.Universal.ShaderUtils.UpdateMaterial(material, MaterialUpdateType.CreatedNewMaterial, id);
  186. }
  187. static void UpgradeV1(Material material, ShaderID shaderID)
  188. {
  189. if (shaderID.IsShaderGraph())
  190. return;
  191. var shaderPath = ShaderUtils.GetShaderPath((ShaderPathID)shaderID);
  192. var upgradeFlag = MaterialUpgrader.UpgradeFlags.LogMessageWhenNoUpgraderFound;
  193. switch (shaderID)
  194. {
  195. case ShaderID.Unlit:
  196. MaterialUpgrader.Upgrade(material, new UnlitUpdaterV1(shaderPath), upgradeFlag);
  197. UnlitShader.SetMaterialKeywords(material);
  198. break;
  199. case ShaderID.SimpleLit:
  200. MaterialUpgrader.Upgrade(material, new SimpleLitUpdaterV1(shaderPath), upgradeFlag);
  201. SimpleLitShader.SetMaterialKeywords(material, SimpleLitGUI.SetMaterialKeywords);
  202. break;
  203. case ShaderID.Lit:
  204. MaterialUpgrader.Upgrade(material, new LitUpdaterV1(shaderPath), upgradeFlag);
  205. LitShader.SetMaterialKeywords(material, LitGUI.SetMaterialKeywords);
  206. break;
  207. case ShaderID.ParticlesLit:
  208. MaterialUpgrader.Upgrade(material, new ParticleUpdaterV1(shaderPath), upgradeFlag);
  209. ParticlesLitShader.SetMaterialKeywords(material, LitGUI.SetMaterialKeywords, ParticleGUI.SetMaterialKeywords);
  210. break;
  211. case ShaderID.ParticlesSimpleLit:
  212. MaterialUpgrader.Upgrade(material, new ParticleUpdaterV1(shaderPath), upgradeFlag);
  213. ParticlesSimpleLitShader.SetMaterialKeywords(material, SimpleLitGUI.SetMaterialKeywords, ParticleGUI.SetMaterialKeywords);
  214. break;
  215. case ShaderID.ParticlesUnlit:
  216. MaterialUpgrader.Upgrade(material, new ParticleUpdaterV1(shaderPath), upgradeFlag);
  217. ParticlesUnlitShader.SetMaterialKeywords(material, null, ParticleGUI.SetMaterialKeywords);
  218. break;
  219. }
  220. }
  221. static void UpgradeV2(Material material, ShaderID shaderID)
  222. {
  223. if (shaderID.IsShaderGraph())
  224. return;
  225. // fix 50 offset on shaders
  226. if (material.HasProperty("_QueueOffset"))
  227. BaseShaderGUI.SetupMaterialBlendMode(material);
  228. }
  229. static void UpgradeV3(Material material, ShaderID shaderID)
  230. {
  231. if (shaderID.IsShaderGraph())
  232. return;
  233. switch (shaderID)
  234. {
  235. case ShaderID.Lit:
  236. case ShaderID.SimpleLit:
  237. case ShaderID.ParticlesLit:
  238. case ShaderID.ParticlesSimpleLit:
  239. case ShaderID.ParticlesUnlit:
  240. var propertyID = Shader.PropertyToID("_EmissionColor");
  241. if (material.HasProperty(propertyID))
  242. {
  243. // In older version there was a bug that these shaders did not had HDR attribute on emission property.
  244. // This caused emission color to be converted from gamma to linear space.
  245. // In order to avoid visual regression on older projects we will do gamma to linear conversion here.
  246. var emissionGamma = material.GetColor(propertyID);
  247. var emissionLinear = emissionGamma.linear;
  248. material.SetColor(propertyID, emissionLinear);
  249. }
  250. break;
  251. }
  252. }
  253. static void UpgradeV4(Material material, ShaderID shaderID)
  254. { }
  255. static void UpgradeV5(Material material, ShaderID shaderID)
  256. {
  257. if (shaderID.IsShaderGraph())
  258. return;
  259. var propertyID = Shader.PropertyToID("_Surface");
  260. if (material.HasProperty(propertyID))
  261. {
  262. float surfaceType = material.GetFloat(propertyID);
  263. if (surfaceType >= 1.0f)
  264. {
  265. material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
  266. }
  267. else
  268. {
  269. material.DisableKeyword("_SURFACE_TYPE_TRANSPARENT");
  270. }
  271. }
  272. }
  273. // Separate Preserve Specular Lighting from Premultiplied blend mode.
  274. // Update materials params for backwards compatibility. (Keep the same end result).
  275. // - Previous (incorrect) premultiplied blend mode --> Alpha blend mode + Preserve Specular Lighting
  276. // - Otherwise keep the blend mode and disable Preserve Specular Lighting
  277. // - Correct premultiply mode is not possible in V5.
  278. //
  279. // This is run both hand-written and shadergraph materials.
  280. //
  281. // Hand-written and overridable shadergraphs always have blendModePreserveSpecular property, which
  282. // is assumed to be new since we only run this for V5 -> V6 upgrade.
  283. //
  284. // Fixed shadergraphs do not have this keyword and are filtered out.
  285. // The blend mode is baked in the generated shader, so there's no material properties to be upgraded.
  286. // The shadergraph upgrade on re-import will handle the fixed shadergraphs.
  287. static void UpgradeV6(Material material, ShaderID shaderID)
  288. {
  289. var surfaceTypePID = Shader.PropertyToID(Property.SurfaceType);
  290. bool isTransparent = material.HasProperty(surfaceTypePID) && material.GetFloat(surfaceTypePID) >= 1.0f;
  291. if (isTransparent)
  292. {
  293. if (shaderID == ShaderID.Unlit)
  294. {
  295. var blendModePID = Shader.PropertyToID(Property.BlendMode);
  296. var blendMode = (BaseShaderGUI.BlendMode)material.GetFloat(blendModePID);
  297. // Premultiply used to be "Premultiply (* alpha in shader)" aka Alpha blend
  298. if (blendMode == BaseShaderGUI.BlendMode.Premultiply)
  299. material.SetFloat(blendModePID, (float)BaseShaderGUI.BlendMode.Alpha);
  300. }
  301. else
  302. {
  303. var blendModePreserveSpecularPID = Shader.PropertyToID(Property.BlendModePreserveSpecular);
  304. if (material.HasProperty(blendModePreserveSpecularPID))
  305. {
  306. // TL;DR; As Complex Lit was not being versioned before we want to only upgrade it in certain
  307. // cases to not alter visuals
  308. //
  309. // To elaborate, this is needed for the following reasons:
  310. // 1) Premultiplied used to mean something different before V6
  311. // 2) If the update is applied twice it will change visuals
  312. // 3) As Complex Lit was missing form the ShaderID enum it was never being upgraded, so its
  313. // version is not a reliable indicator of which version of Premultiplied alpha the user
  314. // had intended (e.g. the URP Foundation test project is currently at V7 but some
  315. // Complex Lit materials are at V3)
  316. // 5) To determine the intended version we can check which version the project is being upgraded
  317. // from (as we can then know which version it was being actually used as). If the project is
  318. // at version 6 or higher then we know that if the user had selected Premultiplied it is
  319. // already working based on the new interpretation and should not be changed
  320. bool skipChangingBlendMode = shaderID == ShaderID.ComplexLit &&
  321. UniversalProjectSettings.materialVersionForUpgrade >= 6;
  322. var blendModePID = Shader.PropertyToID(Property.BlendMode);
  323. var blendMode = (BaseShaderGUI.BlendMode)material.GetFloat(blendModePID);
  324. if (blendMode == BaseShaderGUI.BlendMode.Premultiply && !skipChangingBlendMode)
  325. {
  326. material.SetFloat(blendModePID, (float)BaseShaderGUI.BlendMode.Alpha);
  327. material.SetFloat(blendModePreserveSpecularPID, 1.0f);
  328. }
  329. else
  330. {
  331. material.SetFloat(blendModePreserveSpecularPID, 0.0f);
  332. }
  333. BaseShaderGUI.SetMaterialKeywords(material);
  334. }
  335. }
  336. }
  337. }
  338. // Upgrades alpha-clipped materials to include logic for automatic alpha-to-coverage support
  339. static void UpgradeV7(Material material, ShaderID shaderID)
  340. {
  341. var surfacePropertyID = Shader.PropertyToID(Property.SurfaceType);
  342. var alphaClipPropertyID = Shader.PropertyToID(Property.AlphaClip);
  343. var alphaToMaskPropertyID = Shader.PropertyToID(Property.AlphaToMask);
  344. if (material.HasProperty(surfacePropertyID) &&
  345. material.HasProperty(alphaClipPropertyID) &&
  346. material.HasProperty(alphaToMaskPropertyID))
  347. {
  348. bool isOpaque = material.GetFloat(surfacePropertyID) < 1.0f;
  349. bool isAlphaClipEnabled = material.GetFloat(alphaClipPropertyID) > 0.0f;
  350. float alphaToMask = (isOpaque && isAlphaClipEnabled) ? 1.0f : 0.0f;
  351. material.SetFloat(alphaToMaskPropertyID, alphaToMask);
  352. }
  353. }
  354. // We need to disable the passes with a { "LightMode" = "MotionVectors" } tag for URP shaders that have them,
  355. // otherwise they'll be rendered for static objects (transform not moving and no skeletal animation) regressing MV perf.
  356. //
  357. // This is now needed as most URP material types have their own dedicated MV pass (this is so they work with
  358. // Alpha-Clipping which needs per material data and not just generic vertex data like for the override shader).
  359. //
  360. // In Unity (both Built-in and SRP), the MV pass will be used even if disabled on frames where the object's
  361. // transform changes or there's skeletal animation. But for URP disabling wasn't necessary before as the single
  362. // object MV override shader was only used when needed (and there wasn't even anything to disable per material)
  363. //
  364. // N.B. the SetShaderPassEnabled API takes a tag value corresponding to the "LightMode" key and not a pass name
  365. static void UpgradeV8(Material material, ShaderID shaderID)
  366. {
  367. if (HasMotionVectorLightModeTag(shaderID))
  368. material.SetShaderPassEnabled(MotionVectorRenderPass.k_MotionVectorsLightModeTag, false);
  369. }
  370. // We want to disable the custom motion vector pass for SpeedTrees which won't have any
  371. // vertex animation due to no wind. This is done to prevent performance regression from
  372. // rendering trees with no motion vector output.
  373. static void UpgradeV9(Material material, ShaderID shaderID)
  374. {
  375. if(shaderID != ShaderID.SpeedTree8)
  376. return;
  377. // Check if the material is a SpeedTree material and whether it has wind turned on or off.
  378. if(SpeedTree8MaterialUpgrader.DoesMaterialHaveSpeedTreeWindKeyword(material))
  379. {
  380. bool motionVectorPassEnabled = SpeedTree8MaterialUpgrader.IsWindEnabled(material);
  381. material.SetShaderPassEnabled(MotionVectorRenderPass.k_MotionVectorsLightModeTag, motionVectorPassEnabled);
  382. }
  383. }
  384. }
  385. // Upgraders v1
  386. #region UpgradersV1
  387. internal class LitUpdaterV1 : MaterialUpgrader
  388. {
  389. public static void UpdateLitDetails(Material material)
  390. {
  391. if (material == null)
  392. throw new ArgumentNullException("material");
  393. if (material.GetTexture("_MetallicGlossMap") || material.GetTexture("_SpecGlossMap") || material.GetFloat("_SmoothnessTextureChannel") >= 0.5f)
  394. material.SetFloat("_Smoothness", material.GetFloat("_GlossMapScale"));
  395. else
  396. material.SetFloat("_Smoothness", material.GetFloat("_Glossiness"));
  397. }
  398. public LitUpdaterV1(string oldShaderName)
  399. {
  400. if (oldShaderName == null)
  401. throw new ArgumentNullException("oldShaderName");
  402. string standardShaderPath = ShaderUtils.GetShaderPath(ShaderPathID.Lit);
  403. RenameShader(oldShaderName, standardShaderPath, UpdateLitDetails);
  404. RenameTexture("_MainTex", "_BaseMap");
  405. RenameColor("_Color", "_BaseColor");
  406. RenameFloat("_GlossyReflections", "_EnvironmentReflections");
  407. }
  408. }
  409. internal class UnlitUpdaterV1 : MaterialUpgrader
  410. {
  411. static Shader bakedLit = Shader.Find(ShaderUtils.GetShaderPath(ShaderPathID.BakedLit));
  412. public static void UpgradeToUnlit(Material material)
  413. {
  414. if (material == null)
  415. throw new ArgumentNullException("material");
  416. if (material.GetFloat("_SampleGI") != 0)
  417. {
  418. material.shader = bakedLit;
  419. material.EnableKeyword("_NORMALMAP");
  420. }
  421. }
  422. public UnlitUpdaterV1(string oldShaderName)
  423. {
  424. if (oldShaderName == null)
  425. throw new ArgumentNullException("oldShaderName");
  426. RenameShader(oldShaderName, ShaderUtils.GetShaderPath(ShaderPathID.Unlit), UpgradeToUnlit);
  427. RenameTexture("_MainTex", "_BaseMap");
  428. RenameColor("_Color", "_BaseColor");
  429. }
  430. }
  431. internal class SimpleLitUpdaterV1 : MaterialUpgrader
  432. {
  433. public SimpleLitUpdaterV1(string oldShaderName)
  434. {
  435. if (oldShaderName == null)
  436. throw new ArgumentNullException("oldShaderName");
  437. RenameShader(oldShaderName, ShaderUtils.GetShaderPath(ShaderPathID.SimpleLit), UpgradeToSimpleLit);
  438. RenameTexture("_MainTex", "_BaseMap");
  439. RenameColor("_Color", "_BaseColor");
  440. RenameFloat("_SpecSource", "_SpecularHighlights");
  441. RenameFloat("_Shininess", "_Smoothness");
  442. }
  443. public static void UpgradeToSimpleLit(Material material)
  444. {
  445. if (material == null)
  446. throw new ArgumentNullException("material");
  447. var smoothnessSource = 1 - (int)material.GetFloat("_GlossinessSource");
  448. material.SetFloat("_SmoothnessSource", smoothnessSource);
  449. if (material.GetTexture("_SpecGlossMap") == null)
  450. {
  451. var col = material.GetColor("_SpecColor");
  452. var colBase = material.GetColor("_Color");
  453. var smoothness = material.GetFloat("_Shininess");
  454. if (material.GetFloat("_Surface") == 0)
  455. {
  456. if (smoothnessSource == 1)
  457. colBase.a = smoothness;
  458. else
  459. col.a = smoothness;
  460. material.SetColor("_BaseColor", colBase);
  461. }
  462. material.SetColor("_BaseColor", colBase);
  463. material.SetColor("_SpecColor", col);
  464. }
  465. }
  466. }
  467. internal class ParticleUpdaterV1 : MaterialUpgrader
  468. {
  469. public ParticleUpdaterV1(string shaderName)
  470. {
  471. if (shaderName == null)
  472. throw new ArgumentNullException("oldShaderName");
  473. RenameShader(shaderName, shaderName, ParticleUpgrader.UpdateSurfaceBlendModes);
  474. RenameTexture("_MainTex", "_BaseMap");
  475. RenameColor("_Color", "_BaseColor");
  476. RenameFloat("_FlipbookMode", "_FlipbookBlending");
  477. switch (ShaderUtils.GetEnumFromPath(shaderName))
  478. {
  479. case ShaderPathID.ParticlesLit:
  480. RenameFloat("_Glossiness", "_Smoothness");
  481. break;
  482. case ShaderPathID.ParticlesSimpleLit:
  483. RenameFloat("_Glossiness", "_Smoothness");
  484. break;
  485. case ShaderPathID.ParticlesUnlit:
  486. break;
  487. }
  488. }
  489. }
  490. #endregion
  491. }