-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shadow mapping render pass #11244
Shadow mapping render pass #11244
Conversation
Tested with high performance Win10 64 bit CPU, extremely stable. Tested also with low end windows laptops (2), got mediocre performance and after turning quality down, was not that compelling. It should be off by default for new players in my opinion therefore in my opinion. |
Bringing @lhofhansl @numberZero @hecktest @sofar in |
Seems to work well on my system. Putting shadows up to Ultra high did drop FPS to about 30, I usually get about 60. At Medium settings I didn't see any FPS drop, and the shadows still looked quite nice. |
Works well, little visual artifacts, works well on even slightly older machines. On certain maps and settings it will even run close in performance to default. |
that sounds very promising. How it work in caved with torchs ? |
src/mapgen/mapgen.cpp
Outdated
@@ -468,6 +468,8 @@ void Mapgen::lightSpread(VoxelArea &a, std::queue<std::pair<v3s16, u8>> &queue, | |||
void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax, | |||
bool propagate_shadow) | |||
{ | |||
if (g_settings->getBool("enable_dynamic_shadows")) | |||
propagate_shadow = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a problem.
The mapgen runs on the server, it must not change its results based on purely visual settings set on the client (never mind the fact that this can't work with multiple clients).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, we can remove it without a problem. It's just we'll get double shadows (ShadowMap and propagated one) in remote servers and in local ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't mesh generation be able to remove the shadows encoded in the map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. I'm going to take a look on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to future improvements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi again, I tried to fix this, but as far as I know the static shadow can't be removed in client or at least I don't know how to do it.
using the value "nightRatio" stored at vertex alpha channel that give the ratio between sunlight and artificial light. This is also used to dilute shadows with torch even at day. You can see that here. The green is sunlight to 1, and red is all artificial light |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very very nice feature PR, i added first recommandations/fixes
src/client/renderingengine.h
Outdated
@@ -113,6 +120,14 @@ class RenderingEngine | |||
return m_device->run(); | |||
} | |||
|
|||
static ShadowRenderer *get_shadow_renderer() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm working on removing the global Renderer singleton. Can you make this function non static & call it properly from other objects ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm been working on this this and I think it's not possible without changing current MT shader implementation. We have to have access shadowRenderer data from MainShaderConstantSetter and the only way to do it is by the singleton,
I gave this a very quick look and the first advice I can give is this:
|
IDK why Lua_lint is giving error. The unused variable "ddhandled" is actually used, and it was in there before. |
Great to finally see a PR! Did some quick messing around: CobbleTower.we.zip (Building I used to reproduce bug, saved with WorldEdit) PS: Will there be/Is there a way to prevent nodes you register from casting shadows? |
Thank you, I don't even know what is that XD.
I just test it and for some reason the cobblestone stairs are slightly darker than cobblestone, even without shadows:
No right now, but we can add it if it's desired. |
It looks like you don't re-enable default shadows when the dynamic ones are disabled |
I'll take a deep look on this. But the default shadows are not disabled. I have to find how to disable them in other part: |
Nice! At Medium, it works enough well (FPS ranges from 40 - 50), except dense rainforests where it drops almost half. Making at High, FPS ~ 30 in plains, from 20 - 25 in forests, however, it may become even much less. At Ultra High, it ranges from 1 -5 FPS. I have GeForce GTX 1050 video card, maybe it is weak or better optimisation is needed. Also, I see some artifacts remain still that I discovered in earlier testings like the ripple and the shadow sharpening. Also, is artificial light emitted by torches, mese posts and etc to affect casting shadows from objects not in your plans? |
Suggestions added. |
Nice. Yep. That part is fixed. |
I think is fixed now. |
Did a pass, nothing stood out as wrong. |
there is remaining changes, i think we are fine now. Time to bench it, but honestly i think if we have major performance issue it's clearly not especially this code, but the client code design |
@nerzhul What specifically? You mean the number of draw-calls? Or other general performance issues. |
@lhofhansl yep general performance issue when enabling this. |
Here are my thoughts on this PR. Updated today, using your repo directly rather than applying the PR over upstream. All screenshots were taken with the in-game time locked at 08:00. This is Debian Bullseye with XFCE 4.18, on a Phenom II X6 1055T processor at 2.8 GHz, with 16 GB DDR1333 RAM and an R9 280X GPU (using the
|
Yes to fix the curve we need to tweak the distance, but at the same time if we reduce the distance more glitches will appear from distant shadows (blocks disappearing mostly)
uhmmm I'll take a look on that. Tnx
Yes, I think this is because those nodes are been render as normal blocks not as transparent ones. I think.
Uhm.. I think you have some settings from a previous install, the current default values are:
I can't help with this, @x2048 '??
In my linux machine it about 3-14%, but I'm not sure what value is about :) And @VanessaE , thank you very much for your review :) Also, thank you @sfan5 for your fixes. |
The registration looks pretty normal to me: minetest.register_node("stained_glass:stained_glass", {
description = "Stained Glass",
drawtype = "glasslike_framed_optional",
tiles = { "stained_glass.png", "stained_glass_detail.png" },
paramtype = "light",
paramtype2 = "color",
palette = "unifieddyes_palette_extended.png",
sunlight_propagates = true,
use_texture_alpha = "blend",
light_source = myglow,
is_ground_content = true,
walkable = true,
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3, not_in_creative_inventory=1, ud_param2_colorable = 1},
sounds = default.node_sound_glass_defaults(),
on_construct = unifieddyes.on_construct,
on_dig = unifieddyes.on_dig,
})
...something that doesn't apply in my case, because I changed them to reasonable values (as pictured at the bottom of my last comment) before commenting about the shadow darkness. 😃 Plus, in my previous tests, I had them set to 0.4.
It means how much drawtime difference there is from one frame to the next. If a frame takes say 20ms to draw, then the next one takes 40ms, then 20ms for the next one after, that's a jitter of 100%. At least that's how I interpret the number. Either way, it's much worse with shadows turned on. |
Yes, I'll take a look. @VanessaE, thank you for a good example to test :)
These are most likely colored with glVertexColor and need to be accounted for when we map the colored shadow. Grep for inVertexColor in the shaders to see how it's used. |
Any further improvements or needed fixes can be made in a future PR. @0xLiso found another bug, with WorldEdit's region cube the shadow renders in some random spot: @LoneWolfHT Also I tested and couldn't reproduce your crash. |
Congratulations on the merge guys. |
WoW PR merged. :) Thank you all for your help. @sfan5 I'll take a look on that. |
Yes, that's because the shadow has exactly the same angle that the blocks and creates that kind of glitch. 2 possible solutions are, change shadow tilt by something between 15.0 and 30.0 in the advanced settings, or if you don't want hard shadows, you can increase the soft shadow range by something like 5.0 |
Yeah! Let's do further improvements in individual PRs. |
I would like to see the specular lighting in MT (the reflective water is enough specific feature) with a support of setting materials for each node + yes, reflections of the environment. That would allow to make a mirror on water and on glass surfaces for example. Currently I'm learning OpenGL and GLSL, so I want to try to make that in MT, but that will rather take much time as I'm a quite newbie in it and I don't guarantee I can do that. |
Incredible work guys! Congrats on the merge! |
Co-authored-by: x2048 <codeforsmile@gmail.com>
Looks like the segfault was due to a conflict with @SmallJoker 's |
Well, the trees are better. But are animal shadows normal? Why stripes? cringe_shadow.mp4But in general, shadowing improves the picture very well. |
The drawer visuals from the drawers mod https://github.com/minetest-mods/drawers are not displayed correctly. |
First of all... LoL. Can you create an issue for that? this PR is closed and these bugs can be easily forgotten. |
Locking this PR as it has been merged. Please report any bugs in new issues |
This PR implements shadow mapping with PSM (Perspective Shadow Mapping), PCF filtering and "colored shadows".
The implementation it's originally based in the XEffects shadow mapping examples.
How this works:
3.1. Render ClientMap depth every 0.2 seconds to avoid excessive drawcalls.
3.2. Render depth for all dynamic entities
3.3. Mix both depth textures in the Shadow Texture.
The textures used are (3x):
irr::video::ECOLOR_FORMAT::ECF_R32F for depth
irr::video::ECOLOR_FORMAT::ECF_G32R32F for depth+color(encoded)
Both in 16bits if configured, but the tests I did, anything below 32bits causes lot's of precision problems.
To do
This PR is Ready for Review.
Future improvements.
Check if mesh generation is able to remove the shadows encoded in the map
Depth shaders using standard MT shader.cpp style (I wasn't able to make it work), so we can make things like shadows for waving plants and leaves.
Reduce drawcalls.
How to test
Go to settings tabs, enable shaders, select quality from Dynamic Shadows dropdown.
The default values are:
Ultra low:
-shadow_map_max_distance: 80 blocks
-shadow_map_texture_size: 512
-shadow_map_color: false
-filter level: 0
Low:
-shadow_map_max_distance: 120 blocks
-shadow_map_texture_size: 1024
-shadow_map_color: false
-filter level: 1
Medium:
-shadow_map_max_distance: 350 blocks
-shadow_map_texture_size: 2048
-shadow_map_color: false
-filter level: 1
High:
-shadow_map_max_distance: 350 blocks
-shadow_map_texture_size: 2048
-shadow_map_color: true
-filter level: 2
Ultra High:
-shadow_map_max_distance: 450 blocks
-shadow_map_texture_size: 4096
-shadow_map_color: true
-filter level: 2
The values Ultra Low and Low only work when the map doesn't have too big elements, and even with normal maps it could have some artifacts.
This PR is high demanding because the amount of drawcalls so it's only recommended for slightly modern hardware.
The configuration can be changed within the "All Settings" section -> shadow
Examples:
Configuration:
Examples: