Search Unity

Is switching from URP to HDRP possible?

Discussion in 'High Definition Render Pipeline' started by John_Leorid, May 31, 2020.

  1. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    Hi, while prototyping our FPS semi-open-world game we realized that we are striving for a somewhat realistic look - but we started out with the URP because, well, we had no idea how it would turn out.
    Now after 6 hours of trying to switch the render pipeline from URP to HDRP and still getting a flood of errors, I wanted to ask, if this is even possible without starting a new project from scratch.

    We have a terrain and numerous prefabs, different layers in use, the new input system setup - recreating all of them would be insane, just to change the render pipeline and to update the materials...

    Has anyone tried this yet? One of the biggest problems are the materials, I can't downgrade them to the built in renderer and therefor I can't upgrade them to HDRP, also whenever it seems to work, I get tons of

    Maximum number (256) of shader global keywords exceeded, keyword _REQUIRE_UV2 will be ignored.
    You will have to delete some shaders or make them use less keywords.
    erros followed by a
    TLS Allocator ALLOC_TEMP_THREAD, underlying allocator ALLOC_TEMP_THREAD has unfreed allocations, size 44435
    error and a bunch of
    Allocation of 4438 bytes at 0000026E80771270
    messages in the console.

    Solutions like the replacement mentioned here: https://answers.unity.com/questions/1667795/maximum-number-256-of-shader-global-keywords-excee.html
    Didn't work.

    I wrote my own script to take the textures of the existing materials to place them into the HDRP/Lit shader but it seems like there is no occlusion map or metallicMap.

    The results I got so far are stunning, especially the Glass, but with these errors, those results are worth nothing.

    So ... do you have any suggestions or solutions? Is there any other way than starting the project from scratch?
     
  2. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    I tried a lot of other things and the errors are gone, I've no idea why or how but it works now ^^
     
    Tung-Nguyen likes this.
  3. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    934
    Hi,

    Which binary and HDRP/URP version are you using?

    Regarding the link to usage of "local" keyword.

    HDRP already use "_local" postfix on keyword, so nothing you can really do more (unless you have create your own keyword?). You reach this certainly because you have multiple package? Maybe asset store package as well?

    One thing to try could be to make the conversion between URP and HDRP (so with this error message happening), then remove the URP package. Once remove you shouldn't have issue.

    There is improvement for URP to use more "_local" postfix coming (but depends which verison you use)

    >TLS Allocator ALLOC_TEMP_THREAD, underlying allocator ALLOC_TEMP_THREAD has unfreed allocations, size >44435
    Can't comment for this one, no idea.

    Hope that help.
     
  4. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    It already works flawlessly - I have no idea why but I am happy with the results.
    I just used GIT Reset hard 5 times or so, always did the same thing - Downloading the HRDP Asset, converting all URP Materials with my custom EditorScript, then deinstalling URP and ended up with errors 4 times.
    On the fifth time, I made a restart after installing HDRP and before removing URP, maybe thats why it worked? I've no idea .. but it works now, we are using it since I've posted the answer on the 31.3.2020 with no issues so far.
     
  5. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    934
    Glad you figure out a way to solve this.
    Currently the error is spread out when compiling shader. The keyword are cumulated for every shader you compile. So once you have compile them, the next time you relaunch the editor, shader aren't recompile and this is why it works.
    Loading -> compiling some shaders -> reach the limit . Close editor -> reloading, compiling remainging shader etc...
     
    John_Leorid likes this.
  6. swantonb

    swantonb

    Joined:
    Apr 10, 2018
    Posts:
    172
    can i have this custom script? im having the same issue, making the project from scratch would make me remake 1000 hours of indie work..
     
  7. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    Sure, why not? But it is very basic and just a small helper for a few common cases.
    And as always: make a bakeup before you use anything from the internet xD

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.Collections.Generic;
    4. using System.IO;
    5. using UnityEditor.Presets;
    6.  
    7. public class HDRP_MaterialUpdater : EditorWindow
    8.     {
    9.         Material mat;
    10.         Color col;
    11.  
    12.         /// <summary>
    13.         /// render mode:
    14.         /// 0 = Opaque,
    15.         /// 1 = Cutout,
    16.         /// 2 = Fade,
    17.         /// 3 = Transparent,
    18.         /// 4 = Additive,
    19.         /// 5 = Subtractive,
    20.         /// 6 = Modulate
    21.         /// </summary>
    22.         float mode;
    23.  
    24.         /// <summary>
    25.         /// color mode:
    26.         /// 0 = Multiply,
    27.         /// 1 = Additive,
    28.         /// 2 = Subtractive,
    29.         /// 3 = Overlay,
    30.         /// 4 = Color,
    31.         /// 5 = Difference
    32.         /// </summary>
    33.         float cMode;
    34.  
    35.         Texture baseMap;
    36.         Texture metalMap;
    37.         Texture specularMap;
    38.         Texture normalMap;
    39.         Texture occlusionMap;
    40.         Texture emissionMap;
    41.  
    42.         [MenuItem("Tools/HDRP/MaterialUpdater")]
    43.         static void UpdateHDRPMaterials()
    44.         {
    45.             HDRP_MaterialUpdater window = GetWindow<HDRP_MaterialUpdater>();
    46.             window.Show();
    47.         }
    48.  
    49.         private void OnGUI()
    50.         {
    51.             mat = (Material)EditorGUILayout.ObjectField("Material",
    52.                 mat, typeof(Material), false);
    53.             baseMap = (Texture)EditorGUILayout.ObjectField("baseMap",
    54.                 baseMap, typeof(Texture), false);
    55.             metalMap = (Texture)EditorGUILayout.ObjectField("metalMap",
    56.                 metalMap, typeof(Texture), false);
    57.             specularMap = (Texture)EditorGUILayout.ObjectField("specularMap", specularMap, typeof(Texture), false);
    58.             normalMap = (Texture)EditorGUILayout.ObjectField("normalMap",
    59.                 normalMap, typeof(Texture), false);
    60.             occlusionMap = (Texture)EditorGUILayout.ObjectField("occlusionMap",
    61.                 occlusionMap, typeof(Texture), false);
    62.             emissionMap = (Texture)EditorGUILayout.ObjectField("emissionMap",
    63.                 emissionMap, typeof(Texture), false);
    64.  
    65.             string shaderName = "No Material Found";
    66.  
    67.             if (mat)
    68.             {
    69.                 shaderName = mat.shader.ToString();
    70.             }
    71.  
    72.             GUILayout.TextField(shaderName);
    73.             EditorGUILayout.FloatField(mode);
    74.             EditorGUILayout.FloatField(cMode);
    75.  
    76.             if (GUILayout.Button("Copy Textures"))
    77.             {
    78.                 if (!mat)
    79.                 {
    80.                     if (!Selection.activeObject)
    81.                     {
    82.                         return;
    83.                     }
    84.                     if (!(Selection.activeObject is Material))
    85.                     {
    86.                         return;
    87.                     }
    88.  
    89.                     mat = Selection.activeObject as Material;
    90.                     shaderName = mat.shader.ToString();
    91.                 }
    92.  
    93.                 if (shaderName.StartsWith("Universal"))
    94.                 {
    95.                     col = Color.white;
    96.                     mode = -1;
    97.                     cMode = -1;
    98.                     baseMap = mat.GetTexture("_BaseMap");
    99.                     metalMap = mat.GetTexture("_MetallicGlossMap");
    100.                     specularMap = mat.GetTexture("_SpecGlossMap");
    101.                     normalMap = mat.GetTexture("_BumpMap");
    102.                     occlusionMap = mat.GetTexture("_OcclusionMap");
    103.                     emissionMap = mat.GetTexture("_EmissionMap");
    104.                 }
    105.                 else if (shaderName.Contains("Standard Surface"))
    106.                 {
    107.                     col = mat.GetColor("_Color");
    108.                     mode = mat.GetFloat("_Mode");
    109.                     cMode = -1;
    110.                     baseMap = mat.GetTexture("_MainTex");
    111.                     normalMap = mat.GetTexture("_BumpMap");
    112.                     emissionMap = mat.GetTexture("_EmissionMap");
    113.                 }
    114.                 else if (shaderName.Contains("Standard Unlit"))
    115.                 {
    116.                     col = mat.GetColor("_Color");
    117.                     mode = mat.GetFloat("_Mode");
    118.                     cMode = mat.GetFloat("_ColorMode");
    119.                     baseMap = mat.GetTexture("_MainTex");
    120.                     normalMap = mat.GetTexture("_BumpMap");
    121.                     emissionMap = mat.GetTexture("_EmissionMap");
    122.                 }
    123.                 else if (shaderName.Contains("Particles/Additive"))
    124.                 {
    125.                     mode = -1;
    126.                     cMode = -1;
    127.                     col = mat.GetColor("_TintColor");
    128.                     baseMap = mat.GetTexture("_MainTex");
    129.                 }
    130.             }
    131.             if (GUILayout.Button("Switch Shader"))
    132.             {
    133.                 Undo.RecordObject(mat, "Update RP");
    134.  
    135.                 mat.shader = Shader.Find("HDRP/Lit");
    136.             }
    137.             if (GUILayout.Button("Paste Textures"))
    138.             {
    139.                 Undo.RecordObject(mat, "Update RP");
    140.  
    141.  
    142.                 //mat.SetFloat("_SurfaceType", ) // 0 = opaque, 1 = transparent
    143.                 //mat.SetFloat("_BlendMode", ) // 0 = Alpha, 1 = additive, 2 = premultiply
    144.                 //mat.SetFloat("_SupportDecals", 0);
    145.                 //mat.SetFloat("_ReceivesSSR", 0);
    146.                 //mat.SetFloat("_AlphaCutoffEnable", )
    147.                 mat.SetColor("_BaseColor", col);
    148.                 mat.SetTexture("_BaseColorMap", baseMap);
    149.                 mat.SetTexture("_NormalMap", normalMap);
    150.                 mat.SetTexture("_EmissiveColorMap", emissionMap);
    151.             }
    152.         }
    153.     }
    154.  
    155.     public class HDRP_Utilities : Editor
    156.     {
    157.         [MenuItem("Tools/HDRP/Log Shader")]
    158.         static void LogShader()
    159.         {
    160.             Debug.Log((Selection.activeObject as Material).shader);
    161.         }
    162.  
    163.         [MenuItem("Tools/HDRP/Switch RP")]
    164.         static void SwitchRP()
    165.         {
    166.             string[] matGUIDs = AssetDatabase.FindAssets("t:Material");
    167.  
    168.             foreach (string s in matGUIDs)
    169.             {
    170.                 string path = AssetDatabase.GUIDToAssetPath(s);
    171.                 Material mat = AssetDatabase.LoadAssetAtPath<Material>(path);
    172.                 if (mat)
    173.                 {
    174.                     string matShaderName = mat.shader.ToString();
    175.                     if (matShaderName.StartsWith("Universal"))
    176.                     {
    177.                         Debug.Log(matShaderName, mat);
    178.                     }
    179.                     if (mat.shader ==
    180.                         Shader.Find("Universal Render Pipeline/Simple Lit"))
    181.                     {
    182.                         SwitchForMatSimpleLit(mat);
    183.                     }
    184.                     if (mat.shader == Shader.Find("Universal Render Pipeline/Lit"))
    185.                     {
    186.                         SwitchForMatLit(mat);
    187.                     }
    188.                 }
    189.             }
    190.         }
    191.  
    192.  
    193.  
    194.         static void SwitchForMatSimpleLit(Material mat)
    195.         {
    196.             Undo.RecordObject(mat, "Update RP");
    197.  
    198.             Texture baseMap = mat.GetTexture("_BaseMap");
    199.             Texture specularMap = mat.GetTexture("_SpecGlossMap");
    200.             Texture normalMap = mat.GetTexture("_BumpMap");
    201.             Texture emissionMap = mat.GetTexture("_EmissionMap");
    202.  
    203.             mat.shader = Shader.Find("HDRP/Lit");
    204.  
    205.             mat.SetTexture("_BaseColorMap", baseMap);
    206.             mat.SetTexture("_NormalMap", normalMap);
    207.             mat.SetTexture("_EmissiveColorMap", emissionMap);
    208.         }
    209.         static void SwitchForMatLit(Material mat)
    210.         {
    211.             Undo.RecordObject(mat, "Update RP");
    212.  
    213.             Texture baseMap = mat.GetTexture("_BaseMap");
    214.             Texture metalMap = mat.GetTexture("_MetallicGlossMap");
    215.             Texture specularMap = mat.GetTexture("_SpecGlossMap");
    216.             Texture normalMap = mat.GetTexture("_BumpMap");
    217.             Texture occlusionMap = mat.GetTexture("_OcclusionMap");
    218.             Texture emissionMap = mat.GetTexture("_EmissionMap");
    219.  
    220.             Texture gloss = metalMap != null ? metalMap : specularMap;
    221.  
    222.             mat.shader = Shader.Find("HDRP/Lit");
    223.  
    224.             mat.SetTexture("_BaseColorMap", baseMap);
    225.             mat.SetTexture("_NormalMap", normalMap);
    226.             mat.SetTexture("_EmissiveColorMap", emissionMap);
    227.         }
    228.  
    229.     }
    230.  

    I also used the Mask Map Packer:
    https://www.reddit.com/r/Unity3D/comments/9kz8kd/updated_hdrp_mask_map_packer/
     
    atincuzun, Blarp and EnricoBC like this.
  8. swantonb

    swantonb

    Joined:
    Apr 10, 2018
    Posts:
    172
    Yes i do have collab backup! Thank you very much bro <3
     
  9. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,363
    It is possible, but requires a huge amount of work. For me was easier porting from URP to HDRP my image effects for example than from Standard. Shaders also were bit more compatible (though still HDRP and URP are radically different and requires huge effort to convert anything custom made for them or between them)
     
  10. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    Shadergraphs can be copied and pasted (you just have to reassign all blackboard-properties), everything else? Well, yes - lots and lots of work, especially understanding HDRP and finding the correct settings which are shattered across the project settings, camera/light/mesh renderer component as well as the Lightning-Tab.
     
  11. Camarent

    Camarent

    Joined:
    Feb 19, 2014
    Posts:
    168