Can Shapes be applied in screen space?

Avatar
  • updated

Hello!


Loving Shapes - great stuff!

I'd like to use the Draw.Matrix functionality to set a world view projection matrix (allowing me to draw shapes in absolute screen space, i.e. based on mouse cursor position). However, I'm having trouble getting this working (although if I hand multiply the points into world space using my created transform it works fine).

Should I expect shapes to support these kinds of matrices, and if so, would you mind sharing up any sample code that has this working (both the generation of the matrix, and its application).

Many thanks,

Adam.

Reporting a bug? please specify Unity version:
2021.3.26f1
Reporting a bug? please specify Shapes version:
Reporting a bug? please specify Render Pipeline:
Built-in render pipeline
Avatar
Freya Holmér creator

It should work! Assuming you're also drawing the shapes in immediate mode. The tricky part is the projective depth, but as long as you don't need correct depth handling, but it should work fine to use the local to world matrix of the camera you want to draw in. However, mind that the near clip is usually beyond 0, so you might have to offset the matrix by the near clip distance, plus some margin to ensure the shapes are within the camera's frustum.

I do something similar in the experimental ImmediateModeCanvas.cs, which might help as a reference!