【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法

370 Views

June 07, 17

スライド概要

"講演者:ジャン・フランソワ・F・フォルティン(Unity Technologies)

こんな人におすすめ
・グラフィックスとインスタンシングに関してもっと知りたいプログラマー

受講者が得られる知見
・インスタンス化されたシェーダーを作成・編集する方法
アニメーションする群衆などをパフォーマンスを低下させずに表示する方法
スキンドメッシュアニメーションをテクスチャにベイクする方法"

講演動画:https://youtu.be/7_i-2n45VoQ

profile-image

リアルタイム3Dコンテンツを制作・運用するための世界的にリードするプラットフォームである「Unity」の日本国内における販売、サポート、コミュニティ活動、研究開発、教育支援を行っています。ゲーム開発者からアーティスト、建築家、自動車デザイナー、映画製作者など、さまざまなクリエイターがUnityを使い想像力を発揮しています。

シェア

またはPlayer版

埋め込む »CMSなどでJSが使えない場合

関連スライド

各ページのテキスト
2.

GPU Instancing

3.

Jean-François F Fortin Graphics Expert, Field Engineer, Unity Technologies jff@unity3d.com

4.

Starting Point • I started at Unity recently and I was looking for ideas to learn to use the engine. • Worked on many projects where we where limited in draw calls. • Inspired by the work I’ve done for the Shinra Technologies ( ) cloud gaming platform. More specifically: • - Engine architecture focusing on “drawing many things”. • - “Living World” demo.

5.

Shinra Technology’s Living World Demo

6.

Starting Point • “Data oriented designs” to work well both on the CPU and GPU. • CPU was potentially expensive as it was required to do specific tasks. • GPU is cheap as work could be shared between multiple players. • Same ideas can be adapted to current games: • - Games can often be limited by the CPU. • - GPU can often execute more work.

7.

Starting Point • What could I bring from this within unity as a learning project? • I’ll take you through the mind of a graphics programmer, through my experiments and thought process to optimize instancing.

8.

Why Instancing? • Game performance is currently usually limited by the CPU. • The world is filled with things, games usually look empty by comparison. • Examples: • - Dense forest with many species of trees, cities filled with buildings. • - Real world feels alive filled with different animals or people. • Problems: • - CPU not as powerful as GPUs. • - Complex and dense scenes means lots of work on the CPU. • - Most of the scene traversal is not GPU friendly.

9.

First Steps… Learning Unity Instancing • Instancing is typically used to render identical objects: • - Same mesh. • - Same material. • - No animations. • Helps to reduce the CPU usage as objects are grouped together and less draw calls needs to be issued. • Available on most platforms.

10.

First Steps… Learning Unity Instancing To enable instancing: 1. Create a new material. 2. Check “Enable Instancing”. 3. Done.

11.

Demo: Unity’s GPU Instancing

12.

First Steps… Per-Instance Data • Custom Shader example:

13.

First Steps… Per-Instance Data • Custom Shader example:

14.

First Steps… Per-Instance Data • MaterialPropertyBlock

15.

Analysis • Renders faster than individual instances but still slow. • Time spent on the CPU processing the scene. • Solution? • - Remove all the objects from the scene! • - Literally!

16.

GPU Instancing using Graphics.DrawMeshInstancedIndirect(…)

17.

Walking… Use scripts to tweak rendering 1. Remove objects (only need to disable the mesh renderers) from the scene. 2. Create MaterialPropertyBlock to include any instance data. 3. Render instances using Graphics.DrawMeshInstancedIndirect(…) which is a new addition to Unity 5.6.

18.

Walking… Use scripts to tweak rendering

19.

Analysis • Better performance on the CPU. • Can usually render more instances of the same model as the previous test. • GPU starts to have trouble when using more complex models. • Solution? • - GPU should do the visibility testing. • - Feed the result into the Graphics.DrawMeshInstancedIndirect(…) call.

20.

Running… Indirect calls • Same as the regular calls in concept. Could in fact implement the functionality of the regular call using them. • Difference? • - Takes the draw call parameters from a GPU buffer. • - See Graphics.DrawProceduralIndirect • - See Graphics.DrawMeshInstancedIndirect • - See ComputeShader.DispatchIndirect

21.

Running… Indirect calls • Very useful to link work done on compute shader with regular rendering. • No need to fetch the results back on CPU… • - This could potentially have a huge latency issues… • This enables the compute shaders to write the draw arguments. • The GPU later reads from the buffer the draw arguments.

22.

Running… Visibility Testing • It can be very simple and cheap to do visibility testing on the GPU. • Mostly dot products, and the GPU is fast at them. • Let’s build a data oriented version of the scene… • - A point cloud is the perfect structure for simple instances.

23.

Running… Visibility Testing Steps: 1. Shader process the objects and filters the visible objects. 2. Visible objects gets added into a “VisibleList” to be rendered. 3. Counter from the VisibleList is then used to update the buffer with the draw arguments. 4. DrawMeshInstanceIndirect(…)

24.

Running… Visibility Testing

25.

Running… Instance Setup

26.

Demo: Visibility testing

27.

Analysis • Best performances so far. • Shader can be flexible on what can be rendered as instances • Can even support dynamic and animated instances.

28.

Ideas to push this further…

29.

Animated Data • Regular instancing won’t work with animated objects. • Skinning is often done on the CPU or as a separate pass. • - “Stream output” from geometry shader or compute shader. • - In both cases it is essentially the same as having separate models for each animated instances. • Could re-implement skinning in Vertex Shader and store the matrices into a buffer like we did for our other parameters… • - This is a lot of data and could require a lot of VRAM. • - Not straightforward to implement as the required information is not easy to get.

30.

Animated Data Solution: 1. Bake animations as vertex animations and store the data into textures. 2. Set the animation texture as a property on the material. 3. Update the frame number and store along the other instance data.

31.

Animated Data: Baking

32.

Animated Data: Vertex Shader

33.

Animated Data: Binding on Material

34.

Moving Objects • How could we extend this to support birds, little animals, etc. • Compute shader that updates the data structure. • Can have objects moving in the scene without hurting performance much. 1. Create a buffer containing “update commands”. 2. Compute Shader to process individual commands. 1. -> Update object #103 to position [100, 10, 500].

35.

LODs and Billboards • Use the shader to do the calculations to get which LOD to use. • Create multiple draw calls from the buffer arguments (IndirectArgs) one for each LOD. • Billboards are essentially just a separate LOD.

36.

Conclusions • Unity instancing options are varied and work well. • Can be improved using new features such as the indirect calls. • Can go around limitations of instancing by using shader tricks.

38.

Thank you!