Hi,
Welcome to the forum then!
Actually rendering a lot of lights is not a limitation of OpenGL but rather two different methods when doing real time graphics : Forward rendering (classic one) and Deferred Rendering. It’s really well explained on this thread :
If you go on the GitHub repo of Processing 4 (the next release which is in alpha), they say this in the changes.md
file :
Processing 4.0 alpha 2
Revision 1271 - 15 September 2020
Several fixes for this round, plus working on the guts quite a bit to prepare for newer/faster/better rendering methods.
So hopefully they are going to change that!
And when you look at the GLSL code for the basic shading, you see that it’s forward rendering limited to 8 lights :
// processing4/core/src/processing/opengl/shaders/LightVert.glsl
for (int i = 0; i < 8; i++) { // <<= HERE
if (lightCount == i) break;
vec3 lightPos = lightPosition[i].xyz;
bool isDir = lightPosition[i].w < one_float;
float spotCos = lightSpot[i].x;
float spotExp = lightSpot[i].y;
vec3 lightDir;
float falloff;
float spotf;
if (isDir) {
falloff = one_float;
lightDir = -one_float * lightNormal[i];
} else {
falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]);
lightDir = normalize(lightPos - ecVertex);
}
//... they compute basic phong lighting
}
(processing4/core/src/processing/opengl/shaders/LightVert.glsl at main · benfry/processing4 · GitHub)
I did a test by changing the 8
value in this shader and modifying the MAX_LIGHTS
variable inside the processing4/core/src/processing/opengl/PGL.java
source file to 32 and compiled processing4 with ant. With this program I was able to have more than 8 lights :
ArrayList<PVector> lights;
float range = 500;
float r = 0;
float lightsIntensity = 10;
float rRange(float range) {
return random(-range, range);
}
void setup() {
size(500, 500, P3D);
lights = new ArrayList<PVector>();
for (int i = 0; i < 32; i++) {
lights.add(new PVector(rRange(range), rRange(range), rRange(range)));
}
}
void draw() {
background(0);
for (int i = 0; i < 32; i++) {
PVector light = lights.get(i);
pointLight(lightsIntensity, lightsIntensity, lightsIntensity, light.x, light.y, light.z);
// Visualize light
stroke(255);
point(light.x, light.y, light.z);
}
camera(cos(r) * 500, 100, sin(r) * 500, 0, 0, 0, 0, 1, 0);
// shininess(10.0);
fill(255);
noStroke();
sphere(100);
r += 0.01;
}
But as you noticed, we get wrong results because the light calculation doens’t handle too much lights and the colors overflow or something
Anyway fun experiment!