actionscript-3fragment-shaderstage3dagal

How do AGAL registers get added or subtracted when they 'contain' 3D vectors?


I'm working on adding a shadow to planetary rings in a space game I'm developing. For this I need to calculate where a cylinder (the shadow of the planet) intersects with a plane (the mesh of the rings).

I'm being impeded by not being able to see how the 'sub' and 'add' opcodes deal with each component of a register. On this page http://www.adobe.com/devnet/flashplayer/articles/what-is-agal.html there is a graphic that illustrates what each of the opcodes does; It describes the addition and subtraction (amongst other calculations) as 'component-wise'.

Does this mean, if I'm adding or subtracting 3D vectors, the x, y, z (and w?) components will be affected independently of one another? And, if so, how do the registers 'know' NOT to do that if adding or subtracting, say, 2 Numbers? Do I need to deal with each component separately for 3D vectors or would just using 'add' or 'sub' add or subtract the 2 vectors correctly?


Solution

    1. Component-wise means that each vector component will be added/substracted/etc separatelly from each other. For example, adding two vectors together:

      (x1, y1, z1, w1) + (x2, y2, z2, w2) = (x1 + x2, y1 + y2, z1 + z2, w1 + w2)

    2. You use vector swizzling if you need to add only some components in arbitrary order:

      v1.xzy + v2.wwx = (v1.x + v2.w, v1.z + v2.w, v1.y + v2.x)