2. Draw calls 많은 수의 오브젝트들은 CPU의 부하를 주고, 많은 수의 triangle들은 GPU의 부하를 가져다 준다. 더해서 게임 코드를 위해서 또한 CPU가 필요. 오늘날에 그래픽 처리 장치는 초당 500 개의 draw call들 정도면적당하다. 각각의 픽셀 조명은 메쉬를한번더 그리게 되므로, 절대 많은 수의 픽셀 조명을 사용하지 말것!
3. Combining 씬내에 많은 수의 오브젝트들 – bad. 근접해 있는 오브젝트들간에 combine – good. “너무 많은 combine” – bad again.
4. Good Combining Combined objects are close to each other and use the same meterial Combine의 쉬운 예시로써는 집에 있는 방들 배치 같은경우 Often requires using texture sheets! 오브젝트 크기와 포인트/SPOT 라이트 크기가 같은 경우
5. Bad Combining 서로간에 멀리떨어진 오브젝트의 경우 절대 하지 말것. If light shines only on part of object, whole object needs to be drawn. 만약 조명이 오브젝트의 부분에만 드리워지면전체 오브젝트는 그려져야만 함. If camera sees only a tiny corner of object, 만약 카메라가 오브젝트 코너에 작은 영역만을 보는 경우 Whole object needs to be drawn. 전체 오브젝트가 그려질 필요가 있는경우
9. Lights are for? 동적라이팅과정적라이트맵을합치는것. 라이트맵은 월드상에 고정적 빛 요소를 모두 제거 해준다. 빠르고 비주얼도 좋다. 그럼 동적 빛은 언제 써야할까? 로켓, 횟불, 동적 그림자등.. Culling masks!
10. Raycasting 레이캐스팅은 느려지며 각 프레임 별로 레이 캐스트 남용하지 말것. 컬링 마스크를 사용함으로써 레이캐스팅을 미리 방지 할 수 있다. 3프레임당 한번씩만 레이캐스팅을하는것은 어떨까? 컬링 마스크 = GUI : Layername부여.
11. Finding objects FindObjectsOfType, FindGameObjectWithTag, GameObject.Find Avoid doing it too much. It’s convenient but those calls can quickly add up. Use static variable 모든 활성화된 컴포넌트들을 static ArrayList와 OnEnable/OnDisable을 사용해서 저장 할 것.
12. Only Update nearby objects Don’t run scripts at all, when far away. Function Update() { if(far away) return; }does NOT count.Use enabled = false; Use triggers for finding out when player is close by or use coroutine that updates every seconds. 오브젝트가 근접했는지를 알아내기 위하여 Trigger를 사용또는 매초마다코-루틴 사용
13. Math Add, substract, multiply: a couple cycles. Divide : 30-40 cycles. Square root, sin, cos:60-100cycles Sqrt, Normalize In inner loops avoid Sqrt and Normalize. They are faily expensive. (Normalize internally uses Sqrt) Normalize = vec / sqrt(vec.x^2 + vec.y^2 + vec.z^2); use sqrMagnitude instead. If(distance > dif.magnitude) Bad! If(distance*distance > dif.sqrMagnitude)
19. 1.Built-in array - 13.1FPS 2.CachePosition – 33.5FPS Total Boids Demo static function UpdateCachedPositions () { if (cachedPosition == null) cachedPosition = new Vector3[allVehicles.length]; for (var i=0;i<cachedPosition.length;i++) { cachedPosition[i] = allVehicles[i].transform.position; } } function ApplySeparation () { var separate = Vector3.zero; /// Optimizations /// * Cache position of our selves (no transform.position) /// * Cache position of other in an array updated once per frame (no transform.position) var position = transform.position; for(var i=0; i<allVehicles.Length; i++) { varposDiff = position - cachedPosition[i]; separate += posDiff.normalized * (1.0 / (posDiff.sqrMagnitude + 0.5)); } … }