lwjglgamedev/lwjglbook-leg

Light Angle Renders Incorrectly When Object is Rotated

A68NPQR572SNR opened this issue · 5 comments

I don't know if this only happens when I run the code, but when a GameItem's rotation is modified, the light angle renders incorrectly (I tested it using a sphere made up of triangles so that the problem was more obvious). When the camera changes rotation the light direction renders fine, but if you make a GameItem constantly shift rotation the light seems to wobble up and down the object (depending on the position of the light), creating an undesired effect that makes the scene less realistic since one item has a different lighting than the rest. This problem is the same for all types of lights discussed in the book, but it doesn't affect the shadows. I know that the chapters after lighting was implemented did not involve any rotation, so it doesn't affect the examples in the book. However, if others try to use your shaders and rotate their GameItems, their programs will be flawed as well. I hope that you can fix this problem since I don't possess the LWJGL knowledge to fix this problem myself - I can only suspect that the problem has to do with the vertex shader and the fragment shader, but not the exact location of the problem itself.
Regardless of that, I think that your book is very well-written and explains LWJGL better than anything else on the internet. Thank you for taking the time to put something like this together. I hope you understand the cause of this problem more than I do.

I will check this. Maybe normals are being affected by rotation (and they shouldn't). Can you please clarify if this happen in chapters that introduce light or it happens in later chapters?

Thanks in advance.

The problem occurs throughout every chapter since light is introduced. The tests I conducted on the earlier chapters involving light (chapters 10, 11, and 12) and the tests I conducted on later chapters (26, 27) produced the same results, so I don't think the error only affects the earlier chapters and not the later chapters.

I've tested with a sphere with te source code of chapter 11 and cahpter 27. In chapter 27 I've used a directional light and a point light. For chapter 11 I've set up just a point light. When I rotate the sphere I'm not able to see the effects you mention.

Can you please post the test sample you are using?

Thanks in advance.

I'm sorry that I brought up this problem since I've now discovered that it was an internal problem that didn't have to do with the code. I apologize for wasting your time and angry that I've wasted a larger portion of my own, trying to solve the problem thinking that it had to do with the shaders.
Thank you for the help, however, since I never considered that the problem might not have had to do with the shaders until you tested it and the results turned out fine.

You can close this issue anytime you'd like since the problem has nothing to do with the source code.

It's ok. Thanks for reading the book