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
- Crash on tlsf_free when generating the Font Atlas
- “… is using a shader without GPU deformation support. Switching the renderer over to CPU deformation.” warnings are logged when GPU Skinning is set to GPU
- "Material '...' has _TexelSize / _ST texture properties which are not supported by 2D SRP Batcher...” warning is logged when the Shader is SRB Batcher compatible
- Crash on EnsureUniqueSiblingName when calling GameObjectUtility.EnsureUniqueNameForSibling() with a null argument
- Changes are not applied when selecting Platform settings for Plugins
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);