Overlay cameras have incorrect _ProjectionParams

Hi,

The manual describes the _ProjectionParams variable as:

This is broken on URP 2021.3.16f1 and I estimate it has been broken for around 6 months (I have only just now found this was the cause of a separate bug I have been tracking for some time). It seems fixed on

This bug affects built-in URP functions (e.g. ComputeScreenPos(uv) - although I see that one is now marked deprecated).

Minimal example to reproduce:

  • Make a simple scene: One base camera, one overlay camera.
  • Add a sphere to the scene.
  • Apply the below shader to the scene.
Shader "Test/OverlayProjectionMatrix"
{
    Properties
    { }

    SubShader
    {
        Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" }
        Pass
        {
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"           

            struct Attributes
            {
        float4 positionOS   : POSITION;
    };

    struct Varyings
    {
        float4 positionHCS  : SV_POSITION;
    };

    Varyings vert(Attributes IN)
    {
        Varyings OUT;
        OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
        return OUT;
    }
   
    half4 frag() : SV_Target
    {
        return half4(0.5 + 0.5 * _ProjectionParams.x, 1, 0, 1);
    }
    ENDHLSL
    }
    }
}

Expected output:
Both spheres are the same color.

Actual output:
For DX11 (only one I tested it on) the spheres are different if Overlay or Base camera is doing the rendering:

Cheers,
Elliot


Struggle to replicate
Now, this was where my report was going to end. I opened up a new blank project to make a minimal project for a bug report submission, on exactly the same Unity version, with exactly the same shader, and found this:
8696091--1173612--upload_2022-12-31_13-52-5.png

What on earth? It works now?


After comparing all of the properties, I found that the bug only occurs for an Overlay camera with Post Processing disabled. If Post Processing is enabled, _ProjectionParams appears correctly set. There is no GlobalVolume in my scene.

As an aside, it feels like URP has been particularly bad with quality control lately, and I’m seeing a lot more bugs and unexpected behavior. Things were good around URP11, but since 13 it feels like it has gone completely off the rails. Is URP considered production ready at the moment? Is this going to be a particularly bumpy period until the fabled ‘reunification of the SRPs’ occurs?

1 Like

Bug report IN-27401

This bug also affects ShaderGraph shaders using the screen position node, which compiles down to:

        output.ScreenPosition = ComputeScreenPos(TransformWorldToHClip(input.positionWS), _ProjectionParams.x);

I wonder if this also accounts for an incorrect ray from ScreenPointToRay?

You can see in the Game Camera window that the actual camera is very narrow (this is a portrait-mode mobile game), but in the scene view, it’s drawing a wide aspect ratio frustum. I’ve clicked on the screen near the lower right circle, but the resulting ray through the mouse position is pointing way the heck off to the side, making it impossible for me to tell which lane was clicked on.

Possibly, are you sure its not just drawing a frustum with the same aspect ratio as your scene tab? Anyway, afaik the bug was never fixed