Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser MMOG Daosheng Mu, Lead Programmer Eric Chang, CTO XPEC Entertainment Inc.

Similar presentations


Presentation on theme: "Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser MMOG Daosheng Mu, Lead Programmer Eric Chang, CTO XPEC Entertainment Inc."— Presentation transcript:

1 Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser MMOG Daosheng Mu, Lead Programmer Eric Chang, CTO XPEC Entertainment Inc.

2 Outline Brief of Speakers Introduction of Adobe Flash Stage3D API XPEC Flash 3D Engine Optimization for Flash Program Future Works Conclusion Q & A

3 Brief of Speakers Eric Chang –19 Years of Game Industry Experiences –Cross-platform 3D Game Engine Development –PC/Console/Web

4

5 Brief of Speakers Daosheng Mu –4.5 Years of Cross-platform 3D Game Engine Development Experiences –PC/Console/Web

6 Why Flash? Native C/C++ vs. Unity vs. Flash Native C/C++ UnityFlash Development Difficulty HighLowMid Ease of Cross Platform LowHigh Performance HighMidLow Market Popularity LowMid High (>95%)

7 Project C4 Demo Video

8 Introduction of Adobe Flash Stage3D API

9 Stage3D Support all browsers

10 Stage3D Stage3D includes with GPU-accelerated 3D APIs –Z-buffering –Stencil/Color buffer –Vertex shaders –Fragment shaders –Cube textures –More…

11 Stage3D Pros: –GPU accelerated API –Relies on DirectX, OpenGL, OpenGL ES –Programmable pipeline Cons: –No support of alpha test –No support of high-precision texture format

12 Stage3D ResourceNumberallowedTotalmemory Vertex buffers MB Index buffers MB Programs MB Textures MB* Cube textures MB Draw call limits32,768 *350 MB is absolute limit for textures, 340 MB is the result we gather

13 AGAL Adobe Graphics Assembly Language –No support of ‘if-else’ statements –No support of ‘constants’

14 XPEC Flash 3D Engine

15 Model Pipeline Action Message Format (AMF): –Native ByteArray compression –Native object serialization 3DS Max Engine Loader Exporter Collada Binary Converter AMF Engine Render

16 XPEC Flash 3D Engine Application: update/render on CPU Command buffer: store graphics API instruction Application Command buffer Driver GPU CPU

17 XPEC Flash 3D Engine: Application

18 Scene Management Goal: Minimize draw calls as possible Indoor Scene –BSP tree Outdoor Scene –Octree/Quad tree –Cell –Grid

19 Scene Management: Project C4 Grid partition Object3D: (MinX, MaxX), (MinY, MaxY) (0,0),(1,2) (3,4),(0,2) y x

20 Scene Management: Project C4 Frustum: (MinX, MaxX), (MinY, MaxY) (1,4),(0,4) (0,0),(1,2) (3,4),(0,2) y x

21 XPEC Flash 3D Engine: Command Buffer Initialize createVertex/Index Buffer createTexture createProgram Begin clear setRenderToTexture Draw setVertex/Index Buffer setProgram setProgramConstants setRenderState setTextureAt drawTriangles End present Avoid user/kernel mode transition Decrease shader patching –“Material sorting” Reduce draw call –“Shared buffers” –“Dynamic batching”

22 Material Sorting Opaque/Translucent

23 Material Sorting State management 1047/2598 draw calls

24

25

26 Before sorting(ms)After sorting(ms) NVIDIA 8800 GT draw calls Render loop elapsed time 16 Total elapsed time 4140 NVIDIA 8800 GT draw calls Render loop elapsed time 36 Total elapsed time 50 Before sorting(ms)After sorting(ms) NVIDIA 6600 GT draw calls Render loop elapsed time 3431 Total elapsed time 5348 NVIDIA 6600 GT draw calls Render loop elapsed time 8164 Total elapsed time 89

27 Shared Buffers Problem: –Numbers of buffers are limited ResourceNumberallowedTotalmemory Vertex buffers MB Index buffers MB Programs MB

28 Shared Buffers Vertex Buffer Index Buffer Vertex Buffer Index Buffer Vertex Buffer Index Buffer

29 Particle System Each particle property is computed on the CPU at each frame –Alpha, Color, LinearForce, Size, Speed, UV –Facing

30 Particle System Index buffer –Indices will not be changed Vertex buffer –Problem: Particle amount depends on frame Upload data to vertex buffer frequently

31 Particle System Static Index Buffer Dynamic Vertex Buffer Vertex Data

32 Skinned Model Problem: –Lesser vertex constants allowed 128 constants per vertex program –Global vertex constants Lighting, Fog, Const

33 Skinned Model 4x3 Matrix Bone count per geometry is limited to 29 –“Split mesh” 128 constants / 3 = bones 3 * 29 bones = 87 constants

34 Shadow Map

35 present() End frame setRenderToBackBuffer() Set shadow map setRenderToTexture() Clear shadow mapDraw to shadow map clear() Clear back buffer

36 Shadow Map Problem: –Texture format: RGBA8 –Artifact Aliasing Popping while moving

37 Size: 1024x1024 RGBA8  R32 Shadow Map

38 Percentage Closer Filtering (PCF) solution: –Hard shadow –Aliasing –Popping while moving

39 Shadow Map PCF pw = 1/mapWidth ph = 1/mapHeight Result = 0.5 * texel( 0, 0) * texel( -pw, +ph) * texel(-pw, -ph) * texel( +pw, +ph) * texel(+pw, -ph) (-pw, +ph) (+pw, +ph) (0, 0) (+pw, -ph)(-pw, -ph)

40 Shadow Map PCF based solution:

41 Toon Shading Single pass –Problem: Dependent on no. of face Two passes –Scale vertex position following the vertex normal –Not dependent on no. of face

42 Toon Shading Enable back face Scale vertex position Draw color Toon Enable front face Draw material GeneralResult

43 Alpha Test Problem: –Stage3D without alpha test –“kil opcode in AGAL” Performance penalty on mobile device

44 Alpha Test Solution: Render loop time(ms) Total time(ms) 6600GT alpha test 17~ GT alpha blend 18~1965~ GT alpha test GT alpha blend draw calls Alpha-test performance is better on desktop Replace alpha-test with alpha-blend

45 Post Effect OriginGlowDOFColor Filter

46 Static Lightmap Pros: –Pre-computation –Global illumination Cons: –More textures

47 Optimization for Flash Program

48 Problem: –For Each is slow “Use for-loop to replace it” –Memory management “Recycle manager” “Strengthen garbage collection”

49 Optimization for Flash Program Solution: –Recycle manager Reduce garbage collection loading Save objects initial time public function recycleObject3D( obj:IObject3D ):void public function requestObject3D( classType:int, searchKey:*, renderHandle:int = 0 ):*

50 Optimization for Flash Program Solution: –Strengthen garbage collection Avoid inner function Force to dereference function pointer Dereference attribute in object destructor

51 Avoid inner function Force to dereference function pointer Without inner function Use inner function

52 Optimization for Flash Program Experiment: before vs. after –Switching among levels Before improvement:After improvement :

53 Rapid loading

54 Streaming –Data compression PNG: swf compression: 20%~55% Package: zip compression: 25~30% –Batch loading Separate resource to several packages Download what you really need

55

56 Rapid loading Enter to avatar stage Enter to game stage After loading picture finished 5Mb/s Elapsed time (sec) game code ui game scene scene textures

57 Future Works Adobe Texture Format (ATF) –Support for compressed/mipmap textures on the different GPU chipset FlasCC –C++  AS3 Compilation AS3 Workers –Multi-thread support MovieClip –Replace with Stage3D UI framework, ex: Starling

58 Conclusion Cross-Device/Cross-OS/Cross-Browser –Browser + Cloud Computing –Write Once, Run Anywhere Flash vs. HTML5 Cross-Compiling Technology Trend –C/C++ + Flash/ActionScript –C/C++ + HTML5/JavaScript

59 Acknowledgements XPEC - Project C4 Team XPEC - RDO Team

60 Q & A


Download ppt "Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser MMOG Daosheng Mu, Lead Programmer Eric Chang, CTO XPEC Entertainment Inc."

Similar presentations


Ads by Google