Simple AGAL Shader Testbed

This is a very quick testbed designed to help write Flash AGAL shaders.

If you don’t know what a shader is you should read my Shader Post.

[swf src=”http://northwaygames.com/wp-content/uploads/ShaderTest.swf” params=”wmode=direct” version=11 width=600 height=600]You must have Flash 11 for this to work[/swf]

You can test it out by pasting in my “swaying grass” pixel shader:

sub ft3, v1.y, fc1.y //offset = 1-y
pow ft3, ft3, fc2 //offset = offset^3
mul ft3, ft3.y, fc3 //offset = sin(count)*offset
mul ft3, ft3, fc4 //offset *= .3
add ft2, v1, ft3 //texturePos.x += offset
tex ft1, ft2, fs0 <2d,linear,repeat,mipnearest> //pixel = texture(texturePos)
mov oc, ft1 //return(pixel)

If you replace the Pixel/Fragment shader with the above code and hit the “Render” button you’ll see the grass sway. See my Pixel Shader Example post for a full description of this AGAL code.

The (hastily written) source is here: ShaderTestBed.

And you can download the .swf Here.

Comments

8 responses to “Simple AGAL Shader Testbed”

  1. […] You can see this shader in action over in my shader sandbox. […]

  2. Paul Avatar
    Paul

    Nice.. but it doesn’t work, the grass doesnt move and the page says that the wmode is wrong.

    1. Colin Northway Avatar
      Colin Northway

      It’s not embedded in the page. You have to download the swf and play it localy.

      1. Franklyn Avatar
        Franklyn

        Is there an error in TriangleMesh.as ?

        line 250 is mVertexBuffer.uploadFromVector(vertexData.data, 0, mTriangles.length);

        but i think it should be

        mVertexBuffer.uploadFromVector(vertexData().data, 0, mTriangles.length);

        1. dialectric Avatar
          dialectric

          I’m trying to convert the example from Box2d to Nape and am getting compiler errors related to TriangleMesh.as – not sure if it is the new version of starling or compiling for Flash Player 11.6, but there are several lines throwing errors.

  3. […] I’m going assume you have the standalone flash player. But you will need that if you don’t have it. This example is going to use my simple Shader Testbed which you can download from this post. […]

  4. Kyle Avatar
    Kyle

    it works for me! really cool stuff.
    thanks man! got a lot from your tuts.

  5. Kyle Avatar
    Kyle

    a few questions:
    > for vertex shader code:
    m44 vt0, va0, vc0
    mov v0, va1
    mov v1, va2
    mov op, vt0
    1, where do the va0 / vc0 / va1 and va2 values come from?
    2, here you set va1 to v0, but i think it’s not used in fragment shader code? why we need to set this value?

    > for fragment shader code:
    sub ft3, v1.y, fc1.y
    pow ft3, ft3, fc2
    mul, ft3, ft3.y, fc3
    mul ft3, ft3, fc4
    add ft2, v1, ft3
    tex ft1, ft2, fs0
    mov oc, ft1
    3, i think in v1, it’s texture position value, and this value is passed from va2 in the vertex shader code, but how do you know the position is stored in va2 but not in va0 / va1 etc?
    4, why need to pow the y value and do sin(count)?
    emmm… i think 0.3 is used for easing the swaying action.
    thank you very much! and sorry for my bad English.

Leave a Reply

Your email address will not be published. Required fields are marked *