顯示具有 stage3d 標籤的文章。 顯示所有文章
顯示具有 stage3d 標籤的文章。 顯示所有文章

2012年12月10日 星期一

Stage3D: 2D Particle Random Motion [optimized]

I just updated some code of my last demo and optimized it by reducing draw calls.
Now it can render over large number of particle(500,000+).

Here are some optimization:
  • reduce draw call
  • upload minimum of constants

2012年11月21日 星期三

Stage3D Limitation and Optimization

Stage3D AGAL Limitation:
  • The VertexBuffer is limited to 65535 vertex.
  • The IndexBuffer is limited to 983040 index.
  • In theory, you could have up to 983040/3 = 327680 triangle in one draw call.
  • In particle(using quads), you could have up to 65535/4 = 16383 particle max per draw call.
  • Shaders length can only contain a maximum of 200 opcodes.
  • The drawTriangles limited to 32768 calls per present call.

Optimization:
  • reduce draw call.
  • reuse material and batch rendering.
  • upload minimum number of constants.

2012年9月20日 星期四

AGAL quick reference guide

AGAL 教學 備忘

Vertex Shader:
va0-va7:vertex attribute registers, set with context3D.setVertexBufferAt(...)
vc0-vc127:vertex constant registers, set with context3D.setProgramConstantsFromMatrix/Vector(Context3DProgramType.VERTEX, ...)
vt0-vt7:vertex temporary registers with xyzw component (ex: add vt0, va0, vc0)
v0-v7:varying registers, pass values to the fragment shader (ex: mov v0, va0)
op:output point (ex: mov op, va0)

Fragment Shader:
fc0-fc127:fragment constants set with context3D.setProgramConstantsFromMatrix/Vector(Context3DProgramType.FRAGMENT,...)
fs0-fs7:fragment(texture) sampler, set with context3D.setTextureAt(__sampler, __textureBmpd)
v0-v7:varying registers, values passed from the vertex shader (ex: mov oc, v0)
ft0-ft7:fragment temporary registers with xyzw component (ex: tex ft0, v0, fs0<2d,linear,nomip,repeat>)
oc:output color (ex: mov oc, ft0)

2012年9月19日 星期三

Introduction to Stage3D: Part 7

Introduction to Stage3D: Part 7
fire effect for stage3d tutorial
火/火球/火焰 效果教學

本篇是 Stage3D 的應用,
如果對 Stage3D 運作還不是很清楚,可以先看前幾篇入門文章。

在前一篇火焰效果教學,
是用 CPU Render 的方式處理效果,
接下來會用到 Stage3D GPU Render 運算功能來呈現火焰效果,

2012年7月20日 星期五

Introduction to Stage3D: Part 6

perspective projections
透視投影基本介紹及教學

右手座標系 RH:
+x is right
+y is up
-z is into the screen
順時針為正面,逆時針為背面

2012年7月16日 星期一

Introduction to Stage3D: Part 5

Stage3D 基本介紹及教學

之前的例子都是在幾何圖形上渲染上不同的顏色,
這篇介紹如何在圖形上貼上材質,
進入貼圖之前,先說明一下 UV(U,V) 座標對應,
U 水平 V 垂直,以百分比描述。

2012年7月13日 星期五

Introduction to Stage3D: Part 4

Stage3D 基本介紹及教學

建立 camera,
控制 camera 旋轉
沿 Y 軸旋轉
var dx:Number = _stage.mouseX - _lastMouseX;
_mat.prependRotation((dx/_stage.stageWidth)*360, Vector3D.Y_AXIS);

2012年7月12日 星期四

Introduction to Stage3D: Part3

Stage3D 基本介紹及教學
物件透過變形與透視可以呈現出 3D 顯示效果,

Matrix3D 處理 3D 變形
m = new Matrix3D();
沿著 Y 軸旋轉
m.appendRotation(getTimer()/30, Vector3D.Y_AXIS);
沿著 X 軸旋轉
m.appendRotation(getTimer()/10, Vector3D.X_AXIS);
沿著 Z 軸方向平移 2
m.appendTranslation(0, 0, 2);

Introduction to Stage3D: Part 2

Stage3D 基本介紹及教學
總結一下上篇 Stage3D 的流程
  1. 取得 context3D
  2. 設定 viewport
  3. 建立頂點"緩衝區"/定義頂點資料/上傳頂點資料
  4. 建立索引"緩衝區"/定義索引資料/上傳索引資料
  5. 設定暫存器
  6. 建立頂點及片段著色器程式
  7. 上傳 AGAL bytecode
  8. 顯示結果於螢幕/drawTriangles and present.

2012年7月10日 星期二

Introduction to Stage3D: Part 1

Stage3D 基本介紹及教學
Stage3D 簡單講就是提供 API 讓 Flash 可以使用 GPU 進行 3D 硬體加速以提升效能,

架構示意圖
   GPU   
OpenGL or DirectX
  Stage3D  

顯示的順序如下,
Stage(最上層為傳統的 flash 顯示層)
Stage3D[2]
Stage3D[1]
Stage3D[0]
StageVideo