Alright, kiddies, sit around. I’m here to tell you how to use AGALMiniAssembler. It is probably not like anything you’ve ever used (unless you’ve used assembly).

Each register holds 4 floats, and are indexed x,y,z,w, so the sixth float would be reg1.y, as the first five would be held in reg0.x,y,z and w, followed by reg1.x.

There are several types of registers (variables):

  • Vertex Attribute (va) – This is passed in with Vertex Buffers. The index you pass into context.setVertexBufferAt is the index at which you can access it.
  • Vertex Constant (vc) – These are passed into the program with setProgramConstantsFromVertex/Matrix. If you need to pass any numbers into your shader (for example, pi, or a light direction) this is what you’d use (for your vertex shader)
  • Vertex Temporary (vt) – These can be used to hold values for calculations later in the shader. They are uninitialized before the shader is run on each vertex.
  • Vertex Output (op) – This is where you store the final vertex co-ordinate.
  • Varying (v) – You can pass values from the vertex shader to the fragment shader using a varying. The value received by the fragment shader is interpolated between the three vertexes making up the triangle.
  • Fragment Constant (fc) – Same as Vertex Constant, except for fragment shaders.
  • Fragment Temporary (ft) – Same as Vertex Temporary, except for fragment shaders.
  • Texture Sampler (fs) – Binding a texture using setTextureAt() will bind it to whatever fs index you use.
  • Fragment Output (oc) – The final color of the fragment goes in here.

The general format for statements is
operation destination source [source2]
For more information, check out the Program3D docs.

Here’s an example of a shader I’ve written, a textured vertex colored fog shader.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//v0 = UV Co-ordinates
//v1 = fog factor
//vc0-3 = modelview matrix
//vc4-7 = projection matrix
//vc8 = [fogstart, fogend, fogend-fogstart, 0] (though only y and z are used)
 
m44 vt0, va0, vc0 // Transform position by modelview matrix
m44 vt1, vt0, vc4 // and then by the projection matrix
sub vt2.z, vc8.y, vt1.w // Convert fog to 0-1 range
div vt2.w, vt2.z, vc8.z // "                      "
sat v1, vt2.w            // and output the fog factor
mov op, vt1  // as well as the position
mov v0, va1 // as well as the vertex colors
 
//fc0 = [1,0,0,0] (some constants I needed)
//fc1 = [1,1,1,1] (White fog)
 
tex ft3, v0, fs0 <2d,repeat,linear> //Sample the texture at the UV point
mul ft0.xyz, ft3.xyz, v1 // Multiply by fog factor
sub ft1.x, fc0.x, v1     // Subtract fog factor from 1 (Stored in fc0.x)
mul ft2, fc1, ft1.x      // And multiply the result by the fog color (stored in fc1)
add ft0.xyz, ft0.xyz, ft2.xyz //Add the values together (Blending fog in)
mov ft0.w, ft3.w //And set the alpha value
mov oc, ft0 // and move the result into the output

More information about shader programs can be found in the Program3D docs.


No related posts.

  4 Responses to “AGALMiniAssembler Primer”

  1. [...] vorhanden sein muss – eine zweite ist möglich. Aus- und Eingabe erfolgt über sogenannte Register, die wie der Opcode einer fest Formulierung folgen. Da wir die Befehle als String in AS3 notieren, [...]

  2. Each register holds 4 floats, and are indexed x,y,z,w, so the sixth float would be reg1.x, as the first five would be held in reg0.x,y,z and w, followed by reg1.x.

    Correct me if i’m wrong but shouldn’t the 5th float be found in reg1.x? As the first 4 are held in reg0.x,y,z,w, followed by reg1.x.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

   
© 2012 RyanSpeets.com Suffusion theme by Sayontan Sinha