Skip to content

Commit

Permalink
Settings GUI: Move shadow presets to Shaders, remove Most Used (#13713)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Aug 5, 2023
1 parent 28fce8a commit 752ce1a
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 193 deletions.
34 changes: 7 additions & 27 deletions builtin/mainmenu/settings/dlg_settings.lua
Expand Up @@ -19,8 +19,8 @@
local component_funcs = dofile(core.get_mainmenu_path() .. DIR_DELIM ..
"settings" .. DIR_DELIM .. "components.lua")

local quick_shader_component = dofile(core.get_mainmenu_path() .. DIR_DELIM ..
"settings" .. DIR_DELIM .. "shader_component.lua")
local shadows_component = dofile(core.get_mainmenu_path() .. DIR_DELIM ..
"settings" .. DIR_DELIM .. "shadows_component.lua")


local full_settings = settingtypes.parse_config_file(false, true)
Expand Down Expand Up @@ -61,31 +61,6 @@ local change_keys = {
}


add_page({
id = "most_used",
title = gettext("Most Used"),
content = {
change_keys,
"language",
"fullscreen",
PLATFORM ~= "Android" and "autosave_screensize" or false,
"touchscreen_threshold",
{ heading = gettext("Scaling") },
"gui_scaling",
"hud_scaling",
{ heading = gettext("Graphics / Performance") },
"smooth_lighting",
"enable_particles",
"enable_3d_clouds",
"opaque_water",
"connected_glass",
"node_highlighting",
"leaves_style",
{ heading = gettext("Shaders") },
quick_shader_component,
},
})

add_page({
id = "accessibility",
title = gettext("Accessibility"),
Expand Down Expand Up @@ -155,6 +130,11 @@ end
load_settingtypes()

table.insert(page_by_id.controls_keyboard_and_mouse.content, 1, change_keys)
do
local content = page_by_id.graphics_and_audio_shaders.content
local idx = table.indexof(content, "enable_dynamic_shadows")
table.insert(content, idx, shadows_component)
end


local function get_setting_info(name)
Expand Down
163 changes: 0 additions & 163 deletions builtin/mainmenu/settings/shader_component.lua

This file was deleted.

121 changes: 121 additions & 0 deletions builtin/mainmenu/settings/shadows_component.lua
@@ -0,0 +1,121 @@
--Minetest
--Copyright (C) 2021-2 x2048
--Copyright (C) 2022-3 rubenwardy
--
--This program is free software; you can redistribute it and/or modify
--it under the terms of the GNU Lesser General Public License as published by
--the Free Software Foundation; either version 2.1 of the License, or
--(at your option) any later version.
--
--This program is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
--GNU Lesser General Public License for more details.
--
--You should have received a copy of the GNU Lesser General Public License along
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


local shadow_levels_labels = {
fgettext("Disabled"),
fgettext("Very Low"),
fgettext("Low"),
fgettext("Medium"),
fgettext("High"),
fgettext("Very High"),
fgettext("Custom"),
}
local PRESET_DISABLED = 1
local PRESET_CUSTOM = #shadow_levels_labels


-- max distance, texture size, texture_32bit, filters, map color
local shadow_presets = {
[2] = { 62, 512, true, 0, false },
[3] = { 93, 1024, true, 0, false },
[4] = { 140, 2048, true, 1, false },
[5] = { 210, 4096, true, 2, true },
[6] = { 300, 8192, true, 2, true },
}


local function detect_mapping_idx()
if not core.settings:get_bool("enable_dynamic_shadows", false) then
return PRESET_DISABLED
end

local shadow_map_max_distance = tonumber(core.settings:get("shadow_map_max_distance"))
local shadow_map_texture_size = tonumber(core.settings:get("shadow_map_texture_size"))
local shadow_map_texture_32bit = core.settings:get_bool("shadow_map_texture_32bit", false)
local shadow_filters = tonumber(core.settings:get("shadow_filters"))
local shadow_map_color = core.settings:get_bool("shadow_map_color", false)

for i = 2, 6 do
local preset = shadow_presets[i]
if preset[1] == shadow_map_max_distance and
preset[2] == shadow_map_texture_size and
preset[3] == shadow_map_texture_32bit and
preset[4] == shadow_filters and
preset[5] == shadow_map_color then
return i
end
end
return PRESET_CUSTOM
end


local function apply_preset(preset)
if preset then
core.settings:set_bool("enable_dynamic_shadows", true)
core.settings:set("shadow_map_max_distance", preset[1])
core.settings:set("shadow_map_texture_size", preset[2])
core.settings:set_bool("shadow_map_texture_32bit", preset[3])
core.settings:set("shadow_filters", preset[4])
core.settings:set_bool("shadow_map_color", preset[5])
else
core.settings:set_bool("enable_dynamic_shadows", false)
end
end


return {
query_text = "Shadows",
requires = {
shaders = true,
opengl = true,
},
get_formspec = function(self, avail_w)
local labels = table.copy(shadow_levels_labels)
local idx = detect_mapping_idx()

-- Remove "custom" if not already selected
if idx ~= PRESET_CUSTOM then
table.remove(labels, PRESET_CUSTOM)
end

local fs =
"label[0,0.2;" .. fgettext("Dynamic shadows") .. "]" ..
"dropdown[0,0.4;3,0.8;dd_shadows;" .. table.concat(labels, ",") .. ";" .. idx .. ";true]" ..
"label[0,1.5;" .. core.colorize("#bbb", fgettext("(The game will need to enable shadows as well)")) .. "]"
return fs, 1.8
end,
on_submit = function(self, fields)
if fields.dd_shadows then
local old_shadow_level_idx = detect_mapping_idx()
local shadow_level_idx = tonumber(fields.dd_shadows)
if shadow_level_idx == nil or shadow_level_idx == old_shadow_level_idx then
return false
end

if shadow_level_idx == PRESET_CUSTOM then
core.settings:set_bool("enable_dynamic_shadows", true)
return true
end

local preset = shadow_presets[shadow_level_idx]
apply_preset(preset)
return true
end
end,
}
2 changes: 1 addition & 1 deletion builtin/settingtypes.txt
Expand Up @@ -430,7 +430,7 @@ enable_dynamic_shadows (Dynamic shadows) bool false
shadow_strength_gamma (Shadow strength gamma) float 1.0 0.1 10.0

# Maximum distance to render shadows.
shadow_map_max_distance (Shadow map max distance in nodes to render shadows) float 200.0 10.0 1000.0
shadow_map_max_distance (Shadow map max distance in nodes to render shadows) float 140.0 10.0 1000.0

# Texture size to render the shadow map on.
# This must be a power of two.
Expand Down
2 changes: 1 addition & 1 deletion minetest.conf.example
Expand Up @@ -433,7 +433,7 @@

# Maximum distance to render shadows.
# type: float min: 10 max: 1000
# shadow_map_max_distance = 200.0
# shadow_map_max_distance = 140.0

# Texture size to render the shadow map on.
# This must be a power of two.
Expand Down
2 changes: 1 addition & 1 deletion src/defaultsettings.cpp
Expand Up @@ -274,7 +274,7 @@ void set_default_settings()
// Effects Shadows
settings->setDefault("enable_dynamic_shadows", "false");
settings->setDefault("shadow_strength_gamma", "1.0");
settings->setDefault("shadow_map_max_distance", "200.0");
settings->setDefault("shadow_map_max_distance", "140.0");
settings->setDefault("shadow_map_texture_size", "2048");
settings->setDefault("shadow_map_texture_32bit", "true");
settings->setDefault("shadow_map_color", "false");
Expand Down

0 comments on commit 752ce1a

Please sign in to comment.