Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Resolved Enabling Post-processing on camera has weird side-effects

Discussion in 'Universal Render Pipeline' started by iSinner, Jul 14, 2021.

  1. iSinner

    iSinner

    Joined:
    Dec 5, 2013
    Posts:
    174
    I'm in the process of upgrading from built-in render pipeline to URP.

    I had some drawing made via GL class in OnPostRender, but since URP doesn't call this method, i used
    RenderPipelineManager.endCameraRendering
    event and called my OnPostRender(which i renamed to OnRender) method through it.

    This is how it looks:



    OnPostRender was renamed to OnRender.

    In OnRender, some gizmos are drawn, similar to unity's move gizmos.
    Now the issue is as follows, i didn't change anything on how things are done in OnRender, but here are the results with and w/o the Post Processing checkbox checked on the camera.

    Not checked:

    In the game view, the gizmos is not drawn at the model, where it should be(but in the scene view it is on the model). Notice the view-projection matrix doesn't differ between the above and below screens.

    With checkbox:

    Now the gizmos is drawn at the correct position in both views. The view-projection matrix is the same.

    From the frame debugger it can be seen that there are 2 additional profiling scopes, one at the start('ColorGradingLUT') and one at the end ('Render PostProcessing Effects'). This somehow changes the position of the dawn gizmos which is drawn via GL class.

    Here is the shader used for drawing the gizmos.

    Code (CSharp):
    1. Shader "Custom/Lines"
    2. {
    3.     SubShader
    4.     {
    5.         Pass
    6.         {
    7.             Blend SrcAlpha OneMinusSrcAlpha
    8.             ZWrite Off
    9.             ZTest Always
    10.             Cull Off
    11.             Fog { Mode Off }
    12.  
    13.             BindChannels
    14.             {
    15.               Bind "vertex", vertex
    16.               Bind "color", color
    17.             }
    18.         }
    19.     }
    20. }
    Since the view-projection matrix is not changed, then, i assume, the model matrix is different, but how and why?
    The model, view and projection matrices are not changed in the OnRender.
    The script that draws the gizmos is on the camera gameobject.

    Does anybody know what is going on here?

    Also, when the post processing checkbox is not checked, why is the drawn gizmos in the scene view on the model, while in the game view it's in a different place?

    Unity version: 2020.3.11.f1
    URP version: 10.5.1

    P.S. If any additional information is needed, let me know.
     
    Last edited: Jul 14, 2021
  2. iSinner

    iSinner

    Joined:
    Dec 5, 2013
    Posts:
    174
    I figured it out.

    Doing this:
    Code (CSharp):
    1.  private void RenderPipelineManager_endCameraRendering(ScriptableRenderContext context, Camera cam)
    2.         {
    3.             GL.PushMatrix();
    4.             GL.MultMatrix(Matrix4x4.identity);
    5.             OnRender();
    6.             GL.PopMatrix();
    7.         }
    solved the issue.

    Which means that the post processing passes set the model matrix to identity and leave it at that even after finishing.

    I'm not sure if this is intended behavior or not from the unity's part. If anyone from unity is reading this and it's not the intended behavior, consider noting a bug in the backlog.