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.
You must have Flash 11 for this to work
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.
Nice.. but it doesn’t work, the grass doesnt move and the page says that the wmode is wrong.
It’s not embedded in the page. You have to download the swf and play it localy.
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);
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.
it works for me! really cool stuff.
thanks man! got a lot from your tuts.
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.