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 8908781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:16:15+00:00 2026-06-15T03:16:15+00:00

How can I reach this light structure in my vertex shader? struct LightInfo {

  • 0

How can I reach this light structure in my vertex shader?

struct LightInfo {
    vec4 Position; // Light position in eye coords.
    vec3 La; // Ambient light intensity
    vec3 Ld; // Diffuse light intensity
    vec3 Ls; // Specular light intensity
};
uniform LightInfo Light;

I tried:

shaderProgram.Light = gl.getUniformLocation(shaderProgram, "Light");

which compiles, but when I try to insert some value like:

gl.uniform4f(
    shaderProgram.Light.Position,
    parseFloat(document.getElementById("lightPositionX").value),
    parseFloat(document.getElementById("lightPositionY").value),
    parseFloat(document.getElementById("lightPositionZ").value),
    0.0
);

It breaks completely. How would one send this position data into a shader structure?

  • 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-06-15T03:16:16+00:00Added an answer on June 15, 2026 at 3:16 am

    you must get a location for each base type. In your example

    struct LightInfo {
        vec4 Position; // Light position in eye coords.
        vec3 La; // Ambient light intensity
        vec3 Ld; // Diffuse light intensity
        vec3 Ls; // Specular light intensity
    };
    uniform LightInfo Light;
    

    Means you need

    var lightPosLoc = gl.getUniformLocation(program, "Light.Position");
    var lightLaLoc  = gl.getUniformLocation(program, "Light.La");
    var lightLdLoc  = gl.getUniformLocation(program, "Light.Ld");
    var lightLsLoc  = gl.getUniformLocation(program, "Light.Ls");
    

    If you have arrays you’d need locations for each field of each array as in

    struct LightInfo {
        vec4 Position; // Light position in eye coords.
        vec3 La; // Ambient light intensity
        vec3 Ld; // Diffuse light intensity
        vec3 Ls; // Specular light intensity
    };
    uniform LightInfo Lights[2];
    
    var light0PosLoc = gl.getUniformLocation(program, "Lights[0].Position");
    var light0LaLoc  = gl.getUniformLocation(program, "Lights[0].La");
    var light0LdLoc  = gl.getUniformLocation(program, "Lights[0].Ld");
    var light0LsLoc  = gl.getUniformLocation(program, "Lights[0].Ls");
    var light1PosLoc = gl.getUniformLocation(program, "Lights[1].Position");
    var light1LaLoc  = gl.getUniformLocation(program, "Lights[1].La");
    var light1LdLoc  = gl.getUniformLocation(program, "Lights[1].Ld");
    var light1LsLoc  = gl.getUniformLocation(program, "Lights[1].Ls");
    

    And arrays of arrays etc.

    struct LightInfo {
        vec4 Positions[2]; // Light positions in eye coords.
        vec3 La; // Ambient light intensity
        vec3 Ld; // Diffuse light intensity
        vec3 Ls; // Specular light intensity
    };
    uniform LightInfo Lights[2];
    
    var light0Pos0Loc = gl.getUniformLocation(program, "Lights[0].Positions[0]");
    var light0Pos1Loc = gl.getUniformLocation(program, "Lights[0].Positions[1]");
    var light0LaLoc   = gl.getUniformLocation(program, "Lights[0].La");
    var light0LdLoc   = gl.getUniformLocation(program, "Lights[0].Ld");
    var light0LsLoc   = gl.getUniformLocation(program, "Lights[0].Ls");
    var light1Pos0Loc = gl.getUniformLocation(program, "Lights[1].Positions[0]");
    var light1Pos1Loc = gl.getUniformLocation(program, "Lights[1].Positions[1]");
    var light1LaLoc   = gl.getUniformLocation(program, "Lights[1].La");
    var light1LdLoc   = gl.getUniformLocation(program, "Lights[1].Ld");
    var light1LsLoc   = gl.getUniformLocation(program, "Lights[1].Ls");
    

    etc…

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

Sidebar

Related Questions

I have a service in an application, and I can reach this service from
I have a file that I can reach by pidl via IShellFolder . This
How to make this code work? I don't see how I can reach div
am trying to figure out the max scroll position that the WebView can reach,
In a load test of our PHP based web application we can easily reach
public ActionResult Edit(string param) { } http://localhost/Edit/5,someothervalue,etc How can i reach 'param' from a
I am reading GNU/Linux application programming the 2nd edition ,you can reach what am
My app failed certification because of the 6.5.1 guideline: The application can reach a
I received a requirement and I'm totally lost, I hope some1 can light me.
I am wondering how come I can reach inner class directly from outer type

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.