Hey, I don't feel like I'm doing shader's the correct way.
This is the shader;
uniform vec2 frag_LightOrigin;
uniform vec3 frag_LightColor;
uniform float frag_LightAttenuation;
void main()
{
vec2 baseDistance = gl_FragCoord.xy;
vec2 distance = frag_LightOrigin - baseDistance;
float linear_distance = length(distance);
float attenuation = 1.0 / (frag_LightAttenuation * linear_distance +
frag_LightAttenuation * linear_distance);
vec4 lightColor = vec4(frag_LightColor, 1.0);
vec4 color = vec4(attenuation, attenuation, attenuation, 0.75) * lightColor;
gl_FragColor = color;
}
The following is in the draw-function of all particles;
rTexture.clear(sf::Color(0, 0, 0, 255));
for (size_t i = 0; i < particles.size(); i++)
{
shader.setParameter("frag_LightOrigin", particles.at(i)->position);
shader.setParameter("frag_LightColor", particles.at(i)->color);
shader.setParameter("frag_LightAttenuation", particles.at(i)->strength);
rTexture.draw(painting, states);
}
rTexture.display();
(painting is a sf::RectangleShape covering the whole screen)
Currently, I'm drawing each new state of the shader on a sf::RectangleShape(painting) for as many lightsources (particles).
This makes the whole game lag so much when there's many lights.
The game works and all, but I feel like something is wrong.
Is there a way of drawing each particle on the same shape or something?