Trying to implement Shadow Mapping

For people working on the C++ code.
Liso
Member
Posts: 33
Joined: Thu Feb 06, 2020 10:21
GitHub: 0xLiso
In-game: Liso
Location: Valencia - Spain.
Contact:

Re: Trying to implement Shadow Mapping

by Liso » Post

Andrey01 wrote:
Wed Jan 06, 2021 21:41
I tested out the shadows today and after that I understood why this is currently even "pre-alpha" version. There is my list of discovered bugs/lacks:
And these bugs are only a small subset of them xD.


First of all, THANK YOU for testing it. You make my day :).

Second, Sorry I didn´t push the last changes in to the master branch. Could you try it with the changes I just commit in to the master?
or, you can checkout the "shadowmap" branch.


And I mostly worked in the CSM version, and it's not enabled by default. to enable it go to the all settings menu, search shadows, and enable the "Cascade Shadow Mapping" and the texture in 32 bits:

Something like this:
Image

Most of the bugs you listed are because the lack of code in the non-CSM mode.


About the "ripple" is a well known (but not easy to fix) problem with shadow mapping. The self-shadowing, or shadow acne, and basically it's a problem with precision.

The way to face it is to use a small bias when we build the shadows, but if we use too much bias we can have the opposite problem, the Peter-Panning . In theory this can be fixed using "glDepthOffset" but I don't know how to use it in Irrlicht3D.

The last version has a naive basic implementation of Slope-Scale Depth Bias, that try to minimize that problem.

I want to say I'm sorry for my lack of activity.

And again, Thank you for your help.
Attachments
Settings
Settings
settings.jpg (60.33 KiB) Viewed 2789 times
Liso. - My twitter -

User avatar
Andrey01
Member
Posts: 2574
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Trying to implement Shadow Mapping

by Andrey01 » Post

Liso wrote:Could you try it with the changes I just commit in to the master?
or, you can checkout the "shadowmap" branch.
Ok, I will try out it tonight.
Liso wrote:And I mostly worked in the CSM version, and it's not enabled by default. to enable it go to the all settings menu, search shadows, and enable the "Cascade Shadow Mapping" and the texture in 32 bits:
Hmm, i.e. those shadows that I tested were handled server-side and for that reason it caused so heavy lags? I think their rendering should occur fully client-side.
Liso wrote:I want to say I'm sorry for my lack of activity.
I am currently learning OpenGL bases and then I plan switch to learn GLSL. Maybe I can somehow help with code and fix those bugs, but that's rather long-term process because I need to learn also the part of the engine where the rendering occurs itself.

Liso
Member
Posts: 33
Joined: Thu Feb 06, 2020 10:21
GitHub: 0xLiso
In-game: Liso
Location: Valencia - Spain.
Contact:

Re: Trying to implement Shadow Mapping

by Liso » Post

Andrey01 wrote:
Thu Jan 07, 2021 11:03

Hmm, i.e. those shadows that I tested were handled server-side and for that reason it caused so heavy lags? I think their rendering should occur fully client-side.
Yes. All the shadow mapping is done in the client.
Liso. - My twitter -

User avatar
Andrey01
Member
Posts: 2574
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Trying to implement Shadow Mapping

by Andrey01 » Post

It is strange, the game gets playable only if the shadow map texture size <= 2048 as FPS ranges 56-60 in such case. If I increase it twice (4096), FPS will drop down five times what is not in inverse ratio to the size growth. If one more increase twice (8192), FPS will be somewhere lower 5. Why does FPS so much drop down in the second case? At fact, then in third one it should be equal to 1, not higher.

Also, I`ve noticed nodes of 'plantlike', 'flowingliquid' and 'torchlike' drawtypes are not affected by shadows, they have the same tint as if the dynamic shadows were be disabled.

Liso
Member
Posts: 33
Joined: Thu Feb 06, 2020 10:21
GitHub: 0xLiso
In-game: Liso
Location: Valencia - Spain.
Contact:

Re: Trying to implement Shadow Mapping

by Liso » Post

Yes, the texture size can cause a high impact in the performance and that depends on the GPU because is often limited by fillrate or memory bandwidth.

But the shadows should be good enough with 2048, or even 1024.

About the drawtypes not affected by shadows, probably the shader is wrong ;), I remember I turned off the shadow casting on torchlike.
Liso. - My twitter -

User avatar
Andrey01
Member
Posts: 2574
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Trying to implement Shadow Mapping

by Andrey01 » Post

Hello Liso. Just I'm interested in knowing how your development is going on :)

User avatar
runs
Member
Posts: 3225
Joined: Sat Oct 27, 2018 08:32

Re: Trying to implement Shadow Mapping

by runs » Post

Hola, ¿cómo vas, Liso? ¿Algún progreso? :-)

Liso
Member
Posts: 33
Joined: Thu Feb 06, 2020 10:21
GitHub: 0xLiso
In-game: Liso
Location: Valencia - Spain.
Contact:

Re: Trying to implement Shadow Mapping

by Liso » Post

Hi again!

Thanks for your follow up @runs and @Andrey01
runs wrote:
Sat Mar 13, 2021 12:45
Hola, ¿cómo vas, Liso? ¿Algún progreso? :-)
Andrey01 wrote:
Thu Feb 18, 2021 12:26
Hello Liso. Just I'm interested in knowing how your development is going on :)
I've been quite busy at work the last months, but it's getting better now :)

I checked MT's last dev version and I'm quite excited about the Irrlicht 1.9 addition in to MT. but It forces us to rewrite all the code we have for the shadow mapping.

And the answer is, I hope to be able to start developing it in a couple of weeks.

Thank you.
Liso. - My twitter -

pevernow
Member
Posts: 10
Joined: Sun Oct 04, 2020 04:33
GitHub: pevernow
IRC: pevernow
In-game: pevernow

Re: Trying to implement Shadow Mapping

by pevernow » Post

Well done. This has made a great contribution to the further development of minetest.



But there are still many mistakes. When I turn on VSM, the shadow turns with my eyes.

When VSM is not turned on, the shadow edge has obvious jitter.



When I tried to join a server with high complexity, the frame rate dropped to 5.

(the same computer running minecraft with seus can render 30 frames per second)



But it's done pretty well.

Liso
Member
Posts: 33
Joined: Thu Feb 06, 2020 10:21
GitHub: 0xLiso
In-game: Liso
Location: Valencia - Spain.
Contact:

Re: Trying to implement Shadow Mapping

by Liso » Post

pevernow wrote:
Sat Mar 27, 2021 03:07
Well done. This has made a great contribution to the further development of minetest.



But there are still many mistakes. When I turn on VSM, the shadow turns with my eyes.

When VSM is not turned on, the shadow edge has obvious jitter.



When I tried to join a server with high complexity, the frame rate dropped to 5.

(the same computer running minecraft with seus can render 30 frames per second)



But it's done pretty well.

Yes, the VMS shadow doesn't work at all xD.

Anyway, I've more time now, so the code has been ported to new MT5.4. I'm really excited about new MT's irrlicht and I want to try it with shadows.

Obviously the major problem right now is performance, but I'm sure it's going to be fixed soon ;)
Liso. - My twitter -

deleted c0a803ab

Re: is Shadow mapping desired?

by deleted c0a803ab » Post

This looks already pretty awesome!
Shadows always add a lot of immersion to gaming.
Last edited by deleted c0a803ab on Thu Apr 08, 2021 17:57, edited 1 time in total.

User avatar
DELTA_FORCE
Member
Posts: 165
Joined: Tue Oct 30, 2018 01:26
IRC: DELTA_FORCE
In-game: DELTA_FORCE
Location: ee

Re: Trying to implement Shadow Mapping

by DELTA_FORCE » Post

Heya,
I wanted to provide some feedback so it may hopefully help you on your way with this addition to MT.
1, I really appreciate how it is sane to compile, just like you would compile normally with irrlichtmt.
2, Even with 8192^2 shadow maps, it only uses ~2gb of video memory, which for my case is just fine (gpu utilized is an nvidia rtx 2060)
3, Performance with 4096 and lower is pretty similar to what I get with just plain MT, just with amazing shadows

There still seem to be some kinks to be worked out like artifacting commonly seen with this implementation, or nighttime, or darks, but overall with a bit more work I hope to see this as a viable and future addition to the engine! Great job!
check me out nowhere because i never do anything

User avatar
philipbenr
Member
Posts: 1897
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: robinspi
Location: United States

Re: Trying to implement Shadow Mapping

by philipbenr » Post

Considering Warframe (a fairly comparable game now that they added shadow mapping to their open world) uses around 2.5GB of VRAM in an open world scenario, that's not half bad, especially for a one-person implementation in a bad engine like Irrlicht.

x2048
Developer
Posts: 68
Joined: Mon Feb 15, 2021 22:41
GitHub: x2048

Re: Trying to implement Shadow Mapping

by x2048 » Post

Hi everyone,

Would it help if nodes generate shadows using voxel light while entities use shadow mapping?

Here are some experiments I made with voxel light using a mod in 5.4.0:
sunlight3.jpg
sunlight3.jpg (75.89 KiB) Viewed 2789 times
sunlight2.jpg
sunlight2.jpg (132.07 KiB) Viewed 2789 times
sunlight1.jpg
sunlight1.jpg (143.58 KiB) Viewed 2789 times

User avatar
philipbenr
Member
Posts: 1897
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: robinspi
Location: United States

Re: Trying to implement Shadow Mapping

by philipbenr » Post

Gut reaction, that looks like it would be a higher performing model (just thinking from a black box perspective) than trying to shadow map everything. However, by the looks of the implementation, it wouldn't change based on time of day? Sunlight1 and 3 look good albeit a little dark.

x2048
Developer
Posts: 68
Joined: Mon Feb 15, 2021 22:41
GitHub: x2048

Re: Trying to implement Shadow Mapping

by x2048 » Post

philipbenr wrote:
Sat Apr 10, 2021 18:29
Gut reaction, that looks like it would be a higher performing model (just thinking from a black box perspective) than trying to shadow map everything. However, by the looks of the implementation, it wouldn't change based on time of day? Sunlight1 and 3 look good albeit a little dark.
I implemented a fixed propagation vector -1,-2,-1 (sunlight from north-east) as a proof of concept, but it should be possible to have a dynamic vector. Time of day does not change frequently, so I guess updating blocks can be implemented without burning too many resources.

Darkness is merely due to rough implementation and can be tuned (for example, leaves are still treated solid). I am also playing with how light spreads, which gives higher contrast and darker shades as a result.

I am wondering currently (a) whether there is general interest to maintain this model longer term, or are we going all in on shadow mapping and (b) does it make sense to implement voxel-based shadows short term until shadow mapping is completed.

User avatar
philipbenr
Member
Posts: 1897
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: robinspi
Location: United States

Re: Trying to implement Shadow Mapping

by philipbenr » Post

x2048 wrote:
Sat Apr 10, 2021 19:34
I implemented a fixed propagation vector -1,-2,-1 (sunlight from north-east) as a proof of concept, but it should be possible to have a dynamic vector. Time of day does not change frequently, so I guess updating blocks can be implemented without burning too many resources.
Nice. Thanks for sharing this early in the process.

As for time of day not changing frequently (from the wiki):
The time of day internally uses so-called “millihours” (mh). A millihour is the 1000th part of an hour. 1 millihour equals exactly 3.6 seconds... The time of day is a number between 0 and 23999.
So by default, a Minetest day lasts 20 minutes, meaning time of day number should change 20 times a second, (24,000 values / 20 mins * 60 sec per minute = 20Hz). This can be changed in minetest.conf though, so I'm not sure what implications that has for any implementations of shadows.
Darkness is merely due to rough implementation and can be tuned (for example, leaves are still treated solid). I am also playing with how light spreads, which gives higher contrast and darker shades as a result.
In the case of leaves, do you think adding in the detail of the leaves would cause a significant hit to the performance? I know if you're shadow mapping everything, it shouldn't matter as much (afaik), but I'm not sure about voxel lighting.

I also think that being able to user-tune the "strength" of shadows is a nice feature, if that's in the works.
I am wondering currently (a) whether there is general interest to maintain this model longer term, or are we going all in on shadow mapping and (b) does it make sense to implement voxel-based shadows short term until shadow mapping is completed.
I think that the model that has the best performance / hardware would be the best due to Minetest's user-group. I'm no expert on voxel lights, but from what I know, shadow mapping is a less resource intensive approach depending on implementation. But that's just the teaspoon of knowledge I have, so... ¯\_(ツ)_/¯

Liso
Member
Posts: 33
Joined: Thu Feb 06, 2020 10:21
GitHub: 0xLiso
In-game: Liso
Location: Valencia - Spain.
Contact:

Re: Trying to implement Shadow Mapping

by Liso » Post

x2048 wrote:
Sat Apr 10, 2021 16:38
Hi everyone,

Would it help if nodes generate shadows using voxel light while entities use shadow mapping?

Here are some experiments I made with voxel light using a mod in 5.4.0:
sunlight3.jpg
sunlight2.jpg
sunlight1.jpg
IMHO the screenshots are beautiful. I like it.

Technically speaking, casting shadows for terrain can be disabled without any problem. But as philipbenr said,
philipbenr wrote:
Sat Apr 10, 2021 23:39
So by default, a Minetest day lasts 20 minutes, meaning time of day number should change 20 times a second, (24,000 values / 20 mins * 60 sec per minute = 20Hz). This can be changed in minetest.conf though, so I'm not sure what implications that has for any implementations of shadows.
I don't know if this could be a problem. But it could be tested without any problem, you can download the SM fork and I can help you with the integration, or if you want/need I can download your mod and test it.

And as I said before, great job :)
Liso. - My twitter -

x2048
Developer
Posts: 68
Joined: Mon Feb 15, 2021 22:41
GitHub: x2048

Re: Trying to implement Shadow Mapping

by x2048 » Post

Liso wrote:
Mon Apr 12, 2021 06:48

Technically speaking, casting shadows for terrain can be disabled without any problem. But as philipbenr said,
philipbenr wrote:
Sat Apr 10, 2021 23:39
So by default, a Minetest day lasts 20 minutes, meaning time of day number should change 20 times a second, (24,000 values / 20 mins * 60 sec per minute = 20Hz). This can be changed in minetest.conf though, so I'm not sure what implications that has for any implementations of shadows.
I don't know if this could be a problem. But it could be tested without any problem, you can download the SM fork and I can help you with the integration, or if you want/need I can download your mod and test it.

And as I said before, great job :)
Thank you, Liso. I have published my work at https://github.com/x2048/shadows. It's lazy and quite slow (Lua), so give it some time when you move around.

I don't take time of day into account yet, and if I do, it will most likely be quite inaccurate because my units are nodes 1x1x1m. At least you can get an idea of how it looks together with shadow mapping and maybe share some screenshots :). (I've posted mine here: viewtopic.php?f=3&p=393386#p393386)

Liso
Member
Posts: 33
Joined: Thu Feb 06, 2020 10:21
GitHub: 0xLiso
In-game: Liso
Location: Valencia - Spain.
Contact:

Re: is Shadow mapping desired?

by Liso » Post

philipbenr wrote:
Fri Nov 13, 2020 20:47
The above image got me curious, how are you feeling in regards to partially transparent, or colored things like water or stained glass? I know that keeping a narrow scope at the beginning of a project or part of a project is a good idea and this is certainly more in the light transport realm and less "shadows" I suppose, but I am curious how you feel about it. Being able to handle this would be great, as it would open up a lot of different possibilities for future light expansions in the engine/mods.
But it's in an early alpha version. It has lots of artifacts, the code is awful and it's not optimized in any way.
Isn't that how it always is? ;P It looks great for one person's work.

Just working on it :)

Image


Image
Liso. - My twitter -

User avatar
Krock
Developer
Posts: 4648
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: Trying to implement Shadow Mapping

by Krock » Post

I don't know what to say except... keep up the good work! I hope this will make it into Minetest someday :)
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

deleted c0a803ab

Re: is Shadow mapping desired?

by deleted c0a803ab » Post

Liso wrote:
Thu Apr 15, 2021 11:23
Just working on it :) [...]
Neat!
Last edited by deleted c0a803ab on Thu Apr 15, 2021 21:41, edited 1 time in total.

User avatar
philipbenr
Member
Posts: 1897
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: robinspi
Location: United States

Re: is Shadow mapping desired?

by philipbenr » Post

Liso wrote:
Thu Apr 15, 2021 11:23
Just working on it :)

[ images ]
Very nice looking indeed. How does it work if you stack one behind or on top of another? ;)

Do you think that variable opacity of an element is going to be a problem?

User avatar
Andrey01
Member
Posts: 2574
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: is Shadow mapping desired?

by Andrey01 » Post

Liso wrote:
Thu Apr 15, 2021 11:23
Just working on it :)

Image
Hmm. I seem not to quite understand what is here. Mirror reflections in glass? o_O Or is those blocks that on a floor a reflection of the glass wall?

User avatar
philipbenr
Member
Posts: 1897
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: robinspi
Location: United States

Re: is Shadow mapping desired?

by philipbenr » Post

Andrey01 wrote:
Thu Apr 15, 2021 21:32
Hmm. I seem not to quite understand what is here. Mirror reflections in glass? o_O Or is those blocks that on a floor a reflection of the glass wall?
Its "colored light" passing through the glass that is in the screenshot. The second screenshot is the character throwing a shadow on in front of the glass light.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest