All is broken with URP on 2022.2.0f1 unity

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

Shader "Universal Render Pipeline/2D/SimpleSpriteShader"
{
    Properties
    {
        _MainTex("_MainTex", 2D) = "white" {}
    }

    HLSLINCLUDE
    #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

    CBUFFER_START(UnityPerMaterial)
    CBUFFER_END
    ENDHLSL

    SubShader
    {
        Tags {"Queue" = "AlphaTest" "RenderType" = "TransparentCutout" "RenderPipeline" = "UniversalPipeline" }

        Pass
        {
            Tags { "LightMode" = "UniversalForward" "Queue" = "AlphaTest" "RenderType" = "TransparentCutout"}
            ZTest LEqual    //Default
            // ZTest Less | Greater | GEqual | Equal | NotEqual | Always
            ZWrite On       //Default
            Cull Off

            HLSLPROGRAM
            #pragma vertex UnlitVertex
            #pragma fragment UnlitFragment

            #pragma target 4.5
            #pragma exclude_renderers gles gles3 glcore
            #pragma multi_compile_instancing
            #pragma instancing_options procedural:setup

            struct Attributes
            {
                float3 positionOS   : POSITION;
                float2 uv            : TEXCOORD0;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct Varyings
            {
                float4  positionCS        : SV_POSITION;
                float2    uv                : TEXCOORD0;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            TEXTURE2D(_MainTex);
            SAMPLER(sampler_MainTex);

#if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED)
            StructuredBuffer<int> _propertyPointers;
            StructuredBuffer<float4> _mainTexSTBuffer;
            StructuredBuffer<float> _sortingValueBuffer;
            StructuredBuffer<float2> _positionBuffer;
            StructuredBuffer<float2> _pivotBuffer;
            StructuredBuffer<float2> _heightWidthBuffer;
#endif

            void setup()
            {
#if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED)
                int propertyIndex = _propertyPointers[unity_InstanceID];
                float2 scale = _heightWidthBuffer[propertyIndex];
                float2 renderPos = _positionBuffer[propertyIndex] - scale * _pivotBuffer[propertyIndex];
                unity_ObjectToWorld = half4x4
                (
                    scale.x, 0, 0, renderPos.x,
                    0, scale.y, 0, renderPos.y,
                    0, 0, 1, 0,
                    0, 0, 0, 1
                );
#endif
            }

            float2 TilingAndOffset(float2 UV, float2 Tiling, float2 Offset)
            {
                return UV * Tiling + Offset;
            }
            Varyings UnlitVertex(Attributes attributes, uint instanceID : SV_InstanceID)
            {
                Varyings varyings = (Varyings)0;

#if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED)
                int propertyIndex = _propertyPointers[instanceID];
                float4 mainTexST = _mainTexSTBuffer[propertyIndex];
                float sortingValue = _sortingValueBuffer[propertyIndex];
#else
                float4 mainTexST = float4(1, 1, 0, 0);
                float sortingValue = 0;
#endif
                varyings.positionCS = TransformObjectToHClip(attributes.positionOS);
                varyings.positionCS.z = sortingValue;
                varyings.uv = TilingAndOffset(attributes.uv, mainTexST.xy, mainTexST.zw);

                return varyings;
            }

            half4 UnlitFragment(Varyings varyings, uint instanceID : SV_InstanceID) : SV_Target
            {
                half4 texColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, varyings.uv);
                clip(texColor.w - 0.5);
                return texColor;
            }
            ENDHLSL
        }
    }

    Fallback "Sprites/Default"
}
2 Likes

I’ve noticed that after upgrading to unity 2022.2.0f1 URP renderer asset looks like this (attached) in inspector8651946--1164354--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

When I try to open Render Pipeline Converter it throws

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

With fresh project all works fine. So maybe cause is about some corrupted project settings

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() 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

#pragma instancing_options procedural:setup

void setup()
{
#if defined(UNITY_INSTANCING_ENABLED) || defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) || defined(UNITY_STEREO_INSTANCING_ENABLED)
   // ...
   unity_ObjectToWorld = half4x4
   (
      scale.x, 0, 0, renderPos.x,
      0, scale.y, 0, renderPos.y,
      0, 0, 1, 0,
      0, 0, 0, 1
   );
#endif
}

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.
8653800--1164837--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

Things getting weirder :face_with_spiral_eyes:. 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.

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.

1 Like