Flash AGAL

http://iflash3d.com/shaders/my-name-is-agal-i-come-from-adobe-1/

http://iflash3d.com/page/2/

 

Adobe recently introduced a new language called AGAL (Adobe Graphics Assembly Language). It’s part of Molehill, and its purpose is to
create the so called “shaders”: tiny little programs that affect how 3d models get rendered into the scene.

AGAL是adobe官方出的一个底层的着色器语言,能够写出神奇的渲染效果,但是相对于AS3比较难。
一般的形式就像这样:
//vertex shader
m44 op, va0, vc0 // pos to clipspace
mov v0, va1 // copy uv

//pixel shader
tex ft1, v0, fs0 <2d,linear,nomip>
mov oc, ft1

关于OpCode
opcode由三个字母组成,每行着色器语言就是一条命令,
语法形式如下:
<opcode> <destination> <source 1> <source 2 or sampler>
其中:
destination 和 source 指GPU中的寄存器(registers);
opcode由30个不同命令组成,一般常用的有以下几类:
   mov move data from source1 to destination, component-wise
    add destination = source1 + source2, component-wise
    sub destination = source1 – source2, component-wise
    mul destination = source1 * source2, component-wise
    div destination = source1 / source2, component-wise
    dp3 dot product (3 components) between source1 and source2
    dp4 dot product (4 components) between source1 and source2
    m44 multiplication between 4 components vector in source1 and 4×4 matrix in source2
    tex texture sample. Load from texture at source2 at coordinates source1.
关于AGAL寄存器(Registers)
Registers是AGAL在着色器渲染中能够使用的GPU中区域。
在着色器命令中被用于destination和sources的标识。
通过这些寄存器来传参至shaders。
每个寄存器由128bits的数据宽度,包含4个点的数值,每个值被称为寄存器的组件(component),
各个组件可以通过下标来访问(x、y、z、w),以及通过颜色访问器(r、g、b、a)访问。
例如va.x...
寄存器分为如下6类:
Attribute Registers属性寄存器
va是顶点着色器的 input VertexBuffer的引用,故而只在顶点着色器中共有用,
使用 Context3D:setVertexBufferAt() 来设定特定的va到vertexBuffer
va<n>---n=0-7;共有8个

关于常量寄存器Constant Registers
其被用于从as传参至着色器。可由Context3D::setProgramConstants()来操作。
顶点着色器vertex shaders可由 vc<n>访问;
像素着色器pixel shaders可由fc<n> 访问;
共有128个vc
和28个fc

临时寄存器 Temporary Registers
用于临时存放计算结果
 vt<n> (vertex) and ft<n> (pixel)
可用的vertex shaders 和  pixel shaders 分别有8个。

输出寄存器 Output Registers
其是存放顶点和像素着色器的计算结果的寄存器。
对于顶点寄存器而言此处是 剪裁空间 clip space 中的坐标位置;
对于像素着色器而言,就是每个像素点的颜色。

op--vertex Shaders
oc -- pixel shaders
每个只有一个寄存器。


插值寄存器Varying Registers
其被用于在vertex shaders 与 pixel shaders 之间传递参数。
通过GPU实现参数的准确插值过程,所以pixel shaders 可以在过程中获得准确的数值
其传递的典型数据是 vertex color和 UV值UV coordinates for texturing。
v<n>
有8个寄存器可以使用

纹理采样寄存器Texture Samplers
作用:在UV坐标系中,从纹理获得颜色值。
在Actionscript中通过Context3D::setTextureAt()来访问
 fs<n> <flags>
n--寄存器序号;
flags-- 模式序号

    texture dimension. Can be: 2d, 3d, cube
    mip mapping. Can be: nomip, mipnone, mipnearest, mipnone
    texture filtering. Can be: nearest, linear
    texture repeat. Can be: repeat, wrap, clamp.

posted @ 2013-05-30 14:00  jalps  阅读(241)  评论(0编辑  收藏  举报