- Home /
How to draw a line with GL in HDRP?
I want to draw a line with GL api and i have tried two different ways to get it but neither worked I tried to use OnPostRender
hook method to draw the line, but this hook method didn't seem to be called (i had already mounted this script to the main camera)
The second way is that i tried to use OnRenderObject
hook method, and i mounted this script to a gameObject
, but when i tried to run the game, the line was only visible in Scene window but invisible in Game window.
void OnRenderObject ()
{
RenderLines();
}
void RenderLines ()
{
mat.SetPass(0);
GL.PushMatrix();
GL.Begin(GL.LINES);
GL.Color(Color.red);
GL.Vertex(new Vector3(0, 0, 0));
GL.Vertex(new Vector3(1, 0, 0));
GL.End();
GL.PopMatrix();
}
Yeah an example would be in order. nothing works.
Answer by andrew-lukasik · Feb 19 at 06:46 PM
Try subscribing to RenderPipelineManager rendering events
using UnityEngine.Rendering;
void Awake ()
{
RenderPipelineManager.beginCameraRendering += (ctx,cam) => RenderLines();
// note: if beginCameraRendering doesn't work, try the other ones
}
I just tried this and it doesn't render the lines and also puts the FPS down to 2 from around 60.. So this isn't working for 2021.2 sorry to say.
Oh well, that was a guess on my part. I don't remember if it was beginCameraRendering
precisely or one of the other events there, but it's a better answer that none for sb who needs any clue possible here.
I was using these events with URP and worked all fine there.
Answer by thephox1982 · Feb 19 at 08:05 PM
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;
}
Your answer
Follow this Question
Related Questions
Mesh triangles and vertices, searching for adjacent triangle 1 Answer
Multiple coroutines starting from Update() freeze/crash Unity 0 Answers
Player dies when it Hits/crushes a block 2 Answers
variable from another script doesn't update 0 Answers
I want to move the camera by swiping horizontaly (Mobile Input). 1 Answer