2012年11月15日 星期四

Stage3D: 2D Particle Random Motion

2D particle random motion for Stage3D,
Here is a demo with 5000 particles.



code:

AGAL code:
code += "mov vt0, va0\n";                      // get vertex position
code += "mov vt1.x vc4.z\n";  // vt1.x = getTimer()/1000;
code += "frc vt1.x vt1.x\n";  // vt1.x = get value from 0 to 1
code += "mul vt1.xy vc5.xy vt1.xx\n";    // vt1.xy = vc5.xy * vt1.xx;
code += "add vt0.xy vt0.xy vt1.xy\n";     // move: vt0.xy = vt0.xy + vt1.xy
code += "m44 op, vt0, vc0\n";               // m44: vt0 * vc0
code += "mov v0, va1\n";

createParticle: 方便批次產生正方形粒子,但產生海量資料時會拖慢速度,改用另外作法。
setProgramConstantsFromMatrix: Matrix3Ds are always 4×4 matrices so four registers are needed to store their constants.
ie: context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, matrix3d, true);
這樣會佔掉 vc0, vc1, vc2, vc3
drawTriangles: draw from indexBuffer, firstIndex, numTriangles
ie: context3D.drawTriangles(indexParticle, 6, 2);
索引緩衝區中取資料,從第六筆資料開始,繪製兩個三角形

TODO:
- Reduce draw calls.
- Due to the VertexBuffer and IndexBuffer limit(around 16383 particles per draw call).

NUM_PARTICLES 超過 16383 會噴 error
[Fault] exception, information=ArgumentError: Error #3670: Buffer too big

沒有留言:

張貼留言