Search Unity

Question Shader in UI flips upside down in camera render type overlay

Discussion in 'Universal Render Pipeline' started by BKubisova1, Oct 12, 2022.

  1. BKubisova1

    BKubisova1

    Joined:
    Feb 24, 2022
    Posts:
    1
    Hello, I am making a 3D game in URP (unity version 2021.2.7) and I have a GameObject that loads/unloads levels while a transition is playing. Transition is like a water wave, comes from the bottom and goes up, leaves by going up more. The transition is made in Shader Graph and I have set Image component to use this material. Then I use a script to interpolate a variable of this water wave I have made to scroll always up (I haven't figured out how to animate it so I did it by linear interpolation).

    It works just fine, besides in my main level scene. In this scene, I am using multiple cameras rendering different parts of the level, because I need to have world space UI and some particles really close to each other. For some reason, when I set the render camera for my transition canvas to Transition camera (render type overlay), it flips upside down. With render type base, it works perfectly. I have no idea what's happening and I can't find any answers online, this is my first post on forums because I am really hopeless. Thank you in advance.

    For clarification: the wished result is in transition camera, game view has the upside down
    image (8).png image (7).png image (6).png image (5).png image (3).png
     
  2. DWO_

    DWO_

    Joined:
    Feb 19, 2014
    Posts:
    26
    I know this is late but I was having a similar problem when writing a UI Shader to display a texture onto a UI Image component. When the canvas render mode was "Screen Space - Camera" with my main camera set the image was correct, but when set to "Screen Space - Overlay" the same image would be flipped upside down. (I'm using URP).

    On the unity page "Writing shaders for different graphics APIs", under Rendering in UV space, it mentions checking to see if _ProjectionParams.x is 1 or -1. The page on built-in shader variables says:
    So in my shader, before sampling my texture I simply flip the UV's y-axis depending on if the projection matrix is flipped:
    Code (CSharp):
    1. if (_ProjectionParams.x == 1)
    2. {
    3.     uv.y = 1 - uv.y;
    4. }
    5. return SAMPLE_TEXTURE2D(_texture , sampler_LinearClamp, uv);
    You said you were using shader graph for this, maybe you could use the Camera Node to check for a flipped projection matrix? It says ZBufferSign = _ProjectionParams.x in the generated code section.

    Hope this helps anyone that may stumble across this problem.