Hello guys so im completely new to shaders, im creating a gameengine in C++, and i want to implement lightiing. (Im using SFML as my graphics API) However i need to write my own light shader and i just asked chat gpt and it gave me a littel light shader that kind of works. It does have problems tho:
- It doesn't work dynamicly with the SFML camera.
- I dont know how to positions are getting set? Like i see the gl_FragColor thing which sets the FragColor but the positions are not being set. However for some reason i can modify the position array and the light moves
I can hop in a call with you if you'd like to talk
// light_shader.frag
#define MAX_LIGHTS 255
uniform sampler2D texture;
uniform vec2 lightPositions[MAX_LIGHTS];
uniform float lightRadii[MAX_LIGHTS];
uniform float lightIntensities[MAX_LIGHTS];
uniform vec3 lightColors[MAX_LIGHTS];
uniform int lightAmount;
void main()
{
vec4 finalColor = vec4(0.0, 0.0, 0.0, 1.0);
for (int i = 0; i < lightAmount; i++) {
vec2 fragmentPosition = gl_FragCoord.xy;
vec2 lightPosition = lightPositions[i];
float lightRadius = lightRadii[i];
float lightIntensity = lightIntensities[i];
vec3 lightColor = lightColors[i];
float distanceToLight = length(fragmentPosition - lightPosition);
float intensity = 1.0 - smoothstep(0.0, lightRadius, distanceToLight);
intensity *= lightIntensity;
intensity = clamp(intensity, 0.0, 1.0);
vec4 texColor = texture2D(texture, gl_TexCoord[0].xy);
finalColor += texColor * vec4(lightColor, 1.0) * intensity;
gl_FragColor = finalColor;
}
}