PDA

View Full Version : Getting a larger array of structs in my fragment shader?



DragonautX
03-31-2017, 01:23 PM
I was trying Learn OpenGL's Multiple Lights (https://learnopengl.com/#!Lighting/Multiple-lights) tutorial. For multiple point lights, it uses a struct called PointLight in the fragment shader, and makes a uniform array of PointLight to be accessed by the .cpp program.

When I tried it out, I found that certain array sizes caused the program to crash, with no error appearing. I shortened the fragment shader code to the one below to try out different array sizes.


#version 330 core

out vec4 color;

struct PointLight {
vec3 position;

float constant;
float linear;
float quadratic;

vec3 ambient;
vec3 diffuse;
vec3 specular;
};

uniform PointLight pointLights[5];
//array of size 4 works, array of size 5 crashes program

void main()
{
vec3 testPositionValue = pointLights[3].position; //made this assignment
//to make sure pointLights uniform stays existent

vec3 result = vec3(0.4); //default gray to objects drawn
color = vec4(result, 1.0f);
}

Trying it out, an array of PointLight of size 4 works, but size 5 crashes the program. Is there any way to increase the array size without crashing the program? Also, is this max array size normal? I feel like I should be able to code in more point lights than this.