Immediate-Mode Drawing with anamorphic camera

Avatar
  • updated

We are using Shapes to display rigging of a sailing boat, which is working great...


...The issue is that we are rendering an extremely anamorphic camera and need the Shape lines to reflect the camera projection matrix (i.e: We need the horizontal thickness to be different to the vertical thicknes for the lines; let's say a perfectly horizontal line is 10px wide, so a perfectly vertical line needs to be 4px wide [and a diagonal line is somewhere between the two]).


We are setting the anamorphic by using:

```cam.projectionMatrix = cam.projectionMatrix * Matrix4x4.Scale(new Vector3(0.4f, 1f, 1f));```

Is there a way to get the Shapes to respect (or emulate) this scaled camera projection matrix, so that the line thickness is drawn scaled anamorphically so that when the video output scale gets restored, the lines are not super thick horizontally.

Any advice would be appreciated.

Kind regards,

Adam.

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

hmm, that's a tricky one, I don't think there's a way to get this to work out of the box, but there might be modifications to the shaders that would do it by applying a non-uniform scaling factor to any billboarded/clip space offsets, but I'm not sure if even those might have some unforeseen consequences

I'm kinda curious though - what's the reason you're scaling the projection matrix like this/emulating an anamorphic lens? I would've expected this to introduce a lot of artifacts and issues once you restore it to the output aspect ratio

Avatar
adam reed

We have a single UHD / 4k output which is then being video mapped (stretched) across 7 seperate screens that are each rotated 90 degrees (9:16 ratio each).

Avatar
adam reed

We think one way to approach this is on each segment set varying line thickeness relative to its horizontality and verticality to get the desired line thickness when the video is output to the screens.


Do you have any suggestions about how we may approach this in the most efficient way?

Avatar
Freya Holmér creator

I think your best bet right now is to use meter-based thickness of the lines instead of pixel based ones, if possible, in that case I don't think there should be any issues with scaling right?

Another option that might be a little too involved for now is to implement anisotropic pixel scaling in Shapes itself - I have recently been working with pixel based sizing (in a different project) and found a method of getting meters/pixel ratios that support anisotropic projection matrices, as well as just being more accurate in general. I think it wouldn't be too hard to implement it for me at least, once I get around to the next update!

2 * wClip / (_ScreenParams.xy * abs(UNITY_MATRIX_P._m00_m11))