Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3783574
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:14:43+00:00 2026-05-19T11:14:43+00:00

I am trying to implement multiple lights in my shader but I have trouble

  • 0

I am trying to implement multiple lights in my shader but I have trouble to fill the uniform with my light data.

My vertex shader:

attribute vec3 aVertex;
attribute vec3 aNormal;
attribute vec2 aTexture;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat4 uNMatrix;

uniform vec3 uAmbientColor;
uniform vec3 uPointLightingLocation[16];
uniform vec3 uPointLightingColor[16];

varying vec2 vTexture;
varying vec3 vLightWeighting;

void main(void) {
    vec4 mvPosition = uMVMatrix * vec4(aVertex, 1.0);
    gl_Position = uPMatrix * mvPosition;
    vTexture = aTexture;

    int i;
    for (i = 0; i < 16; i++) {
        vec3 lightDirection = normalize(uPointLightingLocation[i] - mvPosition.xyz);
        vec4 transformedNormal = uNMatrix * vec4(aNormal, 1.0);
        float directionalLightWeighting = max(dot(transformedNormal.xyz, lightDirection), 0.0);
        if (i == 0) {
            vLightWeighting = uAmbientColor + uPointLightingColor[i] * directionalLightWeighting;
        } else {
            vLightWeighting = vLightWeighting * (uAmbientColor + uPointLightingColor[i] * directionalLightWeighting);
        }
    }
}

Code that shows only the latest light:

for (var light in this.lightsDirection) {
    gl.uniform3fv(this.shaderProgram.pointLightingLocationUniform, this.lightsDirection[light]);
    gl.uniform3fv(this.shaderProgram.pointLightingColorUniform, this.lightsColor[light]);
}

As the uniform uPointLightingLocation is a vec3 array with the size of 16, I thought that it would be possible to pass the complete array to the uniform, but I have no working solution.

When I try to pass the complete array this.lightsColor (without the index) I see no light at all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T11:14:43+00:00Added an answer on May 19, 2026 at 11:14 am

    gl.uniform3fv expects a flattened array of floats. Also, you are calling it multiple times with the same uniform location. So, the last one wins. Imagine that uniform3fv is a low-level copy command, and you give it (destination, source). It just copies a buffer from one place to another.

    Assuming your example has only 3 lights, you could assign the location uniform this way:

    var locations = [
      1.0, 0, 0,
      0, 1.0, 0,
      0, 0, 0
    ];
    gl.uniform3fv(shaderProgram.pointLightingLocationUniform, locations);
    

    I would also recommend using a more simple shader when you are debugging problems like this. With something like the following in your vertex shader:

    for (int i = 0; i < 3; i++) {
      vColor += uPointLightingLocation[i];
    }
    

    And fragment shader:

    gl_FragColor = vec4(vColor, 1);
    

    Then, if your polygons are yellow you know it is working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to implement pagination using multiple searching criteria. Supposed I Have student table.
I am trying to implement a multiple choice quiz and will want to store
I'm trying to implement thinking-sphinx across multiple 'sites' hosted under a single rails application.
I'm trying to implement an algorithm to search multiple XML files for a certain
I'm trying to implement a SessionState server to allow multiple web servers to share
I'm currently trying to implement a UITableView with a delegate and data source that
I'm trying to implement multiple spinners within one activity, which appears to be working
I'm really novice with ActionScript and Flash/Flex. I'm trying to implement a multiple file
I'm trying to implement a server-client socket program in Java that can support multiple
I am trying to use boost::shared_mutex to implement a multiple-reader / single-writer mutex. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.