Appreciate the response! I did get it working, but the performance impact is still pretty brutal. I was getting about 120 fps with the previous technique, and now it's down to about 70fps. I'm basically rendering each sprite twice (one with a normal image, and one with a secondary image) so I'm not sure this will be viable as I scale up the number of sprites. Since the targetTexture is only input to a shader down the road, it sounds like my best option will be to create a separate texture to pass down into the shader separately, which I was hoping to avoid.
Is this type of performance impact expected when rendering a large number of sprites via shaders? (I'm not experienced enough with shaders / SFML to be sure)For anyone who does want this logic snippet:
full disclosure this wasn't heavily testedsprite.setPosition(sf::Vector2f(x, y));
sprite.setRotation(r);
shader->setUniform("background", background->getTexture());
auto rs = sf::RenderStates();
rs.blendMode = sf::BlendNone;
rs.shader = shader;
rs.texture = sprite.getTexture();
targetTexture->draw(sprite, rs);
w/
uniform sampler2D texture;
uniform sampler2D background;
void main()
{
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
if (pixel.a != 0) {
gl_FragColor = pixel;
} else {
vec2 background_size = textureSize2D(background, 0);
vec2 coords = gl_FragCoord.xy/background_size;
gl_FragColor = texture2D(background, coords);
}
}