Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

GL.Draw in HDRP

Discussion in 'High Definition Render Pipeline' started by TilmiteinemL, Apr 1, 2020.

  1. TilmiteinemL

    TilmiteinemL

    Joined:
    Sep 17, 2018
    Posts:
    5
    In URP I can use GL.Draw methods like seen in the example with no problems. Anyone knows if HDRP will support it too?

    Code (CSharp):
    1.         void DrawLines(List<Vector3> lines, Color color)
    2.         {
    3.             if (lines.Count == 0) return;
    4.  
    5.             GL.Begin(GL.LINES);
    6.             GL.Color(color);
    7.  
    8.             for (int i = 0; i < lines.Count; i += 2) {
    9.                 GL.Vertex(lines[i]);
    10.                 GL.Vertex(lines[i + 1]);
    11.             }
    12.  
    13.             GL.End();
    14.         }
     
    Last edited: Apr 1, 2020
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi,
    Not exactly an answer (I guess only Unity can answer) but maybe you could work around this problem, like using Visual Effect Graph and then render lines with it? Pass your data to it, render it with VEG and done. But of course it's much more cumbersome setup than just using GL.Draw... But as an added bonus you could use all the goodies it has to offer.
     
  3. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    936
    Hi, this couldn't work with HDRP (Also I am surprise it work with URP :) ). SRP in general use command buffer API, so everything is render through the command buffer. GL.vertex are immediate call, so they aren't supported.
     
  4. wumeng2019

    wumeng2019

    Joined:
    Jul 11, 2019
    Posts:
    3
    any other alternatives?
     
  5. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    936
    Fill vertex and index buffer of a mesh.
     
  6. xzodia

    xzodia

    Joined:
    Jan 24, 2013
    Posts:
    50
    A little late, but I had the same problem just now and solved it like this:

    Code (CSharp):
    1.  
    2.         protected void OnEnable()
    3.         {
    4. #if UNITY_2017_1_OR_NEWER
    5.             if (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset != null)
    6.                 UnityEngine.Rendering.RenderPipelineManager.endCameraRendering += endCameraRendering;
    7.             else
    8. #endif
    9.             Camera.onPostRender += OnCameraRender;
    10.         }
    11.  
    12.         protected void OnDisable()
    13.         {
    14. #if UNITY_2017_1_OR_NEWER
    15.             if (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset != null)
    16.                 UnityEngine.Rendering.RenderPipelineManager.endCameraRendering -= endCameraRendering;
    17.                
    18.             else
    19. #endif
    20.             Camera.onPostRender -= OnCameraRender;
    21.         }
    22.  
    23. #if UNITY_2017_1_OR_NEWER
    24.         void endCameraRendering(UnityEngine.Rendering.ScriptableRenderContext src, Camera camera)
    25.         {
    26.             if (CheckFilter(camera))
    27.                 DrawLines();
    28.         }
    29. #endif
    30.  
    31.         protected void OnCameraRender(Camera camera)
    32.         {
    33.             if (CheckFilter(camera))
    34.                 DrawLines();
    35.         }
    36.  
    37.         bool CheckFilter(Camera camera)
    38.         {
    39.             return (camera.cullingMask & (1 << gameObject.layer)) != 0;
    40.         }
    41.  
     
  7. Pavel_D

    Pavel_D

    Joined:
    Nov 17, 2013
    Posts:
    14
    In Unity 2020.2 with HDRP 10.2.2 I am just update the lines OnEnable/OnDisable UnityEngine.Rendering.RenderPipelineManager.endFrameRendering += RenderPipelineManager_endFrameRendering;

    And its working), may be i have more than one camera (MainCamera tag)
     
    SAM-tak and florianBrn like this.
  8. thephox1982

    thephox1982

    Joined:
    Jan 21, 2022
    Posts:
    20
    To fix this issue with HDRP not rendering GL Lines I spent a good three hours found a solution which was either outdated or broken and adapted it until I found the solution that worked. I personally am using Unity 2021.2 so this may not work for your version but something similar should do the trick.

    Code (CSharp):
    1. using UnityEngine.Rendering;
    2.  
    3. void Start(){
    4.     RenderPipelineManager.endContextRendering += OnEndContextRendering;
    5.   }
    6.  
    7.   void OnEndContextRendering(ScriptableRenderContext context, List<Camera> cameras){
    8.     renderLines(); //call to your GL Lines/Draw method
    9.   }
    10.  
    11.   void OnDestroy(){
    12.     RenderPipelineManager.endContextRendering -= OnEndContextRendering;
    13.   }
    Edit: The lines only partially show in build and they render over EVERYTHING whereas in the play mode on the editor they are in the scene with stuff both behind and in front of them as desired. Not sure why it would be fine in the editor using play mode but not in build, so frustrating!
     
    Last edited: Mar 17, 2022
    Nirlah likes this.