GL.Draw in HDRP

In URP I can use GL.Draw methods like seen in the example with no problems. Anyone knows if HDRP will support it too?

        void DrawLines(List<Vector3> lines, Color color)
        {
            if (lines.Count == 0) return;

            GL.Begin(GL.LINES);
            GL.Color(color);

            for (int i = 0; i < lines.Count; i += 2) {
                GL.Vertex(lines[i]);
                GL.Vertex(lines[i + 1]);
            }

            GL.End();
        }

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.

Hi, this couldn’t work with HDRP (Also I am surprise it work with URP :slight_smile: ). 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.

any other alternatives?

Fill vertex and index buffer of a mesh.

A little late, but I had the same problem just now and solved it like this:

        protected void OnEnable()
        {
#if UNITY_2017_1_OR_NEWER
            if (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset != null)
                UnityEngine.Rendering.RenderPipelineManager.endCameraRendering += endCameraRendering;
            else
#endif
            Camera.onPostRender += OnCameraRender;
        }

        protected void OnDisable()
        {
#if UNITY_2017_1_OR_NEWER
            if (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset != null)
                UnityEngine.Rendering.RenderPipelineManager.endCameraRendering -= endCameraRendering;
               
            else
#endif
            Camera.onPostRender -= OnCameraRender;
        }

#if UNITY_2017_1_OR_NEWER
        void endCameraRendering(UnityEngine.Rendering.ScriptableRenderContext src, Camera camera)
        {
            if (CheckFilter(camera))
                DrawLines();
        }
#endif

        protected void OnCameraRender(Camera camera)
        {
            if (CheckFilter(camera))
                DrawLines();
        }

        bool CheckFilter(Camera camera)
        {
            return (camera.cullingMask & (1 << gameObject.layer)) != 0;
        }
7 Likes

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)

2 Likes

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.

using UnityEngine.Rendering;

void Start(){
    RenderPipelineManager.endContextRendering += OnEndContextRendering;
  }

  void OnEndContextRendering(ScriptableRenderContext context, List<Camera> cameras){
    renderLines(); //call to your GL Lines/Draw method
  }

  void OnDestroy(){
    RenderPipelineManager.endContextRendering -= OnEndContextRendering;
  }

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!

1 Like