hardcoremore I want to preserve the alpha of the pixel and I want that all pixels in the texture which have alpha greater than 0 have same color that I set through the filter parameter which in this case is maskColor property of the filter class.
Ah, I see. That’s possible too, and quite straightforward; instead of setting the alpha value you can set the whole RGBA value. Something like this:
override protected function createProgram():Program
{
var vertexShader:String = STD_VERTEX_SHADER;
var fragmentShader:String =
"tex ft0, v0, fs0 <2d, linear> \n" + // read the pixel
"sub ft1, ft0, ft0 \n" + // fill ft1 with zero
"sge ft0.w, ft0.w, ft1.w \n" + // set the alpha to 1 if greater than zero
"mul oc, fc1, ft0.wwww" // multiply by fc1 to get the final pixel
return Program.fromSource(vertexShader, fragmentShader);
}
The last line has changed. Instead of copying ft0
it is using the alpha value, w, which has just been set to 0 or 1, to multiply by fc1
the supplied mask colour. You will need to add this to beforeDraw:
context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 1, maskColour)
The '1' corresponding to the 1st constant fc1
.