Skip to content

Commit c47313d

Browse files
0xLisox2048
andauthoredJun 6, 2021
Shadow mapping render pass (#11244)
Co-authored-by: x2048 <codeforsmile@gmail.com>
1 parent 46f42e1 commit c47313d

35 files changed

+2624
-38
lines changed
 

‎builtin/mainmenu/tab_settings.lua

+56-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ local labels = {
4343
fgettext("2x"),
4444
fgettext("4x"),
4545
fgettext("8x")
46+
},
47+
shadow_levels = {
48+
fgettext("Disabled"),
49+
fgettext("Very Low"),
50+
fgettext("Low"),
51+
fgettext("Medium"),
52+
fgettext("High"),
53+
fgettext("Ultra High")
4654
}
4755
}
4856

@@ -66,6 +74,10 @@ local dd_options = {
6674
antialiasing = {
6775
table.concat(labels.antialiasing, ","),
6876
{"0", "2", "4", "8"}
77+
},
78+
shadow_levels = {
79+
table.concat(labels.shadow_levels, ","),
80+
{ "0", "1", "2", "3", "4", "5" }
6981
}
7082
}
7183

@@ -110,6 +122,15 @@ local getSettingIndex = {
110122
end
111123
end
112124
return 1
125+
end,
126+
ShadowMapping = function()
127+
local shadow_setting = core.settings:get("shadow_levels")
128+
for i = 1, #dd_options.shadow_levels[2] do
129+
if shadow_setting == dd_options.shadow_levels[2][i] then
130+
return i
131+
end
132+
end
133+
return 1
113134
end
114135
}
115136

@@ -197,7 +218,10 @@ local function formspec(tabview, name, tabdata)
197218
"checkbox[8.25,1.5;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";"
198219
.. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" ..
199220
"checkbox[8.25,2;cb_waving_plants;" .. fgettext("Waving Plants") .. ";"
200-
.. dump(core.settings:get_bool("enable_waving_plants")) .. "]"
221+
.. dump(core.settings:get_bool("enable_waving_plants")) .. "]"..
222+
"label[8.25,3.0;" .. fgettext("Dynamic shadows: ") .. "]" ..
223+
"dropdown[8.25,3.5;3.5;dd_shadows;" .. dd_options.shadow_levels[1] .. ";"
224+
.. getSettingIndex.ShadowMapping() .. "]"
201225
else
202226
tab_string = tab_string ..
203227
"label[8.38,0.7;" .. core.colorize("#888888",
@@ -207,7 +231,9 @@ local function formspec(tabview, name, tabdata)
207231
"label[8.38,1.7;" .. core.colorize("#888888",
208232
fgettext("Waving Leaves")) .. "]" ..
209233
"label[8.38,2.2;" .. core.colorize("#888888",
210-
fgettext("Waving Plants")) .. "]"
234+
fgettext("Waving Plants")) .. "]"..
235+
"label[8.38,2.7;" .. core.colorize("#888888",
236+
fgettext("Dynamic shadows")) .. "]"
211237
end
212238

213239
return tab_string
@@ -333,6 +359,34 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
333359
ddhandled = true
334360
end
335361

362+
for i = 1, #labels.shadow_levels do
363+
if fields["dd_shadows"] == labels.shadow_levels[i] then
364+
core.settings:set("shadow_levels", dd_options.shadow_levels[2][i])
365+
ddhandled = true
366+
end
367+
end
368+
369+
if fields["dd_shadows"] == labels.shadow_levels[1] then
370+
core.settings:set("enable_dynamic_shadows", "false")
371+
else
372+
core.settings:set("enable_dynamic_shadows", "true")
373+
local shadow_presets = {
374+
[2] = { 80, 512, "true", 0, "false" },
375+
[3] = { 120, 1024, "true", 1, "false" },
376+
[4] = { 350, 2048, "true", 1, "false" },
377+
[5] = { 350, 2048, "true", 2, "true" },
378+
[6] = { 450, 4096, "true", 2, "true" },
379+
}
380+
local s = shadow_presets[table.indexof(labels.shadow_levels, fields["dd_shadows"])]
381+
if s then
382+
core.settings:set("shadow_map_max_distance", s[1])
383+
core.settings:set("shadow_map_texture_size", s[2])
384+
core.settings:set("shadow_map_texture_32bit", s[3])
385+
core.settings:set("shadow_filters", s[4])
386+
core.settings:set("shadow_map_color", s[5])
387+
end
388+
end
389+
336390
return ddhandled
337391
end
338392

‎builtin/settingtypes.txt

+52
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,58 @@ enable_waving_leaves (Waving leaves) bool false
582582
# Requires shaders to be enabled.
583583
enable_waving_plants (Waving plants) bool false
584584

585+
[***Dynamic shadows]
586+
587+
# Set to true to enable Shadow Mapping.
588+
# Requires shaders to be enabled.
589+
enable_dynamic_shadows (Dynamic shadows) bool false
590+
591+
# Set the shadow strength.
592+
# Lower value means lighter shadows, higher value means darker shadows.
593+
shadow_strength (Shadow strength) float 0.2 0.05 1.0
594+
595+
# Maximum distance to render shadows.
596+
shadow_map_max_distance (Shadow map max distance in nodes to render shadows) float 120.0 10.0 1000.0
597+
598+
# Texture size to render the shadow map on.
599+
# This must be a power of two.
600+
# Bigger numbers create better shadowsbut it is also more expensive.
601+
shadow_map_texture_size (Shadow map texture size) int 1024 128 8192
602+
603+
# Sets shadow texture quality to 32 bits.
604+
# On false, 16 bits texture will be used.
605+
# This can cause much more artifacts in the shadow.
606+
shadow_map_texture_32bit (Shadow map texture in 32 bits) bool true
607+
608+
# Enable poisson disk filtering.
609+
# On true uses poisson disk to make "soft shadows". Otherwise uses PCF filtering.
610+
shadow_poisson_filter (Poisson filtering) bool true
611+
612+
# Define shadow filtering quality
613+
# This simulates the soft shadows effect by applying a PCF or poisson disk
614+
# but also uses more resources.
615+
shadow_filters (Shadow filter quality) enum 1 0,1,2
616+
617+
# Enable colored shadows.
618+
# On true translucent nodes cast colored shadows. This is expensive.
619+
shadow_map_color (Colored shadows) bool false
620+
621+
622+
# Set the shadow update time.
623+
# Lower value means shadows and map updates faster, but it consume more resources.
624+
# Minimun value 0.001 seconds max value 0.2 seconds
625+
shadow_update_time (Map update time) float 0.2 0.001 0.2
626+
627+
# Set the soft shadow radius size.
628+
# Lower values mean sharper shadows bigger values softer.
629+
# Minimun value 1.0 and max value 10.0
630+
shadow_soft_radius (Soft shadow radius) float 1.0 1.0 10.0
631+
632+
# Set the tilt of Sun/Moon orbit in degrees
633+
# Value of 0 means no tilt / vertical orbit.
634+
# Minimun value 0.0 and max value 60.0
635+
shadow_sky_body_orbit_tilt (Sky Body Orbit Tilt) float 0.0 0.0 60.0
636+
585637
[**Advanced]
586638

587639
# Arm inertia, gives a more realistic movement of

0 commit comments

Comments
 (0)
Please sign in to comment.