Shaders Sprite alpha gradient

Ricardo

Member
Hi there,

I'm trying to code a shader to apply an alpha gradient into a sprite. With gradient I mean: alpha will be 1 (100%) in a determined point/corner of the sprite that I'll select, and then it'll fading out into the direction/angle I choose.

I already found a simple shader that almost do what I need, but the alpha fade only works in one direction (left to right).

Here's the code:
Code:
[Fragment]
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
{
  vec4 c = texture2D( gm_BaseTexture, v_vTexcoord );
  float brightness = (c.r + c.g + c.b) / 3.0;
  vec4 blend = mix(v_vColour,vec4(1.0,1.0,1.0,v_vColour.a),brightness);
  gl_FragColor = blend * vec4(c.rgb,c.a*(1.0 - brightness));
}
Any tip or comment will be much appreciated.
Thank you in advance.
 
Top