600 likes | 723 Views
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. Outline. Brief of Speakers Introduction of Adobe Flash Stage3D API XPEC Flash 3D Engine Optimization for Flash Program Future Works
E N D
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.
Outline • Brief of Speakers • Introduction of Adobe Flash Stage3D API • XPEC Flash 3D Engine • Optimization for Flash Program • Future Works • Conclusion • Q & A
Brief of Speakers Eric Chang 19 Years of Game Industry Experiences Cross-platform 3D Game Engine Development PC/Console/Web
Brief of Speakers Daosheng Mu 4.5 Years of Cross-platform 3D Game Engine Development Experiences PC/Console/Web
Why Flash? Native C/C++ vs. Unity vs. Flash
Stage3D • Support all browsers
Stage3D • Stage3D includes with GPU-accelerated 3D APIs • Z-buffering • Stencil/Color buffer • Vertex shaders • Fragment shaders • Cube textures • More…
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
Stage3D *350 MB is absolute limit for textures, 340 MB is the result we gather
AGAL • Adobe Graphics Assembly Language • No support of ‘if-else’ statements • No support of ‘constants’ Program3D
Model Pipeline • Action Message Format (AMF): • Native ByteArray compression • Native object serialization Collada AMF 3DS Max Exporter Binary Converter AMF EngineLoader EngineRender
XPEC Flash 3D Engine CPU • Application: update/render on CPU • Command buffer: store graphics APIinstruction
Scene Management • Goal: Minimize draw calls as possible • Indoor Scene • BSP tree • Outdoor Scene • Octree/Quad tree • Cell • Grid
Scene Management: Project C4 • Grid partition • Object3D: (MinX, MaxX), (MinY, MaxY) x (3,4),(0,2) (0,0),(1,2) y
Scene Management: Project C4 • Frustum: (MinX, MaxX), (MinY, MaxY) x (3,4),(0,2) (0,0),(1,2) y (1,4),(0,4)
XPEC Flash 3D Engine:Command Buffer • Avoid user/kernel mode transition • Decrease shader patching • “Material sorting” • Reduce draw call • “Shared buffers” • “Dynamic batching”
Material Sorting • Opaque/Translucent
Material Sorting • State management • 1047/2598 draw calls
Shared Buffers • Problem: • Numbers of buffers are limited
Shared Buffers Vertex Buffer Index Buffer Vertex Buffer Index Buffer Vertex Buffer Index Buffer
Particle System • Each particle property is computed on the CPU at each frame • Alpha, Color, LinearForce, Size, Speed, UV • Facing
Particle System • Index buffer • Indices will not be changed • Vertex buffer • Problem: • Particle amount depends on frame • Upload data to vertex buffer frequently
Particle System Static Index Buffer Dynamic Vertex Buffer Vertex Data
Skinned Model • Problem: • Lesser vertex constants allowed • 128 constants per vertex program • Global vertex constants • Lighting, Fog, Const
Skinned Model • 4x3 Matrix • Bone count per geometry is limited to 29 • “Split mesh” 128 constants / 3 = 42.6666 bones 3 * 29 bones = 87 constants
Shadow Map • Problem: • Texture format: RGBA8 • Artifact • Aliasing • Popping while moving
Shadow Map • Size: 1024x1024 • RGBA8 R32
Shadow Map • Percentage Closer Filtering (PCF) solution: • Hard shadow • Aliasing • Popping while moving
Shadow Map • PCF pw = 1/mapWidth ph = 1/mapHeight • Result = 0.5 * texel( 0, 0) + 0.125 * texel( -pw, +ph) + 0.125 * texel(-pw, -ph)+ 0.125 * texel( +pw, +ph) + 0.125 * texel(+pw, -ph) (+pw , +ph) (-pw , +ph) (0, 0) (-pw , -ph) (+pw , -ph)
Shadow Map • PCF based solution:
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
Alpha Test • Problem: • Stage3D without alpha test • “kilopcode in AGAL” • Performance penalty on mobile device
Alpha Test • Solution: • Replace alpha-test • with alpha-blend • 304 draw calls • Alpha-test performance is better on desktop
Post Effect Origin Glow Color Filter DOF
Static Lightmap • Pros: • Pre-computation • Global illumination • Cons: • More textures
Optimization for Flash Program • Problem: • For Each is slow • “Use for-loop to replace it” • Memory management • “Recycle manager” • “Strengthen garbage collection”
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 ):*
Optimization for Flash Program • Solution: • Strengthen garbage collection • Avoid inner function • Force to dereference function pointer • Dereference attribute in object destructor