Skip to content

Commit

Permalink
Apply review, bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfence committed Jan 2, 2024
1 parent 2c95df9 commit ecd7eb7
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 73 deletions.
10 changes: 5 additions & 5 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
```
Expand Down Expand Up @@ -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`)
Expand Down
46 changes: 23 additions & 23 deletions games/devtest/mods/lighting/set_lightIntensity.lua
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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"

Expand All @@ -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"
Expand All @@ -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]",
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/client/mapblock_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions src/lighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
};
Expand Down
12 changes: 6 additions & 6 deletions src/network/clientpackethandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
48 changes: 24 additions & 24 deletions src/script/lua_api/l_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
14 changes: 7 additions & 7 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit ecd7eb7

Please sign in to comment.