lwjglgamedev/lwjglbook-leg

Issue with point lights and flickering textures

lukewarlow opened this issue · 4 comments

I've been working through the code and find that I'm getting weird behaviour with point lights.

There's 2 main issues, the rendering of the lamp texture is very different to what I would expect. And not shown in this image but visible when running the application when rotating the camera the textures of the cubes flicker to a much brighter state for a couple of frames and then darken again.

I've tried debugging it locally but haven't managed to work it out, so thought I'd reach out.

Originally the lamp would flicker while moving the camera position too and that I found was fixed by loading the point lights before rendering models. But it didn't fully fix my issue.

image

I'd expect the lamp to look more like:

image

GitHub repo with minimal code for reproduction in https://github.com/lukewarlow/point-light-bug (written in Kotlin)

Hi,

I've just uploaded the samnple to have a quick look but it does not run properly: I've got this exception:

Exception in thread "GAME_LOOP_THREAD" kotlin.UninitializedPropertyAccessException: lateinit property staticRenderer has not been initialized at uk.lukewarlow.engine.GameRenderer.cleanup(GameRenderer.kt:39) at uk.lukewarlow.game.Game.cleanup(Game.kt:112) at uk.lukewarlow.engine.Engine.cleanup(Engine.kt:120) at uk.lukewarlow.engine.Engine.run(Engine.kt:36) at java.base/java.lang.Thread.run(Thread.java:833)

In any case, it is very difficult for me to check this in Kotlin (I'm not used to this language). I will try to have a look but I don't have too much spare time. Just some suggestions. Have you tried to use render doc to check what is happening when rendering? Maybe you could give it a try in tne meantime.

Thanks for taking time to have a look, if you don't manage to take a more in depth look that's fine I know it's a long shot anyway.

Unfortunately I'm on macOS so the OpenGL debugging options available to me aren't great, I'm gonna try and setup renderdoc on a Linux machine I have to debug it.

Regarding the error you may need to launch it with -XstartOnFirstThread as a VM option, not sure if that's a macOS only issue or not.

I've managed to fix the original issue I was having with point lights, I was offsetting the light's position after converting it to the correct coordinate system which led to issues. While that was an issue in the repo linked above I'm not sure what was causing the incorrect colouring I must have messed up somewhere when cutting out irrelevant code.

Thanks for taking a look!

Glad to hear that. Good luck with your porting!