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
- Memory usage rises when switching scenes with GRD enabled and a loaded texture in URP
- [Quality Hackweek] Terrain Brush Size value is not serialized after deselecting the terrain when using the first instance of multiple Inspectors
- "NullReferenceException" is thrown when setting a long string in TMP with "Atlas Population Mode" set to "Dynamic" and "Multi Atlas Textures" enabled
- TextMeshPro text is misaligned when alignment is set via script
- A DX11 shader error is thrown when compiling shaders for platforms without DX11 support
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);