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

  • SEARCH
  • Home
  • 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 6800569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:59:08+00:00 2026-05-26T18:59:08+00:00

I have some GLSL shaders that are compiling correctly, and being successfully attached to

  • 0

I have some GLSL shaders that are compiling correctly, and being successfully attached to a program that links correctly. I have confirmed that other shaders work properly in my program. The strange thing is that the result I see seems to be the same behavior I would get out of default shaders (color, no lighting).

I will paste the source code of both the vertex and fragment shaders, as well as all excerpts from my C++ source code that pertain to the shaders. I will explain in comments any functions or classes that are unique to my program.

My vertex shader (contained in “dirlight.vs”)

uniform int lightcount;
uniform vec4 lightdirs[];
uniform vec4 lightdifs[];
uniform vec4 lightambs[];
uniform vec4 lightposs[];

void main()
{
    vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
    vec4 diffuse = vec4(0.0, 0.0, 0.0, 0.0);
    for(int i = 0; i < lightcount; i++)
    {
        //Adding the diffuse term multiplied by gl_Color for each light.
        //There should be no color (0,0,0,0) if the lights are null
        diffuse += lightdifs[i] * max(dot(normal, normalize(lightdirs[i])), 0.0) * gl_Color;
    }

    gl_FrontColor = diffuse;
    gl_Position = ftransform();
}

My fragment shader (contained in “dirlight.fs”)

void main()
{
    gl_FragColor = gl_Color;
}

Excerpt from initialization in C++ main…

//class program manages shaders
Program shaders = Program();
//attach a vertex shader, compiled from source in dirlight.vs
shaders.addShaderFile(GL_VERTEX_SHADER, "dirlight.vs");
//attach a fragment shader compiled from source in dirlight.fs
shaders.addShaderFile(GL_FRAGMENT_SHADER, "dirlight.fs");
//link program
shaders.link();
//use program
shaders.use();

//Program::getUniformLoc(const char* name) grabs the location
//of the uniform specified
GLint sTime = shaders.getUniformLoc("time");
GLint lightcount = shaders.getUniformLoc("lightcount");
GLint lightdir = shaders.getUniformLoc("lightdirs");
GLint lightdif = shaders.getUniformLoc("lightdifs");
GLint lightamb = shaders.getUniformLoc("lightambs");

glUniform1i(lightcount, 2);
GLfloat lightdirs[] = {-1.f, 1.f, 1.f, 1.f,
                       1.f, 1.f, -1.f, 1.f};
glUniform4fv(lightdir, 2, lightdirs);
GLfloat lightdifs[] = {1.f, 1.f, 1.f, 1.f,
                       1.f, 1.f, 1.f, 1.f};
glUniform4fv(lightdif, 2, lightdifs);
glUniform4f(lightamb, 0.4f, 0.4f, 0.4f, 1.f);

Excerpt from main loop in C++ main…

glUniform1f(sTime, newTime);
//This should cause the light directions to rotate around the origin
GLfloat lightdirs[] = {sinf(newTime * 2.f), 1.f, cosf(newTime * 2.0f), 1.f,
                       cosf(newTime * 2.f), 1.f, sinf(newTime * 2.0f), 1.f};
glUniform4fv(lightdir, 2, lightdirs);
  • 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-26T18:59:09+00:00Added an answer on May 26, 2026 at 6:59 pm
    uniform vec4 lightdirs[];
    

    That is not legal GLSL. I can’t explain why your compiler allows compiling (I’m guessing it’s an NVIDIA compiler, right? That of course assumes that you are checking the compilation/link status), but uniform arrays must have a length defined explicitly within the shader. If you want to have variable length arrays, you have to pick a maximum length and bake it into the shader. The shader can read fewer values (a length based on a uniform you pass in), but that’s about it.

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

Sidebar

Related Questions

I have a project that uses GLSL shaders. This project is designed not to
I have some input checkboxes that are being dynamically generated in a $.post callback
I have some UI in VB 2005 that looks great in XP Style, but
We have some input data that sometimes appears with &nbsp characters on the end.
We have some files on our website that users of our software can download.
Have some data in a sybase image type column that I want to use
I have some code that can convert a single color in a template image
Have some users in Liferay 4.4.2 that are currently active, all having valid passwords.
We're a small dev team working with some GLSL that may be too large
I have some problems adding my shader-glsl files from one xcode project to another.

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.