lwjglgamedev / vulkanbook

Online book which introduces the main concepts required to write graphics games or any other applications using Vulkan in Java by using the LWJGL library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chapter 16 Code has broken lighting

hYdos opened this issue · comments

commented

Describe the bug
Chapter 16 Code has broken lighting

To Reproduce
Steps to reproduce the behavior:

  1. Chapter '16'
  2. Run Main
  3. Move mouse from left to right
  4. See wrong behavior

Expected behavior
Lighting to not move as the camera moves

Screenshots
https://user-images.githubusercontent.com/25501603/235062675-b9160d21-889d-4ec0-bd17-04fcccb91f9d.mp4

Please complete the following information):

  • OS: Windows 11
  • GPU: Nvidia RTX 2070 SUPER
  • Java version 19 (Adoptium)

Additional context
N/A

commented

more updates: this is a very rare bug and ive only had it twice somehow. Not worth fixing

Hi hYdos, I did not have the chance to look at it carefully. But it seems that you experienced a problem of resolution. Sometims due to inevitable acuracies of the shadow map method, some flickering oiccurs (float point incauracies, shadow map resolution, etc..). There are some methods to aleviate this and one of them may be to not recalculate shadow map eachframe (I think this is mentioned in the boook, which by the way is also good for perfomance reasons). In any case, please keep in mind that the goal is not provide a full 3D engine but to show some techniques. Shadows are always a tricky issue that it is very complex to perefectly adress in any situation.

In any case, feel free to contact me about this here or through LWJGL discord channel whenever you want.

commented

I do sadly have to redraw shadows in my scene I do have entities which move around and are all animated thats nonviable. Do you think I can improve on the accuracy in some way? Though I dont see how precision or map resolution would cause the entire shadow to move, I would expect a few pixels or lines to shift

I think, after thinking about the screen shots you posted that the problem may be due to z fighting with the depth map (not tested so pick this with a grain of salt). Thinking out loud, you may have two depth maps, one for static meshes and one for animated ones. You would only recalculate the animated one each frame and pick the minimum value. The drawback is that you need to perform to texture lookups. Anothe approach would be to use a RG image to store depth avlues for those types of meses so you only need to do a texture lookup. You would only render the "G" channel per frame (I don't know if you can just delete one channel). You can maintain the original approach and only recalculate if the animated model has changed (I don't know if such thing is possible in your model). I hope it helps. Another thing that you may play with is with the shadow bias for far models (maybe you need to set up different values per shadow cascade).

As I said, shadows are tricky. I always start to sweat when I found an issue...

commented

any ideas help thanks