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

Shadow map question #32

Closed mudlee closed 7 years ago

mudlee commented 7 years ago

Hi. As I mentioned in the last few cases, I write my "engine" using your and lots of other tutorials beside each other, to avoid copy-and-pasting. I watch and read everything and try to implement myself.

However, shadows are tricky. On the attached images you can see my problem. You can see my shadow map at the top left (it looks good), and I see no shadows :( Tried different ortho settings, light positions, turning spot and point lights off, etc.

Could you give me some starting point where should I search for the bug, because I rewatched, reread everything at least 10 times, and everything in the code looks good.

shadowthing shadowthing2

nickclark2016 commented 7 years ago

Can you post a link to your code? Your shader code for rendering shadows looks like it works fine, but I would need to see code for the rendering of entities and their shaders to give any help!

mudlee commented 7 years ago

Yeah, here it is, thanks for your help! https://bitbucket.org/mudlee/intermettoengine/

If you don't have bitbucket account, I can upload to the drive

nickclark2016 commented 7 years ago

Not 100% following the code, but I don't see where you are setting the offset of the shadow map into world coordinates. Try looking at ThinMatrix's tutorial on YouTube or the shadow tutorials here.

mudlee commented 7 years ago

Did that :) Also checked the red book and learnopengl.com, several times. So what I do, I create the shadow map as you can see on the images. In the vertex.glsl I create the the vertex's lightviewspace coordinate using the transformationMatrixInstanced (which is actually the modelmatrix), pass through the shader chain into the fragment.glsl. There, I just use the shadowMap texture for sampling by the fs_in.vxLightSpacePosition.xyz;

lwjglgamedev commented 7 years ago

I have not time to review your code, but I may give sou some ideas. Your depth map is being generated correctly. Maybe you are not passing the depth texture correctly to the dsahder that renders your scene. If you are using several texturews, review is you are using correctly texture units.

Hope it helps.

mudlee commented 7 years ago

Had some texture issues, because NanoVG uses texture0, and I had not specified the correct texture bank for the depthsampler. But... I still don't have shadows. Keep searching, try to update this issue as a reference for anyone else facing with this.

mudlee commented 7 years ago

OK, after hours debugging, got shadows OMG. If you have the same problem, watch out for these: