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
- [Rendering Debugger] Shortcut in documentation to open window doesn't work
- The "Compress Tilemap Borders" function is not working when used via the Context Menu or through Script
- HDRP Sorting Priority not working when Render Pass is locked on a parent material
- [XR] Camera view rendered by the RenderTexture is not updated at runtime when XR is enabled
- Lens Flare occlusion is slightly delayed when Anti-aliasing is set to TAA
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);