Question

I try to make a shader for Starling that will invert alpha (a kind of mask) of a Starling sprite :

var fragmentProgramCode:String =
// Get texture
"tex ft1, v0, fs0 <2d,linear,nomip>" + "\n" +
// make 1 - pixel alpha
"sub ft1.w, fc0, ft1.w" + "\n" +
// Send result
"mov oc, ft1"

This code works With fc0 = 1 but I don't realy understand why because when I play with fc0 and put into it .5, there is no difference. Where am I wrong ? How to properly do 1 - pixel alpha ?

Was it helpful?

Solution

The right code was : "sub ft1.w, fc0.x, ft1.w" + "\n" +

I must use fc0.x because the alpha amount was pass to fragment shader through the first entry (fc0 have 4 components, x y z and w).

You will find final filter here : https://gist.github.com/simsoft/5169715

Alpha inverter filter

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top