Opaque Discs Drawing Over Cnavas

Avatar
  • updated

I am drawing opaque discs in immediate mode using "beginCameraRendering" but they draw on top of world space canvases. Is there anything I can do to fix this?

Reporting a bug? please specify Unity version:
2022.3.27f1
Reporting a bug? please specify Shapes version:
4.3.1
Reporting a bug? please specify Render Pipeline:
URP
Avatar
Harper Rhett

Updated to 4.5.0 and this problem still seems to be the case.

Avatar
Freya Holmér creator

What do you mean by using "beginCameraRendering" specifically?

Shapes is very sensitive to the exact moment to render in, I generally recommend using the ImmediateModeShapeDrawer helper class for this.

For example, this will draw opaque shapes properly together with world space canvases:

using Shapes;
using UnityEngine;
using UnityEngine.Rendering.Universal;

[ExecuteAlways] // <-- just to make it draw in the scene view as well
public class OpaqueOrderTest : ImmediateModeShapeDrawer {
public override void DrawShapes( Camera cam ) {
using( Draw.Command( cam, RenderPassEvent.AfterRenderingOpaques ) ) {
Draw.BlendMode = ShapesBlendMode.Opaque;
Draw.Disc( Vector3.zero, 100, Color.red );
}
}
}

Image 885

Avatar
Harper Rhett

Thanks! I was not using "RenderPassEvent.AfterRenderingOpaques". Seems to have fixed the issue.

Is there any downside to subscribing like this as opposed to using ImmediateModeShapeDrawer:

protected virtual void Awake()
{
     RenderPipelineManager.beginCameraRendering += Draw;
}

private void OnDestroy()
{
     RenderPipelineManager.beginCameraRendering -= Draw;
}

and then in the Draw function:

private void Draw(ScriptableRenderContext context, Camera camera)
{
     using (Shapes.Draw.Command(camera, RenderPassEvent.AfterRenderingOpaques))
     {
         // Draw stuff here!
     }
}

I like to do this for each script that needs to draw. I understand I lose the ability to define draw order, but otherwise it should be fine right? Instancing should work out alright since I am only drawing similar shapes within the same draw function.