Trying to implement Shadow Mapping

For people working on the C++ code.
User avatar
philipbenr
Member
Posts: 1792
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

I took an introduction to computer graphics course, so I can at least try and keep up. I did not know about Irrlicht limitations, but it is not incredibly surprising tbh... I don't know if there have been any reservations made about the other two textures, so if you need to use one, I would go ahead. I have a feeling that if Minetest really wants to do more that would require them, they should be moving to a better engine than Irrlicht anyway.

Anyway, I wish you luck on implementing that, I know this is a well... More dangerous point in terms of engine stability/performance.

User avatar
Elektrika
Member
Posts: 36
Joined: Fri Sep 25, 2020 15:06
In-game: elektrika

Re: is Shadow mapping desired?

by Elektrika » Post

People will be able to create shaders yaaaaay
I like mods that add dimensions and ores!

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

Re: is Shadow mapping desired?

by Liso » Post

Hi everyone. I just want to share the status with you:

https://www.youtube.com/watch?v=FCdy9e_G1ds


See ya.
Liso. - My twitter -

User avatar
philipbenr
Member
Posts: 1792
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

One interesting thing is that shadows do not actually seem to be aligned properly with the sun, which is especially apparent when walking through that archway at the 20 second mark. Is that something you did or is that a product of some anomaly with the light direction that's baked into Minetest (assuming there even is any?)

Regardless, what you have is certainly a good starting point, even if there are things still to be ironed out.

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

Re: is Shadow mapping desired?

by Liso » Post

Yes, I append a small angle to the light for 2 reasons.

First, as the sun in MT is aligned to Z axis, so the shadows are... too lineal, they don´t add any depth to the scene and the second one, its because blocks are also aligned to axis, so I had to add that angle to avoid the perspective flickering artifact.

And btw, the sun in MT doesn´t have a "position" as is, it has a "hour" from 0 to 23999 ;)
Liso. - My twitter -

User avatar
Lone_Wolf
Member
Posts: 2439
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: is Shadow mapping desired?

by Lone_Wolf » Post

The set_sky API needs support for sun/moon tilt
My ContentDB -|- Working on Voxel Knights -|- Minetest Forums Dark Theme!! (You need it)

User avatar
philipbenr
Member
Posts: 1792
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

I might be convinced to take a look at that code at some point. I fully expect it to be a hairy mess and I will give up fast, but I'll at least think about taking a look after this semester is over...

User avatar
jp
Member
Posts: 829
Joined: Wed Dec 18, 2013 09:03
GitHub: kilbith
Location: France

Re: is Shadow mapping desired?

by jp » Post

I very much hope the bus factor will not fall down on you. Great work, man.

Are you using the PCF filtering?

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

Re: is Shadow mapping desired?

by Liso » Post

Thank you all.
I have to start the PR with this. Just to allow ppl to get the code and help.

About PCF, yes. At shader there are implemented a naive hard shadows, PCF up to 16x and VMS. And the video was recorded with PCF at 16x at first subfrusta, 8x second one and 4x for the last one with a 1024 shadow texture
+bug fixed, we now have Shading in the whole world
Liso. - My twitter -

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

Re: is Shadow mapping desired?

by Andrey01 » Post

WOW!!! After I watched the demo video, I have felt so inspired by this feature! And I wonder it is even still pre-alpha version, I would say this is approaching to the release, huh. The far advanced start! I have noticed an one bug with the shadow mapping on the player model, the shadows look like pretty distorted, especially on his head.

User avatar
philipbenr
Member
Posts: 1792
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

I should not speak for Liso, but no, this is probably not "near release" yet. There are probably a lot of things to explore first, to find problems and special edge cases first. It would be interesting if the feature would get merged in as a toggleable experimental feature, but the moral of this post is to not get your hopes up too high yet.

Lars
Developer
Posts: 7
Joined: Fri Oct 13, 2017 21:12

Re: is Shadow mapping desired?

by Lars » Post

This would be a welcome improvement. I'd be happy to help shepherding a PR through.

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

Re: is Shadow mapping desired?

by Liso » Post

Hi all, @philipbenr is right. There are still a lot of work to do before a release.

But I'm thinking in just integrate SM with the main render pipeline and send the PR just to let ppl to help with the development.

But I need some time because I also have a full time job and a family xDD

About:
Andrey01 wrote:
Sun Nov 22, 2020 22:17
I have noticed an one bug with the shadow mapping on the player model, the shadows look like pretty distorted, especially on his head.
Yes, the reason is that at this demo the SM texture is attached in to a slot that is used by the player skin, so you see the SM texture mapping instead of the actual skin texture ;)
Liso. - My twitter -

User avatar
philipbenr
Member
Posts: 1792
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:
Mon Nov 23, 2020 07:43
But I'm thinking in just integrate SM with the main render pipeline and send the PR just to let ppl to help with the development.

But I need some time because I also have a full time job and a family xDD
Don't burn yourself out. People can be patient if they want to see a feature implemented properly. If you push yourself too hard and get burnt out, we all lose out. ;) Family, your job, your sanity-- all are important.

As JP said, I hope the bus factor doesn't fall all on you and other people who know enough can jump on the PR.

User avatar
hex
Member
Posts: 51
Joined: Sun Dec 06, 2020 04:22
IRC: hecks
In-game: hex hhhehehe

Re: is Shadow mapping desired?

by hex » Post

If this is merged, it must be optional and fully controlled by the server. Not only is shadow mapping expensive (it costs extra drawcalls, and we're badly drawcall-bound), but you also can't assume that it's going to fit everyone's art, or every single object for that matter.
There must be API to toggle shadows per CAO and possibly per node def, both casting and receiving, it must be possible to forbid them entirely, and shadow caster drawcalls must be batched as much as it is possible.

I honestly think that even with those things being addressed, shadows are not a good fit for Minetest. You can't just plug those in and expect it to work.
Right now, sunlight is always cast from above, and there is no separation between natural and artificial light, or between direct and bounced light. Simply overlaying a shadow map on top of everything is not going to look right.
You would have to somehow gain the ability to compute sunlight from arbitrary directions, use an actual light, and use the GI for bounce only, but you'd still have to explain why sunlight gets to have a direct light with shadows and other light sources don't. It just doesn't make any sense.

User avatar
philipbenr
Member
Posts: 1792
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

I think eye candy for every game should be optional for hardware (potato) compatibility, so I would agree that it should be optional.

I also would just disagree that shadows aren't a good fit for Minetest from a subjective standpoint. Sonic Ether's eye-candy for Minecraft is fascinating to me. But I would also agree that the Minetest engine is probably not in a good spot to have it added. I remember enough from my intro to computer graphics class to know about the difficulty that is lighting and shadows... I still would say that people contributing should be encouraged even if it is an experimental feature. Unless there is definitive proof that the engine will be moving to an incompatible place, they should be able to try and implement fun QoL features to an open-source community project, despite there being numerous obstacles to a realistic experience (no GI, colored light, reflection, refraction, etc).

User avatar
hex
Member
Posts: 51
Joined: Sun Dec 06, 2020 04:22
IRC: hecks
In-game: hex hhhehehe

Re: is Shadow mapping desired?

by hex » Post

Just in case I wasn't clear enough: the server should be in control of any major visual feature. Otherwise it becomes impossible to have good art direction in your mods and games, because there are conflicting feature sets that you're expected to target. I already have this problem with tonemapping; I can either make my textures look good in one mode or in the other. I chose to keep it on because most naive users will also probably click it.

Let me tell you another story as well. Once upon a time (5.2), some guy thought it would be a great idea to implement crappy lambert shading on every entity in Minetest, globally. Problem is, I've been making all of my art with the assumption that no shading will be applied to models at all. Needless to say, my models looked like garbage with the lousy shading on, and I yelled at the guy very loudly until he went back and made it optional. Let's try not to make any more opinionated global changes like that, okay?

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

Re: is Shadow mapping desired?

by Liso » Post

The implementation I'm working on is absolutely optional and even configurable into the options menu. And I guess that implementing the server side option won´t be too difficult .

About restricting the shadows by CAO or node def, it´s an interesting option that I think it can be implemented without too much work.

And yes, you are right in "Simply overlaying a shadow map on top of everything is not going to look right", that is one of the reasons I'm not ready to send the PR yet.

About the sun light direction, I'm using an approximation based in the "time_of_day" variable, so the shadow is aligned with the sun position .

About GI and other fancy illumination things, you are talking about a huge tech jump that It´s probably far away of my skills and I'm not even thinking about it.

Also I think @philipbenr is right, eye-candy must be optional and it´s a subjective option.

And one last thing. You created your account 2 days ago so I don´t have others posts to compare, and I don´t know if you are making fun, or is the way you write or I misunderstood you . But, I have to say that I didn´t feel confortable with the tone in your last post.
Liso. - My twitter -

User avatar
jp
Member
Posts: 829
Joined: Wed Dec 18, 2013 09:03
GitHub: kilbith
Location: France

Re: is Shadow mapping desired?

by jp » Post

hex wrote:
Mon Dec 07, 2020 10:43
Just in case I wasn't clear enough: the server should be in control of any major visual feature.
Since it's entirely subjective, it's not up to the server to decide what looks better than another. No other game does that.

User avatar
Lone_Wolf
Member
Posts: 2439
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: is Shadow mapping desired?

by Lone_Wolf » Post

I would instead ask the MT Engine for per-server client settings and the ability for servers to detect clientside settings.
That would allow servers to warn players if they're using a setting that the server doesn't recommend (Could possibly add a builtin function that allows for easily doing this?). Then players would be able to disable the settings in question without changing it for all other servers.
That would also be useful for games like Water_Game. Which is made with players using pitch_move in mind. But is unable to enforce that, set it as the default state, or detect it AFAIK.

I support restricting the shadows by CAO or node def. That would be useful for things other than just disabling the entire feature
And one last thing. You created your account 2 days ago so I don´t have others posts to compare, and I don´t know if you are making fun, or is the way you write or I misunderstood you . But, I have to say that I didn´t feel confortable with the tone in your last post.
From the little I've seen on Github they're a bit hostile when it comes to something they don't agree with
My ContentDB -|- Working on Voxel Knights -|- Minetest Forums Dark Theme!! (You need it)

User avatar
freshreplicant
Member
Posts: 90
Joined: Sun Aug 09, 2020 10:37
In-game: freshreplicant

Re: is Shadow mapping desired?

by freshreplicant » Post

Liso wrote:
Mon Dec 07, 2020 17:29
About the sun light direction, I'm using an approximation based in the "time_of_day" variable, so the shadow is aligned with the sun position .
That's clever!

Looks very promising, I for one totally welcome (optional) eye-candy like this. It really makes a big difference to the impressiveness of the experience.

I know somebody mentioned in this thread already, but coloured lights are near the top of my wishlist. Coloured lights AND shadow mapping? Man that would be amazing.

User avatar
v-rob
Developer
Posts: 833
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: is Shadow mapping desired?

by v-rob » Post

Am I correct in my assumption that Minetest's normal lighting system is ignored with this enabled, or is it still used for light sources like torches? It's hard to tell from the video. But I would assume that if Minetest's lighting system is not used, colored lighting would be possible with this since there's no problem with map compatibility. (Honestly, having colored light streaming through stained glass windows would be incredible.) But I'm no expert on the matter.

I do have a question about how this exactly works: If mapblocks aren't loaded, how are the shadows calculated? E.g. big caverns underground might not have all mapblocks loaded, so how to tell whether it should be in shadow or not?

(BTW: I would suggest a change of title since I think it's nearly unanimous that shadow mapping is desired.)
GUI Core Developer | My Best Mods: Bridger - Slats - Stained Glass | To contact me, send a PM

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

Re: is Shadow mapping desired?

by Liso » Post

v-rob wrote:
Wed Dec 09, 2020 01:00
Am I correct in my assumption that Minetest's normal lighting system is ignored with this enabled, or is it still used for light sources like torches? It's hard to tell from the video. But I would assume that if Minetest's lighting system is not used, colored lighting would be possible with this since there's no problem with map compatibility. (Honestly, having colored light streaming through stained glass windows would be incredible.) But I'm no expert on the matter.
Not yet. I'm trying to keep the SM as separated as I can from the base code. So I'm trying to adapt the shadows to the current lighting system. But probably, we will have to change it in a near future.


v-rob wrote:
Wed Dec 09, 2020 01:00

I do have a question about how this exactly works: If mapblocks aren't loaded, how are the shadows calculated? E.g. big caverns underground might not have all mapblocks loaded, so how to tell whether it should be in shadow or not?
Great question. SM are created by rendering the scene from the pov of the light. And in MT this is a problem because it has HUGE maps.

So to do it, I'm using a technique called "stable cascade shadow mapping" that is basically splitting the camera view in _n_ splits and do a render (only the depth) for each split. with this we can have shadows with a really good resolution.

But this resolution is not used for shadow quality, instead I'm using this to render each split further the camera view. So we can have shadows from objects far away ( about 100 cubes) from the camera.

Once we have the "light camera" we can use the standard mechanism to get the mapblocks, each 200ms or when the camera changes enough. But obviously, if the mapblock is not loaded, there is no shadow.

About underground shadows, there are not shadows in cavers. at least not for the moment. It needs a more deep change in the rendering pipeline (deferred shading), and it will probably break other things.

So the idea is to avoid underground shadows.
Right now I'm exploring different possibilities. We have, in theory, a property in each object that show the light intensity but in reality it only have 2 values :(. No light or full sunlight. We can´t use it.
The other option I saw, is a property that tell us if the block can see the sky or not, maybe with this we can check if we need to render the shadow or not.

I guess the best option ,is to send the PR as WiP and ask the community for help
v-rob wrote:
Wed Dec 09, 2020 01:00
(BTW: I would suggest a change of title since I think it's nearly unanimous that shadow mapping is desired.)
I'll do that, as soon as I figure out how to do it xD.
Edit. Done


Disclaimer: I'm really bad trying to explain myself, and it´s worst when I try it in English ;).
Liso. - My twitter -

User avatar
cHyper
Member
Posts: 1014
Joined: Fri May 06, 2011 08:49
GitHub: cHyper-0815OL
IRC: cHyper cHyper_de
In-game: cHyper
Location: Austria
Contact:

Re: Trying to implement Shadow Mapping

by cHyper » Post

keep up the good work...

cHyper

User avatar
hex
Member
Posts: 51
Joined: Sun Dec 06, 2020 04:22
IRC: hecks
In-game: hex hhhehehe

Re: is Shadow mapping desired?

by hex » Post

Liso wrote:
Mon Dec 07, 2020 17:29
About the sun light direction, I'm using an approximation based in the "time_of_day" variable, so the shadow is aligned with the sun position .
But here's the thing, the built-in sunlight/moonlight is always cast from the top. So your shadow won't be aligned with that, and you will effectively see two conflicting shadows, one soft and one hard. You are trying to superimpose one light model on top of another.
Lone_Wolf wrote:
Mon Dec 07, 2020 19:23
I would instead ask the MT Engine for per-server client settings and the ability for servers to detect clientside settings.
That would allow servers to warn players if they're using a setting that the server doesn't recommend
That's the dumbest thing I've heard in a while. How about just... let the server control it? A server side intensity control is desirable anyway, so just make 0 disable shadow casters entirely.
That situation with pitch_move only proves that leaving things like this up to the client brings nothing but trouble. I recently had invited someone to my test server, and when I told him he's supposed to use third person mode, he was like "wait, you can't enforce that?" We should be trying to get away from the tyranny of client settings, not enable it.
Lone_Wolf wrote:
Mon Dec 07, 2020 19:23
I support restricting the shadows by CAO or node def. That would be useful for things other than just disabling the entire feature
But what's the problem with doing both?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest