Date post: | 16-Jul-2015 |
Category: |
Technology |
Upload: | flash-conference |
View: | 2,045 times |
Download: | 2 times |
https://www.facebook.com/games/cower_defense
https://www.facebook.com/games/clock-maker/
How do QuadBatch work• Collects quads with the same state(same texture,
same blend mode, same shader program)
• Transforms all vertices to one space
• Packs to one vertex buffer
• Renders
Our approach• Create one vertexBuffer during initialization and
upload initial data, compile programs
• Batch quads and images by the same state(blendMode, texture) and collect Vector.<Number> with data (x,y,width,height,uv,tintcolor)
• transfer data to GPU with Context3D.setProgramConstantsFromVector
How it works
0,00,0 1,0
1,10,1
Initial vertex buffer data
Process vertex datain vertex shader withdata from constants
x,y = 100, 100width, height = 100,200rotation = 0uvOffsetuvScaletintColor
transfer to fragment shader
100,100 200,100
200,300100,300
Vertex shader output
Limit• 128 registers for vertex constants, we can batch
around 31 quads into one drawcall. (128 - 4 registers for matrix - 1 register for common vertex constants)/4(data registers for one quad pos, uv, rotation, color)
SAP particle systemhttps://github.com/gonchar/SAP
http://bit.ly/1BLd9w3
Demo
Create init data• Create vertex and index buffers on the start
• Upload to the GPU once
• Vertex Buffer includes simple mesh x,y and global offset value in vertex constants array
Some Starling advices• Starling MovieClip should be rendered through
constants
• Use ByteArray instead of Vector.<Number> for vertices data upload. Also you can use Apparat to optimize your work with ByteArray https://github.com/joa/apparat it gives +20% performance
Batch Spine Animations• All bones are calculated on CPU, so all vertex data in one
space
• How to batch these quads through constants? we can’t use x,y,rotation,width,height properties for the processing simple mesh. We have only vertex positions and uvs.
Create init data• now it holds weights for each vertex. the weight is
like a pointer to constant register with vertex data
Thank you!• Stage3D Facebook Group
https://www.facebook.com/groups/stage3d/
• https://twitter.com/UnknownFlasher
• SAP Particles https://github.com/gonchar/SAP
• http://gonchar.me
• http://www.belkatechnologies.com
• https://github.com/joa/apparat