Torus doesn't render at camera's position

Avatar
  • updated
  • Under Review

Test scene is just a default 3D scene with this script attached to the camera:

using UnityEngine;
using Shapes;

[ExecuteAlways]
public class ShapesTest : ImmediateModeShapeDrawer {
    public bool AddOffset = true;
    public bool UseLocalSpace = true;
    
    public override void DrawShapes( Camera cam ) {
        using( Shapes.Draw.Command( cam ) ) {
            Shapes.Draw.LineGeometry = LineGeometry.Volumetric3D;
            Shapes.Draw.ThicknessSpace = ThicknessSpace.Meters;
            
            var r = 5f;
            var th = 0.25f;
            
            if( UseLocalSpace ) {
                Shapes.Draw.Matrix = transform.localToWorldMatrix;
                var position = AddOffset
                            ? Vector3.forward*0.0001f
                            : Vector3.zero;
                var color = AddOffset ? Color.green : Color.cyan;
                Shapes.Draw.Torus( position, Vector3.up, r, th, color );
            }
            else {
                Shapes.Draw.Matrix = Matrix4x4.identity;
                var position = AddOffset
                            ? transform.position + Vector3.forward*0.0001f
                            : transform.position;
                var color = AddOffset ? Color.red : Color.magenta;
                Shapes.Draw.Torus( position, Vector3.up, r, th, color );
            }
        }
    }
}

When "AddOffset" is true, the torus draws, the desired effect is achieved - camera is inside the torus' centre.
When "AddOffset" is false, torus is not drawn - which to me feels like a bug? I can't blame the camera's culling volume on it - the offset is way smaller than camera's default NearClipPlane of 0.3.
Changing the drawing space has no effect on the behavior.

It's not super-critical for my case, I can live with a workaround, but feels fishy, maybe worth investigating.

P.S.
Shapes rock!

Reporting a bug? please specify Unity version:
2020.3.45
Reporting a bug? please specify Shapes version:
4.2.1
Reporting a bug? please specify Render Pipeline:
Built-in render pipeline
Avatar
Freya Holmér creator
  • Under Review

hah, this is such an edge case that will only ever happen if the center of a torus is exactly at the camera location

tldr: Shapes often needs to know thickness values in pixels rather than meters, and in some cases this is measured from the origin of the object. And when you've got a perspective projection, the pixels per meter value shoots up to infinity exactly at the camera origin