Hi there,
I've got one Sprite which loads an spritesheet and a shader, and it's texture changes on animation
by seting an intrect.
So when rendering, I calculate the new intrect for the animation and then draw it to rendertarget (which is renderwindow by now) like this:
window->draw(*this, &shader);
This is the code to my shader:
uniform vec2 lightpos;
uniform vec3 lightColor;
uniform float screenHeight;
uniform vec3 lightAttenuation;
uniform float radius;
uniform sampler2D tex;
void main()
{
vec2 pixel=gl_FragCoord.xy;
pixel.y=screenHeight-pixel.y;
vec2 aux=lightpos-pixel;
float distance=length(aux);
float attenuation=1.0/(lightAttenuation.x+lightAttenuation.y*distance+lightAttenuation.z*distance*distance);
vec4 color=vec4(attenuation,attenuation,attenuation,1.0)*vec4(lightColor,1.0);
gl_FragColor = color * texture2D(tex,gl_TexCoord[0].st);
}
and how I load it to sf::Shader:
sf::Shader shader; // member of my sprite holding class.
shader.loadFromFile("assets/shaders/lightfx.frag", sf::Shader::Fragment);
shader.setParameter("lightpos", sf::Vector2f(150.f, 50.f));
shader.setParameter("lightColor", sf::Vector3f(255.f, 255.f, 255.f));
shader.setParameter("screenHeight", static_cast<float>(window->getSize().y));
shader.setParameter("lightAttenuation", sf::Vector3f(50.f, 25.f, 15.f));
shader.setParameter("radius", 500.f);
shader.setParameter("texture", sf::Shader::CurrentTexture);
The lighting is fixed by now cause I'm still developing lighting system but this should work.
I want to know why it doesn't seem to abe applied the shader to my sprite.
Am I doing something wrong?
EDIT: Forgot to comment that the output from this is just sprite being as black color square. and If i change the attenuation to 0, it shows the lightColor square, but I want it to "diffuminate" over the sprite.
Thanks!