LS/Hi Feathered friends,
I'm trying to get my head around AGAL, for now AGAL is a bit of a fog around my head 😅
I wrote some AGAL code that semi works but I know there is a beter way of doing this.
If you know and would like to share your 2cents that would be really helpful and appreciated. 😀
What I would like to accomplish is "simple". I want to make a filter that I can apply to my game stage that gives the effect of a gradient that loops in a line, a bit like bright pixel traversing a line on a circuit board (Tron style if you will).
What I did so far is; create texture tiles with only 1 of the rgb bytes between 1 and 255 the others on 0.
From a timer I inject an AGAL constant T2 that loops from 0 to 1 in steps of 1/255, 1/32 (slow vs. fast)
I also have a constant T that flips from zero to 1 and back very completed loop t2
I have some constants that I upload to the fragment shader for use of comparison, like -1(for multiplication when <0 ), 0.000001(almost zero) and 1 for subtracting when >1)\
So the idea is that when the fragment shader hits a textel that meets the rgb requirments (00B) for a positive blue pixel it subtracts the rotating/pulsating T2 value and also subtracts the flipping 0 or 1 T constant.
Then it flips the textel into N+ if it is < 0 by MUL -1
If, then, it is >1 it subtracts 1 .
The effect looks reasonable but far from perfect.
For, 1: It seems to have a "hickup"
2: I added the flipping T constant so it wouldnt as if the pixel went to 1 and than reversed direction.
I'm thinking about making a second 1 pixel high texture gradient going from 1 to 255 and then looping the x UV coords to add to the sampled screen coordinate.
I havent done that yet, I came here first... the source of sources.
Static image of screen with gradients is here: https://imgur.com/a/9EoOo2q
Video of end effect is here: https://youtu.be/_f1l-dX9n-8
So here's the code(use the pixelatefilter as base so hence the name ):
Timer in AS3/starling
public var pf:PixelateFilter = new PixelateFilter(1);
public function updateAGAL(e:TimerEvent):void
if (this.pf != null) // if the filter is not null thus exists
this.pf.t2 += this.pftinc2 increase the T2 constant with the increment value
if (this.pf.t2 > 1-pftinc2 ) // if its almost 1
this.pf.t2 = 0; // reset to zero
if (this.pf.t == 0) // flip the T constant
this.pf.t = 1;
this.pf.t = 0;
So thats the timer updating the constants
the AGAL ( I have changed the constants to their values for readablility:
mov ft0, v0 // get the pixel pos into ft0
tex ft1, ft0, fs0<2d, clamp, nearest, mipnone> // sample the color into ft1
ifl ft1.x, 0.0001 // no red in the rgb
ifl ft1.y, 0.0001 // no green in the rgb
ifg ft1.z, 0 // some blue in the rgb (so no black pixels selected)
mov ft2.z, ft1.z // save it
sub ft1.z, ft1.z, var_t (0 or 1) // subtract the flipping between 0 and 1 T const
ifl ft1.z, 0 //if its less than zero
sub ft1.z, 1, ft2.z // subtract the saved value from 1 and put in ft1.z (blue)
sub ft1.z, ft1.z, var_t2 (0 to 1 in steps 1/32) // subtract incrementing value
ifl ft1.z, 0 // if it is < 0 multiply by -1
mul ft1.z, ft1.z, -1
ifg ft1.z, 1 // if it is greater than 1 subtract 1
sub ft1.z,ft1.z, 1