In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

AGAL quirk

from AGALMiniAssembler.as:
if ( !isDest )
    for ( ; k <= 4; k++ )
        regmask |= cv << ( ( k - 1 ) << 1 ); // repeat last
Get Adobe Flash player
by yonatan 07 Nov 2011
  • Forked from yonatan's it's a knot
  • Diff: 560
  • Related works: 3
  • Talk

    fujimaru at 08 Nov 2011 16:37
    はじめまして dst のコンポーネントは 4 bit で単純に 1 bit が .xyzw それぞれに対応してます。 奇妙なのは src のコンポーネントの仕様で、 8bit [00][00][00][00] で表され 下位から順に 2 bit ずつが 1 コンポーネントずつになってます。 値と種類の対応は x 00 y 01 z 10 w 11 となってまして、ここまでは特に変でもないんですが、 指定が4種類以下の時は最後のコンポーネントで残りを埋めるようにようになってるようです。 (未指定時は 0xe4 = 0x11100100 = .xyzw ) なので、 vc9.y = vc9.yyy = vc9.yyyy (ex. vc.x = vc.xxxx vc.xy = vc.xyyy vc.yyz = vc.yyzz 動作上問題ないのかな?と、自分もちょっと不思議に思ってました
    fujimaru at 08 Nov 2011 16:45
    そういえば dst でもそれぞれ 1bit (ON/OFF)しかないのでバイトコードでは vt0.yyyz = vt0.yz になりました
    yonatan at 08 Nov 2011 17:39
    Hi fujimaru, unfortunately I don't speak japanese and google translate isn't making much sense, but i think you got the gist of it. It just means that one needs to be careful with masks, since things like: add vt0, vt1.x will alter vt0's y z and w components as well, but: add vt0.x, vt1.x should only change vt0.x (at least that's my current assumption, shaders are hard to debug...)
    fujimaru at 08 Nov 2011 17:53
    It commented in Japanese, and I felt sorry for having been now. automatic translation usage. Although he may seldom be able to understand, add vt2, vt0.x, vt1.x [[01 00 00 00 ][02 00 0f 02 ][00 00 00 00000000 02 00 00 00 ][01 00 00 00 02 00 00 00 ]] equal add vt2.xyzw, vt0.xxxx, vt1.xxxx [[01 00 00 00 ][02 00 0f 02 ][00 00 00 00000000 02 00 00 00 ][01 00 00 00 02 00 00 00 ]] I also take care about a mask.
    Embed
/**
 * Copyright yonatan ( http://wonderfl.net/user/yonatan )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/wsTO
 */

// forked from yonatan's it's a knot
// forked from keim_at_Si's Metallic soft cube
package {
    import flash.display.*;
    import flash.events.*; 
    import flash.utils.*;
    import flash.text.*;
    
    import com.adobe.utils.*;
    import com.bit101.components.*;

    public class main extends TextArea {
        private var asm:AGALMiniAssembler = new AGALMiniAssembler();
        
        function main() {
            var a:String = <agal><![CDATA[
mul vt0, vt0, vc9.yyy
add v1,  vt0, vc9.yyy
]]></agal>;

            var b:String = <agal><![CDATA[
mul vt0.xyzw, vt0.xyzw, vc9.y
add v1,  vt0, vc9.y
]]></agal>;

            width = height = 465;
            var aa:ByteArray = asm.assemble("vertex", a);
            var bb:ByteArray = asm.assemble("vertex", b);
            
            var i:int;
            var same:Boolean = true;
            if(aa.length == bb.length) {
                for(i=0; i<aa.length; i++) {
                    text += aa[i] + "\t" + bb[i] + "\n";
                    same &&= aa[i] == bb[i];
                }
                text = 
                    "Shader A:" + a + 
                    "\nShader B:" + b + 
                    "\n" + (same ? "Compiled shaders are identical" : "Compiled shaders differ") + "\n" +
                    text;
            }
        }
    }
}