I have tried this simple CustomShader:
class Main extends Sprite {
public function new () {
super ();
var sprite = new Sprite ();
sprite.graphics.beginFill (0xFF0000);
sprite.graphics.drawRect (0, 0, 100, 100);
sprite.filters = [ new ShaderFilter (new CustomShader ()) ];
addChild (sprite);
}
}
class CustomShader extends Shader {
public function new () {
glFragmentSource =
"
uniform sampler2D tex0;
varying vec3 eyeTS;
varying vec2 texCoords;
void main( void )
{
const float plxScale = 0.03;
const float plxBias = -0.015;
// Iterative parallax mapping
vec3 newCoords = vec3( texCoords, 0 );
vec3 eye = normalize( eyeTS );
for( int i = 0; i < 4; ++i )
{
vec4 nmap = texture2D( tex0, texCoords.st );
float height = nmap.a * plxScale + plxBias;
newCoords += (height - newCoords.p) * nmap.z * eye;
}
vec4 glow = texture2D( tex0, newCoords.st ).rgba;
glow *= glow.a;
gl_FragColor = glow;
}
";
super ();
}
But, I got error:
Uncaught Error: Unable to initialize the shader program.
Can some one tell me what’s wrong in my code?