1 local lighting_sections = {
2 {n = "shadows", d = "Shadows",
4 { n = "intensity", d = "Shadow Intensity", min = 0, max = 1 }
8 n = "exposure", d = "Exposure",
10 {n = "luminance_min", d = "Minimum Luminance", min = -10, max = 10},
11 {n = "luminance_max", d = "Maximum Luminance", min = -10, max = 10},
12 {n = "exposure_correction", d = "Exposure Correction", min = -10, max = 10},
13 {n = "speed_dark_bright", d = "Bright light adaptation speed", min = -10, max = 10, type="log2"},
14 {n = "speed_bright_dark", d = "Dark scene adaptation speed", min = -10, max = 10, type="log2"},
15 {n = "center_weight_power", d = "Power factor for center-weighting", min = 0.1, max = 10},
20 local function dump_lighting(lighting)
22 local section_count = 0
23 for _,section in ipairs(lighting_sections) do
24 section_count = section_count + 1
26 local parameters = section.entries or {}
27 local state = lighting[section.n] or {}
29 result = result.." "..section.n.." = {\n"
32 for _,v in ipairs(parameters) do
34 result = result.." "..v.n.." = "..(math.floor(state[v.n] * 1000)/1000)
35 if count < #parameters then
43 if section_count < #lighting_sections then
52 minetest.register_chatcommand("set_lighting", {
54 description = "Tune lighting parameters",
55 func = function(player_name, param)
56 local player = minetest.get_player_by_name(player_name);
57 if not player then return end
59 local lighting = player:get_lighting()
60 local exposure = lighting.exposure or {}
63 "formspec_version[2]",
65 "position[0.99,0.15]",
72 for _,section in ipairs(lighting_sections) do
73 local parameters = section.entries or {}
74 local state = lighting[section.n] or {}
76 table.insert(form, "label[1,"..line..";"..section.d.."]")
79 for _,v in ipairs(parameters) do
80 table.insert(form, "label[2,"..line..";"..v.d.."]")
81 table.insert(form, "scrollbaroptions[min=0;max=1000;smallstep=10;largestep=100;thumbsize=10]")
82 local value = state[v.n]
83 if v.type == "log2" then
84 value = math.log(value or 1) / math.log(2)
86 local sb_scale = math.floor(1000 * (math.max(v.min, value or 0) - v.min) / (v.max - v.min))
87 table.insert(form, "scrollbar[2,"..(line+0.7)..";12,1;horizontal;"..section.n.."."..v.n..";"..sb_scale.."]")
94 minetest.show_formspec(player_name, "lighting", table.concat(form))
95 local debug_value = dump_lighting(lighting)
96 local debug_ui = player:hud_add({type="text", position={x=0.1, y=0.3}, scale={x=1,y=1}, alignment = {x=1, y=1}, text=debug_value, number=0xFFFFFF})
97 player:get_meta():set_int("lighting_hud", debug_ui)
101 minetest.register_on_player_receive_fields(function(player, formname, fields)
102 if formname ~= "lighting" then return end
104 if not player then return end
106 local hud_id = player:get_meta():get_int("lighting_hud")
109 player:hud_remove(hud_id)
110 player:get_meta():set_int("lighting_hud", -1)
114 local lighting = player:get_lighting()
115 for _,section in ipairs(lighting_sections) do
116 local parameters = section.entries or {}
118 local state = (lighting[section.n] or {})
119 lighting[section.n] = state
121 for _,v in ipairs(parameters) do
123 if fields[section.n.."."..v.n] then
124 local event = minetest.explode_scrollbar_event(fields[section.n.."."..v.n])
125 if event.type == "CHG" then
126 local value = v.min + (v.max - v.min) * (event.value / 1000);
127 if v.type == "log2" then
128 value = math.pow(2, value);
136 local debug_value = dump_lighting(lighting)
137 player:hud_change(hud_id, "text", debug_value)
139 player:set_lighting(lighting)