lwjglgamedev / lwjglbook-leg

Source code of the chapters of the book 3D Game Development with LWJGL 3
https://ahbejarano.gitbook.io/lwjglgamedev/
Apache License 2.0
560 stars 202 forks source link

Slow FPS / Not loading with very few Point Lights #28

Closed TomBlakley closed 7 years ago

TomBlakley commented 7 years ago

Please note that I'm using a laptop instead of my computer, So it may take more lights to slow it down / crash for you. But when I add this code it plays around 30FPS (using chapter 26) This is inside setupLights method.

//Point Light PointLight[] pointLightList = new PointLight[5]; for(int i = 0; i < 5; i++) { lightIntensity = 1.0f; Vector3f col = new Vector3f(1.0f, 1.0f, 1.0f); Vector3f pos = new Vector3f(0 + i, 0, 0 + i); PointLight pointLight = new PointLight(col, pos, lightIntensity); PointLight.Attenuation att = new PointLight.Attenuation(0.0f, 0.0f, 1.0f); pointLight.setAttenuation(att); pointLightList[i] = pointLight; } sceneLight.setPointLightList(pointLightList);

Also when creating more than 5, The game give's a Null Pointer Exception.

lwjglgamedev commented 7 years ago

Cascaded Shadow Maps impose an overhead. I have two laptops, and the one that uses an embedded Intel GPU crawls trying to render the sample. (Bytheway, the sample is by not means optimized, the purpose is to explain the concepts).

Regarding the point lights, the maximum numbe of point lights is defined in several constants, also in the shaders. The shaders only supprt 5 point lights. You should change that in the shader in order to fix that exception.

Hope it helps.