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
- Mono Windows Builds don't produce full log callstacks when generating logs
- AssetBundles fail to load when running in Built Players for Mobile Devices
- UI elements with text gets bigger and grey when Player window is moved to another screen with different resolution
- System name accepts multiline text but crops it on confirmation, duplicates input, and shrinks the field when empty
- UI element scale and position are wrong in project build when DRS is changed with HDR and Software Dynamic Resolution enabled
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);