• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Shaders Multiple light sources in 3D scene

Hey, i want to implement multiple point lights in my 3D scene. This shader code doesn't seem to work. Help me please!
Code:
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;

varying vec3 v_vNormal;
varying vec3 v_vPosition;

uniform float uLightsCount;
uniform vec3 uLightsCol[60];
uniform vec3 uLightsPos[60];
uniform float uLightsRadius[60];

void main()
{
    vec3 col = vec3(1, 1, 1);
    float lighting = 1.0;
    int lightsCount = int(uLightsCount);
    for (int i = 0; i < lightsCount; ++i) {
        vec3 dir = uLightsPos - v_vPosition;
        float radius = 100.0;
        col += uLightsCol;
        float attenuation = max(1.0 - length(dir)/radius, 0.0);
        lighting = ((dot(normalize(v_vNormal), normalize(dir)) + 0.5 * 0.5) * attenuation);
    }
    gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord) * vec4( lighting * col, 1.0);
}
 
Last edited:
Top