Search Issue Tracker
By Design
Votes
0
Found in
2018.4
2019.2.6f1
2019.4
2020.1
2020.2
Issue ID
1266427
Regression
No
Handles DrawSolidRectangleWithOutline is not frustum culled and is appearing in the opposite camera side of the object
How to reproduce:
1. Open attached project "HandleTest.zip" and scene "SampleScene"
2. In Scene view, fly and bypass the object with the black rectangle and label
3. In Scene view, observe black label background
Expected result: the black rectangle is not visible
Actual result: the black rectangle is culled and not visible
Reproducible with: 2018.4.26f1, 2019.4.6f1, 2020.1.0f1, 2020.2.0a18
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- var VisionOSEDRHeadromm has a comma instead of a dot when building with Metal Rendering App Mode and local OS localization is set to German
- IAP Catalog remove product “x” and add product “+” buttons are not consistent with other remove and add buttons in the Editor
- Performance issues in Play Mode when quickly hovering the mouse cursor over Hierarchy GameObjects
- Frame Debugger displays incorrect output when FidelityFX Super Resolution or Spatial-Temporal Upscaler is used with Temporal Anti-aliasing or Subpixel Morphological Anti-aliasing
- The layout system is failing to correctly calculate or apply the height of the Japanese fallback font when the primary English font's metrics are used
Resolution Note (2021.2.X):
Handles.DrawSolidRectangleWithOutline is being given a valid rect, and is drawing correctly.
The problem is coming from this line:
labelRect = HandleUtility.WorldPointToSizedRect(pos, labelContent, labelStyle);
HandleUtility.WorldPointToSizedRect is not doing any special handling for frustum culling, so when given a point behind the camera it still returns a valid rect.
Arguably this could return Rect(inf, inf, 0, 0,) or similar when given out of bounds positions, but that would be a breaking change for anyone already using this method, and really I'm not sure it leaves us in a better position. DrawSolidRectangleWithOutline is not typically used in GUI blocks, and all existing Handles functions that draw in GUI space (ex, Handles.Label) already perform a check prior to rendering that they are in front of the camera.
I would suggest doing the check that other Handles methods when drawing GUI from a world point, ex:
Handles.BeginGUI();
if (HandleUtility.WorldToGUIPointWithDepth(pos).z > 0f)
{
Rect labelRect = HandleUtility.WorldPointToSizedRect(pos, labelContent, labelStyle);
Handles.DrawSolidRectangleWithOutline(labelRect, labelRectFaceColor, LabelRectOutlineColor);
}
Handles.EndGUI();
Handles.Label(pos, labelContent, labelStyle);