문제해결
Frustum culling으로 유니티 2D 모바일 프레임 드랍 이슈 해결하기
samosa
2024. 11. 27. 14:35
2D 텍스쳐 크기가 커도 너무 컸다.
4000*3000 정도도 있고... 작은 것도 있긴 하고... 뭐 다양했다.
모바일 빌드하니 fps 가 12가 나왔다. 헉.
유니티 프로파일러를 켜보니 CPU보다 GPU가 문제였다.
아. 그냥 렌더를 하는데 너무 많은 부하가 있구나.
3D 만들 때는 Mesh로 유니티가 알아서 Occlusion culling을 해주고
Static으로 설정해준 오브젝트들도 연산이 가벼워지는 이점이 있었는데
2D에서는 이런 테크닉이 전혀 작동하지 않는다.
따라서 렌더 자체를 덜 하게 하기 위해 Frustum culling 코드를 테스트해보았다.
private void Update()
{
foreach (var spriteRenderer in _childSpriteRenderers)
{
var spriteBounds = spriteRenderer.bounds;
spriteRenderer.enabled = IsBoundsVisible(spriteBounds);
}
}
private bool IsBoundsVisible(Bounds bounds)
{
var cameraPlanes = GeometryUtility.CalculateFrustumPlanes(mainCamera);
// Check if the sprite's bounds intersect with the camera's frustum
return GeometryUtility.TestPlanesAABB(cameraPlanes, bounds);
}
잘되는걸!!!!
12fps 에서 60fps (모바일 최대 설정)까지 끌어올려졌다.