Search Unity

Question Topographic Scanner Effect In URP

Discussion in 'Universal Render Pipeline' started by lingdu_y, Aug 3, 2021.

  1. lingdu_y

    lingdu_y

    Joined:
    Apr 15, 2021
    Posts:
    11
    I have seen a really cool effect in youtube, the Link is here:https://www.youtube.com/results?search_query=urp+Topographic+Scanner

    But it is under build-in pipeline. So I try to transform this code into URP project , and I meet some tricklish questions. In this tutorial, he use GL to draw a QUADs to record relative location between camera position and screen position like this:
    upload_2021-8-3_14-59-2.png
    And I use this in scriptablepass. In framedebugger it shows <unknown scope>:
    upload_2021-8-3_14-59-47.png
    it is a wrong render order, I really have no idea how to solve this. thanks everyone for help.
    Code (CSharp):
    1. private void RaycastCornerBlit(CommandBuffer commandBuffer)
    2.         {
    3.             // Compute Frustum Corners
    4.             float camFar = m_Camera.farClipPlane;
    5.             float camFov = m_Camera.fieldOfView;
    6.             float camAspect = m_Camera.aspect;
    7.  
    8.             float fovWHalf = camFov * 0.5f;
    9.  
    10.             Vector3 toRight = m_Camera.transform.right * Mathf.Tan(fovWHalf * Mathf.Deg2Rad) *
    11.                               camAspect;
    12.             Vector3 toTop = m_Camera.transform.up * Mathf.Tan(fovWHalf * Mathf.Deg2Rad);
    13.  
    14.             Vector3 topLeft = (m_Camera.transform.forward - toRight + toTop);
    15.             float camScale = topLeft.magnitude * camFar;
    16.  
    17.             topLeft.Normalize();
    18.             topLeft *= camScale;
    19.  
    20.             Vector3 topRight = (m_Camera.transform.forward + toRight + toTop);
    21.             topRight.Normalize();
    22.             topRight *= camScale;
    23.  
    24.             Vector3 bottomRight = (m_Camera.transform.forward + toRight - toTop);
    25.             bottomRight.Normalize();
    26.             bottomRight *= camScale;
    27.  
    28.             Vector3 bottomLeft = (m_Camera.transform.forward - toRight - toTop);
    29.             bottomLeft.Normalize();
    30.             bottomLeft *= camScale;
    31.  
    32.             // ----------------------------------------
    33.             GL.PushMatrix();
    34.             GL.LoadOrtho();
    35.  
    36.             m_Material.SetPass(0);
    37.  
    38.             GL.Begin(GL.QUADS);
    39.  
    40.             GL.MultiTexCoord2(0, 0.0f, 0.0f);
    41.             GL.MultiTexCoord(1, bottomLeft);
    42.             GL.Vertex3(0.0f, 0.0f, 0.0f);
    43.  
    44.             GL.MultiTexCoord2(0, 1.0f, 0.0f);
    45.             GL.MultiTexCoord(1, bottomRight);
    46.             GL.Vertex3(1.0f, 0.0f, 0.0f);
    47.  
    48.             GL.MultiTexCoord2(0, 1.0f, 1.0f);
    49.             GL.MultiTexCoord(1, topRight);
    50.             GL.Vertex3(1.0f, 1.0f, 0.0f);
    51.  
    52.             GL.MultiTexCoord2(0, 0.0f, 1.0f);
    53.             GL.MultiTexCoord(1, topLeft);
    54.             GL.Vertex3(0.0f, 1.0f, 0.0f);
    55.  
    56.             GL.End();
    57.             GL.PopMatrix();
    58.             // ----------------------------------------
    59.            
    60.             Blit(commandBuffer, source, m_TempRenderTargetHandler.Identifier(), m_Material);
    61.             Blit(commandBuffer, m_TempRenderTargetHandler.Identifier(), source, m_Material);
    62.         }