Drawing text in split screen

Avatar
  • updated

I'm trying to draw text in immediate mode on one half of the screen. But the text is misaligned, draws on the entire screen, and is stretched by a factor of the viewport rect.

This is how it looks, names are rendered using the same position as the black lines. The only value changing in this gif is the viewport rect of the left camera, changing its width from 0.5 to 1. A similar effect occurs when reducing the height.

Image 659

This is the draw command

using (Draw.Command(cam, (UnityEngine.Rendering.Universal.RenderPassEvent)renderQueue))
{
  if (fontAsset != null)
    Draw.Font = fontAsset;

  Draw.FontStyle = textStyle;
  Draw.FontSize = fontSize;
  Draw.TextAlign = TextAlign.Center;
  Draw.Color = textColor;

  foreach (var station in stations)
  {
    Draw.Text(station.WorldPosition + textOffset, station.name);
  }
}

Reporting a bug? please specify Unity version:
2021.3.14
Reporting a bug? please specify Shapes version:
4.2.1
Reporting a bug? please specify Render Pipeline:
URP
Avatar
Freya Holmér creator

from where are you calling this code?

Avatar

It's being called through a ImmediateModeShapeDrawers DrawShapes function.
And now I've solved it! Probably.

I was rendering the lines on RenderPassEvent 1001 and the text on 1002. Moving the text down to 1001 made it render as expected. I also made a repro project where 1002 worked fine but was broken at 1034.

All of these values are higher than "AfterRendering" I pushed them this far back because my skybox was rendering over them. I might have overreacted.