diff --git a/doc/lua_api.md b/doc/lua_api.md index 5af0b5aec0032..0869196bb374c 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5280,7 +5280,7 @@ Utilities physics_overrides_v2 = true, -- In HUD definitions the field `type` is used and `hud_elem_type` is deprecated (5.9.0) hud_def_type_field = true, - -- set_lighting support lightIntensity table (5.9.0) + -- set_lighting support light_intensity table (5.9.0) light_intensity = true, } ``` @@ -8047,15 +8047,15 @@ child will follow movement and rotation of that bone. * `volumetric_light`: is a table that controls volumetric light (a.k.a. "godrays") * `strength`: sets the strength of the volumetric light effect from 0 (off, default) to 1 (strongest) * This value has no effect on clients who have the "Volumetric Lighting" or "Bloom" shaders disabled. - * `lightIntensity` is a table that controls calculation of night and day sun light color. - `sun_color = colorOffset + colorRatioCoef*daynight_ratio` where `daynight_ratio` is not linear to day time + * `light_intensity` is a table that controls calculation of sun light color. + `sun_color = color_offset + color_ratio_coef*daynight_ratio` where `daynight_ratio` is not linear to day time Result color lesser or equal to 0.0 means no color in light. Result color greater or equal to 1.0 means full color in light. - * `colorOffset` is a table that controls red, green and blue color offsets. + * `color_offset` is a table that controls red, green and blue color offsets. * `r` (default: `-0.04`) * `g` (default: `-0.04`) * `b` (default: `0.078`) - * `colorRatioCoef` is table that controls red, green and blue color ration coefficients. + * `color_ratio_coef` is table that controls red, green and blue color ration coefficients. * `r` (default: `0.001`) * `g` (default: `0.001`) * `b` (default: `0.00098`) diff --git a/games/devtest/mods/lighting/set_lightIntensity.lua b/games/devtest/mods/lighting/set_lightIntensity.lua index 737697feac536..c51373e92134c 100644 --- a/games/devtest/mods/lighting/set_lightIntensity.lua +++ b/games/devtest/mods/lighting/set_lightIntensity.lua @@ -1,13 +1,13 @@ -local lightIntensity_sections = { - {n = "colorOffset", d = "Color offset", +local light_intensity_sections = { + {n = "color_offset", d = "Color offset", entries = { {n = "r", d = "Red color offset", min = -1, max = 2}, {n = "g", d = "Green color offset", min = -1, max = 2}, {n = "b", d = "Blue color offset", min = -1, max = 2}, } }, - {n = "colorRatioCoef", d = "Color day-night ratio coefficient", + {n = "color_ratio_coef", d = "Color day-night ratio coefficient", entries = { {n = "r", d = "Red color day-night ratio coefficient", min = -1e-3, max = 2e-3}, {n = "g", d = "Green color day-night ratio coefficient", min = -1e-3, max = 2e-3}, @@ -16,14 +16,14 @@ local lightIntensity_sections = { } } -local function dump_lightIntensity(lightIntensity) +local function dump_light_intensity(light_intensity) local result = "{\n" local section_count = 0 - for _,section in ipairs(lightIntensity_sections) do + for _,section in ipairs(light_intensity_sections) do section_count = section_count + 1 local parameters = section.entries or {} - local state = lightIntensity[section.n] or {} + local state = light_intensity[section.n] or {} result = result.." "..section.n.." = {\n" @@ -39,7 +39,7 @@ local function dump_lightIntensity(lightIntensity) result = result.." }" - if section_count < #lightIntensity_sections then + if section_count < #light_intensity_sections then result = result.."," end result = result.."\n" @@ -48,15 +48,15 @@ local function dump_lightIntensity(lightIntensity) return result end -minetest.register_chatcommand("set_lightIntensity", { +minetest.register_chatcommand("set_light_intensity", { params = "", - description = "Tune lighting lightIntensity parameters", + description = "Tune lighting light_intensity parameters", func = function(player_name, param) local player = minetest.get_player_by_name(player_name) if not player then return end local lighting = player:get_lighting() - local lightIntensity = lighting.lightIntensity + local light_intensity = lighting.light_intensity local form = { "formspec_version[2]", @@ -68,9 +68,9 @@ minetest.register_chatcommand("set_lightIntensity", { }; local line = 1 - for _,section in ipairs(lightIntensity_sections) do + for _,section in ipairs(light_intensity_sections) do local parameters = section.entries or {} - local state = lightIntensity[section.n] or {} + local state = light_intensity[section.n] or {} table.insert(form, "label[1,"..line..";"..section.d.."]") line = line + 1 @@ -90,33 +90,33 @@ minetest.register_chatcommand("set_lightIntensity", { line = line + 1 end - minetest.show_formspec(player_name, "lightIntensity", table.concat(form)) - local debug_value = dump_lightIntensity(lightIntensity) + minetest.show_formspec(player_name, "light_intensity", table.concat(form)) + local debug_value = dump_light_intensity(light_intensity) 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}) - player:get_meta():set_int("lightIntensity_hud", debug_ui) + player:get_meta():set_int("light_intensity_hud", debug_ui) end }) minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname ~= "lightIntensity" then return end + if formname ~= "light_intensity" then return end if not player then return end - local hud_id = player:get_meta():get_int("lightIntensity_hud") + local hud_id = player:get_meta():get_int("light_intensity_hud") if fields.quit then player:hud_remove(hud_id) - player:get_meta():set_int("lightIntensity_hud", -1) + player:get_meta():set_int("light_intensity_hud", -1) return end local lighting = player:get_lighting() - local lightIntensity = lighting.lightIntensity - for _,section in ipairs(lightIntensity_sections) do + local light_intensity = lighting.light_intensity + for _,section in ipairs(light_intensity_sections) do local parameters = section.entries or {} - local state = (lightIntensity[section.n] or {}) - lightIntensity[section.n] = state + local state = (light_intensity[section.n] or {}) + light_intensity[section.n] = state for _,v in ipairs(parameters) do @@ -133,7 +133,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end end - local debug_value = dump_lightIntensity(lightIntensity) + local debug_value = dump_light_intensity(light_intensity) player:hud_change(hud_id, "text", debug_value) player:set_lighting(lighting) diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 15770f3ef6568..d22536db9531f 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -283,9 +283,9 @@ u16 getSmoothLightTransparent(const v3s16 &p, const v3s16 &corner, MeshMakeData } void get_sunlight_color(video::SColorf *sunlight, u32 daynight_ratio, const LightIntensity &lightIntensity){ - sunlight->r = lightIntensity.colorOffset_rgb[0]+lightIntensity.colorRatioCoef_rgb[0]*daynight_ratio; - sunlight->g = lightIntensity.colorOffset_rgb[1]+lightIntensity.colorRatioCoef_rgb[1]*daynight_ratio; - sunlight->b = lightIntensity.colorOffset_rgb[2]+lightIntensity.colorRatioCoef_rgb[2]*daynight_ratio; + sunlight->r = lightIntensity.colorOffset_rgb.X+lightIntensity.colorRatioCoef_rgb.X*daynight_ratio; + sunlight->g = lightIntensity.colorOffset_rgb.Y+lightIntensity.colorRatioCoef_rgb.Y*daynight_ratio; + sunlight->b = lightIntensity.colorOffset_rgb.Z+lightIntensity.colorRatioCoef_rgb.Z*daynight_ratio; } void final_color_blend(video::SColor *result, diff --git a/src/lighting.h b/src/lighting.h index d02afaabbf5e3..2477e3592bea0 100644 --- a/src/lighting.h +++ b/src/lighting.h @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include "irr_v3d.h" /** * Parameters for automatic exposure compensation @@ -52,17 +53,17 @@ struct AutoExposure * Light color is calculated in function get_sunlight_color. * Variable daynight_ration can be from 0 to 1000. * - * sunlight->r = colorOffset_rgb[0]+colorRatioCoef_rgb[0]*daynight_ratio; - * sunlight->g = colorOffset_rgb[1]+colorRatioCoef_rgb[1]*daynight_ratio; - * sunlight->b = colorOffset_rgb[2]+colorRatioCoef_rgb[2]*daynight_ratio; + * sunlight->r = colorOffset_rgb.X+colorRatioCoef_rgb.X*daynight_ratio; + * sunlight->g = colorOffset_rgb.Y+colorRatioCoef_rgb.Y*daynight_ratio; + * sunlight->b = colorOffset_rgb.Z+colorRatioCoef_rgb.Z*daynight_ratio; * */ struct LightIntensity { /// @brief Sunlight color offset - float colorOffset_rgb[3]; + v3f colorOffset_rgb; /// @brief Sunlight color dayratio effect - float colorRatioCoef_rgb[3]; + v3f colorRatioCoef_rgb; LightIntensity(); }; diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 1d14260210fbd..93e20c696b6cf 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -1818,11 +1818,11 @@ void Client::handleCommand_SetLighting(NetworkPacket *pkt) if (pkt->getRemainingBytes() >= 4) *pkt >> lighting.volumetric_light_strength; if (pkt->getRemainingBytes() >= 24) { - *pkt >> lighting.lightIntensity.colorOffset_rgb[0] - >> lighting.lightIntensity.colorOffset_rgb[1] - >> lighting.lightIntensity.colorOffset_rgb[2] - >> lighting.lightIntensity.colorRatioCoef_rgb[0] - >> lighting.lightIntensity.colorRatioCoef_rgb[1] - >> lighting.lightIntensity.colorRatioCoef_rgb[2]; + *pkt >> lighting.lightIntensity.colorOffset_rgb.X + >> lighting.lightIntensity.colorOffset_rgb.Y + >> lighting.lightIntensity.colorOffset_rgb.Z + >> lighting.lightIntensity.colorRatioCoef_rgb.X + >> lighting.lightIntensity.colorRatioCoef_rgb.Y + >> lighting.lightIntensity.colorRatioCoef_rgb.Z; } } diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 553c7924a3c96..cbe4a01c629de 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -2518,24 +2518,24 @@ int ObjectRef::l_set_lighting(lua_State *L) } lua_pop(L, 1); // volumetric_light - lua_getfield(L, 2, "lightIntensity"); + lua_getfield(L, 2, "light_intensity"); if (lua_istable(L, -1)) { - lua_getfield(L, 3, "colorOffset"); + lua_getfield(L, 3, "color_offset"); if (lua_istable(L, -1)) { - lighting.lightIntensity.colorOffset_rgb[0] = getfloatfield_default(L, -1, "r", lighting.lightIntensity.colorOffset_rgb[0]); - lighting.lightIntensity.colorOffset_rgb[1] = getfloatfield_default(L, -1, "g", lighting.lightIntensity.colorOffset_rgb[1]); - lighting.lightIntensity.colorOffset_rgb[2] = getfloatfield_default(L, -1, "b", lighting.lightIntensity.colorOffset_rgb[2]); + lighting.lightIntensity.colorOffset_rgb.X = getfloatfield_default(L, -1, "r", lighting.lightIntensity.colorOffset_rgb.X); + lighting.lightIntensity.colorOffset_rgb.Y = getfloatfield_default(L, -1, "g", lighting.lightIntensity.colorOffset_rgb.Y); + lighting.lightIntensity.colorOffset_rgb.Z = getfloatfield_default(L, -1, "b", lighting.lightIntensity.colorOffset_rgb.Z); } - lua_pop(L, 1); // colorOffset - lua_getfield(L, 3, "colorRatioCoef"); + lua_pop(L, 1); // color_offset + lua_getfield(L, 3, "color_ratio_coef"); if (lua_istable(L, -1)) { - lighting.lightIntensity.colorRatioCoef_rgb[0] = getfloatfield_default(L, -1, "r", lighting.lightIntensity.colorRatioCoef_rgb[0]); - lighting.lightIntensity.colorRatioCoef_rgb[1] = getfloatfield_default(L, -1, "g", lighting.lightIntensity.colorRatioCoef_rgb[1]); - lighting.lightIntensity.colorRatioCoef_rgb[2] = getfloatfield_default(L, -1, "b", lighting.lightIntensity.colorRatioCoef_rgb[2]); + lighting.lightIntensity.colorRatioCoef_rgb.X = getfloatfield_default(L, -1, "r", lighting.lightIntensity.colorRatioCoef_rgb.X); + lighting.lightIntensity.colorRatioCoef_rgb.Y = getfloatfield_default(L, -1, "g", lighting.lightIntensity.colorRatioCoef_rgb.Y); + lighting.lightIntensity.colorRatioCoef_rgb.Z = getfloatfield_default(L, -1, "b", lighting.lightIntensity.colorRatioCoef_rgb.Z); } - lua_pop(L, 1); // colorRatioCoef + lua_pop(L, 1); // color_ratio_coef } - lua_pop(L, 1); // lightIntensity + lua_pop(L, 1); // light_intensity } getServer(L)->setLighting(player, lighting); @@ -2578,24 +2578,24 @@ int ObjectRef::l_get_lighting(lua_State *L) lua_pushnumber(L, lighting.volumetric_light_strength); lua_setfield(L, -2, "strength"); lua_setfield(L, -2, "volumetric_light"); - lua_newtable(L); // "lightIntensity" - lua_newtable(L); // "colorOffset" - lua_pushnumber(L, lighting.lightIntensity.colorOffset_rgb[0]); + lua_newtable(L); // "light_intensity" + lua_newtable(L); // "color_offset" + lua_pushnumber(L, lighting.lightIntensity.colorOffset_rgb.X); lua_setfield(L, -2, "r"); - lua_pushnumber(L, lighting.lightIntensity.colorOffset_rgb[1]); + lua_pushnumber(L, lighting.lightIntensity.colorOffset_rgb.Y); lua_setfield(L, -2, "g"); - lua_pushnumber(L, lighting.lightIntensity.colorOffset_rgb[2]); + lua_pushnumber(L, lighting.lightIntensity.colorOffset_rgb.Z); lua_setfield(L, -2, "b"); - lua_setfield(L, -2, "colorOffset"); - lua_newtable(L); // "colorRatioCoef" - lua_pushnumber(L, lighting.lightIntensity.colorRatioCoef_rgb[0]); + lua_setfield(L, -2, "color_offset"); + lua_newtable(L); // "color_ratio_coef" + lua_pushnumber(L, lighting.lightIntensity.colorRatioCoef_rgb.X); lua_setfield(L, -2, "r"); - lua_pushnumber(L, lighting.lightIntensity.colorRatioCoef_rgb[1]); + lua_pushnumber(L, lighting.lightIntensity.colorRatioCoef_rgb.Y); lua_setfield(L, -2, "g"); - lua_pushnumber(L, lighting.lightIntensity.colorRatioCoef_rgb[2]); + lua_pushnumber(L, lighting.lightIntensity.colorRatioCoef_rgb.Z); lua_setfield(L, -2, "b"); - lua_setfield(L, -2, "colorRatioCoef"); - lua_setfield(L, -2, "lightIntensity"); + lua_setfield(L, -2, "color_ratio_coef"); + lua_setfield(L, -2, "light_intensity"); return 1; } diff --git a/src/server.cpp b/src/server.cpp index 825767d3a3cea..028b49da9bcc0 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1910,15 +1910,15 @@ void Server::SendSetLighting(session_t peer_id, const Lighting &lighting) << lighting.exposure.speed_bright_dark << lighting.exposure.center_weight_power; - pkt << lighting.lightIntensity.colorOffset_rgb[0] - << lighting.lightIntensity.colorOffset_rgb[1] - << lighting.lightIntensity.colorOffset_rgb[2] - << lighting.lightIntensity.colorRatioCoef_rgb[0] - << lighting.lightIntensity.colorRatioCoef_rgb[1] - << lighting.lightIntensity.colorRatioCoef_rgb[2]; - pkt << lighting.volumetric_light_strength; + pkt << lighting.lightIntensity.colorOffset_rgb.X + << lighting.lightIntensity.colorOffset_rgb.Y + << lighting.lightIntensity.colorOffset_rgb.Z + << lighting.lightIntensity.colorRatioCoef_rgb.X + << lighting.lightIntensity.colorRatioCoef_rgb.Y + << lighting.lightIntensity.colorRatioCoef_rgb.Z; + Send(&pkt); }