Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Transparency Gradient  (Read 3620 times)

0 Members and 1 Guest are viewing this topic.

Megatron

  • Newbie
  • *
  • Posts: 22
    • View Profile
Transparency Gradient
« on: November 17, 2010, 07:48:59 pm »
I was wondering if it's possible to have a sprite who's tranparency changes from side to the other? For instance, I have a sprite that I want to be fully visible at the top but then fade to transparent by the time I hit the bottom. Would you have to use shaders for this?

Thanks

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Transparency Gradient
« Reply #1 on: November 17, 2010, 08:28:19 pm »
What if you just set the image's pixel's transparency by hand? sf::Sprite::GetImage() gives you the image, and then you can modify it's pixels. :)

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Transparency Gradient
« Reply #2 on: November 17, 2010, 08:31:51 pm »
You can create a generic mask/layer/whatever it is called image for it. You just render it above the image you want and set the global color of the sprite. Never tried but I think it should work.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Xorlium

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
Transparency Gradient
« Reply #3 on: November 18, 2010, 01:30:11 am »
No, no, what (s)he is asking is different from what you guys answered.

What you want is a perfect example on when to use shaders.

The shader should be something like this (I'll be overly verbose for clarity. You might want to do it all in a single line)

Code: [Select]

uniform sampler2D current; //set this to sf::Shader::CurrentTexture as explained in the tutorials

void main()
{
  vec2 thisposition = gl_TexCoord[0].xy;
  float alpha = thisposition.y;  //this is the y coordinate, from 0 to 1
  vec4 pixel = texture2D(current, gl_TexCoord[0].xy);
  pixel.a = alpha;
  gl_FragColor = pixel;
}

 

anything