Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved All is broken with URP on 2022.2.0f1 unity

Discussion in 'Universal Render Pipeline' started by Tony_Max, Dec 10, 2022.

  1. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    354
    I was upgrading project from 2021.3.13f1 + entities 0.51 to 2022.2.0b16 + entities 1.0.0-exp.12. During those transitions everything was fine.
    Then I've upgraded project to unity 2022.2.0f1 + entities 1.0.0-pre.15. After that step nothing rendered in editor nor in playmode.

    I've tried to downgrade back to 2021.3.13f1 (not revert from vcs, just open project win lower editor version) then some sprites gets rendered but at the same position with same other properties (like scale, so all sprites rendered at the same place with same size / color / etc).

    There is an issue where unlit gameobjects doesn't get rendered, but there is no 2022.2.0f1.

    Maybe there is something broken with URP updates.

    I use custom rendering system which calls
    Graphics.DrawMeshInstancedProcedural
    . Shader code below
    Code (CSharp):
    1. Shader "Universal Render Pipeline/2D/SimpleSpriteShader"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex("_MainTex", 2D) = "white" {}
    6.     }
    7.  
    8.     HLSLINCLUDE
    9.     #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    10.  
    11.     CBUFFER_START(UnityPerMaterial)
    12.     CBUFFER_END
    13.     ENDHLSL
    14.  
    15.     SubShader
    16.     {
    17.         Tags {"Queue" = "AlphaTest" "RenderType" = "TransparentCutout" "RenderPipeline" = "UniversalPipeline" }
    18.  
    19.         Pass
    20.         {
    21.             Tags { "LightMode" = "UniversalForward" "Queue" = "AlphaTest" "RenderType" = "TransparentCutout"}
    22.             ZTest LEqual    //Default
    23.             // ZTest Less | Greater | GEqual | Equal | NotEqual | Always
    24.             ZWrite On       //Default
    25.             Cull Off
    26.  
    27.             HLSLPROGRAM
    28.             #pragma vertex UnlitVertex
    29.             #pragma fragment UnlitFragment
    30.  
    31.             #pragma target 4.5
    32.             #pragma exclude_renderers gles gles3 glcore
    33.             #pragma multi_compile_instancing
    34.             #pragma instancing_options procedural:setup
    35.  
    36.             struct Attributes
    37.             {
    38.                 float3 positionOS   : POSITION;
    39.                 float2 uv            : TEXCOORD0;
    40.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    41.             };
    42.  
    43.             struct Varyings
    44.             {
    45.                 float4  positionCS        : SV_POSITION;
    46.                 float2    uv                : TEXCOORD0;
    47.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    48.             };
    49.  
    50.             TEXTURE2D(_MainTex);
    51.             SAMPLER(sampler_MainTex);
    52.  
    53. #if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED)
    54.             StructuredBuffer<int> _propertyPointers;
    55.             StructuredBuffer<float4> _mainTexSTBuffer;
    56.             StructuredBuffer<float> _sortingValueBuffer;
    57.             StructuredBuffer<float2> _positionBuffer;
    58.             StructuredBuffer<float2> _pivotBuffer;
    59.             StructuredBuffer<float2> _heightWidthBuffer;
    60. #endif
    61.  
    62.             void setup()
    63.             {
    64. #if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED)
    65.                 int propertyIndex = _propertyPointers[unity_InstanceID];
    66.                 float2 scale = _heightWidthBuffer[propertyIndex];
    67.                 float2 renderPos = _positionBuffer[propertyIndex] - scale * _pivotBuffer[propertyIndex];
    68.                 unity_ObjectToWorld = half4x4
    69.                 (
    70.                     scale.x, 0, 0, renderPos.x,
    71.                     0, scale.y, 0, renderPos.y,
    72.                     0, 0, 1, 0,
    73.                     0, 0, 0, 1
    74.                 );
    75. #endif
    76.             }
    77.  
    78.             float2 TilingAndOffset(float2 UV, float2 Tiling, float2 Offset)
    79.             {
    80.                 return UV * Tiling + Offset;
    81.             }
    82.             Varyings UnlitVertex(Attributes attributes, uint instanceID : SV_InstanceID)
    83.             {
    84.                 Varyings varyings = (Varyings)0;
    85.  
    86. #if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED)
    87.                 int propertyIndex = _propertyPointers[instanceID];
    88.                 float4 mainTexST = _mainTexSTBuffer[propertyIndex];
    89.                 float sortingValue = _sortingValueBuffer[propertyIndex];
    90. #else
    91.                 float4 mainTexST = float4(1, 1, 0, 0);
    92.                 float sortingValue = 0;
    93. #endif
    94.                 varyings.positionCS = TransformObjectToHClip(attributes.positionOS);
    95.                 varyings.positionCS.z = sortingValue;
    96.                 varyings.uv = TilingAndOffset(attributes.uv, mainTexST.xy, mainTexST.zw);
    97.  
    98.                 return varyings;
    99.             }
    100.  
    101.             half4 UnlitFragment(Varyings varyings, uint instanceID : SV_InstanceID) : SV_Target
    102.             {
    103.                 half4 texColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, varyings.uv);
    104.                 clip(texColor.w - 0.5);
    105.                 return texColor;
    106.             }
    107.             ENDHLSL
    108.         }
    109.     }
    110.  
    111.     Fallback "Sprites/Default"
    112. }
    113.  
     
    Last edited: Dec 11, 2022
    Laicasaane and charleshendry like this.
  2. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    354
    I've noticed that after upgrading to unity 2022.2.0f1 URP renderer asset looks like this (attached) in inspector upload_2022-12-11_11-48-53.png
    And after trying create new asset I get
    Exception: Cannot load. Path Packages/com.unity.render-pipelines.universal/Runtime/Data/XRSystemData.asset is correct but AssetDatabase cannot load now.


    So the problem also in that I can't use my URP render asset after migrating to new version
     
  3. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    354
    When I try to open Render Pipeline Converter it throws
    NullReferenceException: Object reference not set to an instance of an object
    UnityEditor.Rendering.Universal.RenderPipelineConvertersEditor.CreateGUI () (at Library/PackageCache/com.unity.render-pipelines.universal@14.0.4/Editor/Converter/RenderPipelineConvertersEditor.cs:246)

    Window is empty btw
     
    Last edited: Dec 11, 2022
  4. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    354
    With fresh project all works fine. So maybe cause is about some corrupted project settings
     
    Last edited: Dec 12, 2022
  5. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    354
    After reimporting whole project issue with assets gone.

    Though all sprites rendered with the same default matrix with zero position and one scale.
    • Rendering performed with
      Graphics.DrawMeshInstancedProcedural
    • StructuredBuffer
      value comes through
      MaterialPropertyBlock.SetBuffer

    • I've checked that shader obtain instanced properties properly, so problem is just in wrong matrix. Instancing also works, because #if defined(<instancing directives>) passes, so code inside happens.
    Full shader code attached at the first reply in this thead. But it seems like this section completely ignored now
    Code (hlsl):
    1. #pragma instancing_options procedural:setup
    2.  
    3. void setup()
    4. {
    5. #if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED)
    6.    // ...
    7.    unity_ObjectToWorld = half4x4
    8.    (
    9.       scale.x, 0, 0, renderPos.x,
    10.       0, scale.y, 0, renderPos.y,
    11.       0, 0, 1, 0,
    12.       0, 0, 0, 1
    13.    );
    14. #endif
    15. }

    How can I check this code section performed? Or what can be wrong with this section? Again all worked before updating to 2022.2.0f1

    UPD#0:
    Also I've noticed that in FrameDebugger there is no
    _positionBuffer
    /
    _heightWidthBuffer
    /
    _pivotBuffer
    in buffer list, which means they are never used. So
    setup()
    function never called, even if it declared with
    #pragma instancing_options procedural:setup
    . If I try to remove setup function then shader compiler throws error that #pragma should have such function.
    upload_2022-12-12_12-9-38.png
    I need somebody who knows what is going on! please

    UPD#1: I've checked compiled shader code and it contains no
    _positionBuffer
    /
    _heightWidthBuffer
    /
    _pivotBuffer
    buffers nor
    setup()
    function
     
    Last edited: Dec 12, 2022
  6. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    354
    Things getting weirder :confused:. Unity (2022.2.0f1) was in passive mode some time. Then I've activated it and saw that sprites was rendered at proper position with proper scale but all of them was black. After entering playmode unity just immediately stacked.

    UPD#0: Same happened once after reopening project (can't reproduce). Compiled shader code was different too, it was including all necessary buffers.

    UPD#1: With reverted changes to project with unity 2022.2.0b16 rendering goes well with all same assets. Project has URP 14.0.3 installed

    UPD#2: After another one step by step bypassing through all upgrade stages all magically works fine. omg.
     
    Last edited: Dec 13, 2022
  7. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,465
    If you are on URP 12 I would recommend not upgrading beyond that, everything breaks from URP 13+ if you don't start from scratch.
     
    ElliotB likes this.