0

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 ?

Charles
  • 50,943
  • 13
  • 104
  • 142
Simon Eyraud
  • 2,445
  • 1
  • 20
  • 22
  • Does your shader receive any input in `v0`? The manual states that v0 should be filled with UV first. – Vesper Mar 14 '13 at 13:30
  • I think, FragmentShader from starling automaticaly set : vertex constants 0-3: mvpMatrix (3D), vertex attribute 0: vertex position (FLOAT_2), vertex attribute 1: texture coordinates (FLOAT_2) and texture 0: input texture – Simon Eyraud Mar 14 '13 at 13:54

1 Answers1

0

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

Simon Eyraud
  • 2,445
  • 1
  • 20
  • 22