Shadows Work To A Good Enough Point


So I finally got shadow maps working thanks to these two tutorials helping me a lot with some of the understanding http://www.rastertek.com/dx11tut40.html https://learnopengl.com/Advanced-Lighting/Shadows/Shadow-Mapping
Also these two books helped me: GL Superbible 7th Ed(ISBN-13: 978-0672337475 | ISBN-10: 9780672337475) and Real Time Rendering Third Edition (ISBN: 9781439865293)

Anyways, now I get how shadow mapping works.

Basically, you get that 2d buffer I had mentioned in one of my previous posts that holds the Z value of all things in the scene from the PoV of the light so aka just render on a modern GAPI and store teh resultant Z buffer as if you're doing 3d, you're highly likely to be using one.
Then, you take that into your normal render pass and calculate the position of a given vertex from both the camera / proj and the light's perspective / proj (again). In your fragment, pixel, shader that decides what color a texel should be or part of the pipe that does this, you simply use the vertex when looked at the light's xy / w to get the actual projected coordinate (if using GL or DX you'll want to divide both y and x by 2 and then add .5 as you can't have negative texture coordinates unless your texture samples -1 to 1 instead of 0 to 1!!!).

Using that coordinate, you sample from the depth texture that was obtained from the pass that came sometime before the pass that's drawing now which will fill in shadows / normal color for the world. Using the sampled depth value, you now use the projected coordinate of Z of the vertex when looked at from teh camera's pov so Z / W to then compare if that is less than the stored, sampled, depth value.
Also, it does appear that you really do have to subtract some tolerance value from the Z / W light's depth value (not the sampled one) to actually get a result that starts to be believable.

Anyways, if that last comparsion IE light Z / W  - tolerance < stored depth value, you will light the current texel and else, you just have a shadowed area!!! Pretty simple but this is obviously going to get costy as you're literally doing atleast one comparision on every texel which can add up quickly and kill your perf.

So now i'll get into potentially "new news" for people who read those tutorials before I basically wrote what they have verbatim.

I had said in this video https://twitter.com/AndrewNReinke/status/1448645912952119301 that I might just end up drawing a shadow under the boat to do what is currently happening with the dynamic shadow code to save perf. I still think that's ultimately what i'll end up doing but the reason why I don't want to do this is because there's still quite a bit that I am unsure of in terms of what the game will have in the near future. What I mean by this is that if I add some big piece of geometry that does indeed obscure a lot of the incoming light, i'd like to just have that "auto shadow" so I can quickly iterate despite trading off lots of perf / beauty for the interm. Still though, i've learned that iteration is key to actually making something fun (atleast to me) so i'd reccomend it to anyone who reads this blog!

Please let me know what your thoughts are on the shadows / game thus far and I hope you have an awesome day :)

Files

Funmi_Zip.7z 96 kB
Oct 14, 2021
Funmi_Windows.exe 231 kB
Oct 14, 2021
ChallengeList.txt 3 kB
Oct 03, 2021
English_Controls.txt 2 kB
Oct 03, 2021
日本語_Controls.txt 2 kB
Oct 03, 2021
日本語_README.txt 935 bytes
Sep 16, 2021
English_README.txt 1 kB
Sep 16, 2021

Get Funmi

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.