Hello there!
Yesterdy I checked out the
radial gradient shader that appeared on the wiki recently, because I wanted to use this effect in a little project of mine. While I was browsing the code I wondered why the code is so complicated. You have to specify a center, a radius and the windows height; all in screen coordinates! So I thought there has to be an easier way using variables that are already defined in the shader, like texture coordinates.
It turns out it's not that easy. I set up a
sf::CircleShape with a size, a color, a position and a gradient fragment shader. Something was wrong with the texture coordinates though. When I set the output color to
gl_TexCoord[0].xy the output was always black for all fragments. Debbuging into the code of
sf::Shape it turns out the texture coordinates are
only calculated properly if m_textureRect is set. So I set the texture rect to
sf::Int(0, 0, size, size) and the texture coordinates in the shader turned white, meaning there was another problem. I debugged a little further and remembered that SFML uses non-normalized texture coordinates. Since I don't have a texture applyed
sf::Texture::bind doesn't get called and
the texture coordinates are not being converted. If I devide the coordinates by the shapes size in the shader everything works as expected.
All of that seems quiet hackey to me though. I think we should be able to use the texture coordinates even if the shape has no texture. A lot of effects rely on texture coordinates, especially post processing effects done in the fragment shader, it would be sad if you can't use them with an untextured shape. Or is there a reason that this has been left out?
I'd suggest if
m_texture is NULL, set
m_textureRect to the shapes dimensions and apply the texture transform matrix in the draw method or simply set the texture coordinates to normalized coordintes when
m_texture is NULL. I can write a pull request if this gets agreed on.