Added ambient light to devtest, setting alpha always to 255 and some other improvements

This commit is contained in:
Andrey2470T 2024-04-06 15:07:56 +03:00
parent 41ab0eb0fd
commit 4a351df32b
8 changed files with 38 additions and 29 deletions

@ -8395,9 +8395,9 @@ child will follow movement and rotation of that bone.
* `set_lighting(light_definition)`: sets lighting for the player * `set_lighting(light_definition)`: sets lighting for the player
* Passing no arguments resets lighting to its default values. * Passing no arguments resets lighting to its default values.
* `light_definition` is a table with the following optional fields: * `light_definition` is a table with the following optional fields:
* `ambient_light` is a ColorSpec controlling lightness & color of ambient light; alpha must be 255 * `ambient_light` is a ColorSpec controlling lightness & color of ambient light; alpha is ignored (always set to 255)
(global lighting; default: `{a = 255, r = 0, g = 0, b = 0}` / last set value). (global lighting; default: `{a = 255, r = 0, g = 0, b = 0}` / last set value).
* It works only if 'enable_shaders' setting is set to true. * It works only if 'enable_shaders' is set to true.
* `saturation` sets the saturation (vividness; default: `1.0`). * `saturation` sets the saturation (vividness; default: `1.0`).
* values > 1 increase the saturation * values > 1 increase the saturation
* values in [0,1] decrease the saturation * values in [0,1] decrease the saturation

@ -14,6 +14,14 @@ local lighting_sections = {
{n = "speed_bright_dark", d = "Dark scene adaptation speed", min = -10, max = 10, type="log2"}, {n = "speed_bright_dark", d = "Dark scene adaptation speed", min = -10, max = 10, type="log2"},
{n = "center_weight_power", d = "Power factor for center-weighting", min = 0.1, max = 10}, {n = "center_weight_power", d = "Power factor for center-weighting", min = 0.1, max = 10},
} }
},
{
n = "ambient_light", d = "Ambient Light",
entries = {
{n = "r", d = "Red", min = 0, max = 255},
{n = "g", d = "Green", min = 0, max = 255},
{n = "b", d = "Blue", min = 0, max = 255}
}
} }
} }
@ -61,7 +69,7 @@ minetest.register_chatcommand("set_lighting", {
local form = { local form = {
"formspec_version[2]", "formspec_version[2]",
"size[15,30]", "size[15,32]",
"position[0.99,0.15]", "position[0.99,0.15]",
"anchor[1,0]", "anchor[1,0]",
"padding[0.05,0.1]", "padding[0.05,0.1]",
@ -137,4 +145,4 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
player:hud_change(hud_id, "text", debug_value) player:hud_change(hud_id, "text", debug_value)
player:set_lighting(lighting) player:set_lighting(lighting)
end) end)

@ -248,14 +248,6 @@ void ClientEnvironment::step(float dtime)
if (m_client->modsLoaded()) if (m_client->modsLoaded())
m_script->environment_step(dtime); m_script->environment_step(dtime);
// Update the ambient light
auto new_ambient_light_clr = getLocalPlayer()->getLighting().ambient_light;
bool enable_shaders = g_settings->getBool("enable_shaders");
if (enable_shaders && (new_ambient_light_clr != m_ambient_light))
m_ambient_light = new_ambient_light_clr;
// Update lighting on local player (used for wield item) // Update lighting on local player (used for wield item)
u32 day_night_ratio = getDayNightRatio(); u32 day_night_ratio = getDayNightRatio();
{ {
@ -273,8 +265,8 @@ void ClientEnvironment::step(float dtime)
video::SColor ambient_light(255, 0, 0, 0); video::SColor ambient_light(255, 0, 0, 0);
if (enable_shaders) if (g_settings->getBool("enable_shaders"))
ambient_light = m_ambient_light; ambient_light = lplayer->getLighting().ambient_light;
final_color_blend(&lplayer->light_color, light, day_night_ratio, ambient_light); final_color_blend(&lplayer->light_color, light, day_night_ratio, ambient_light);
} }

@ -149,9 +149,6 @@ class ClientEnvironment : public Environment
void updateFrameTime(bool is_paused); void updateFrameTime(bool is_paused);
u64 getFrameTime() const { return m_frame_time; } u64 getFrameTime() const { return m_frame_time; }
u64 getFrameTimeDelta() const { return m_frame_dtime; } u64 getFrameTimeDelta() const { return m_frame_dtime; }
video::SColor getAmbientLight() const { return m_ambient_light; }
private: private:
ClientMap *m_map; ClientMap *m_map;
LocalPlayer *m_local_player = nullptr; LocalPlayer *m_local_player = nullptr;
@ -167,6 +164,4 @@ class ClientEnvironment : public Environment
u64 m_frame_time = 0; u64 m_frame_time = 0;
u64 m_frame_dtime = 0; u64 m_frame_dtime = 0;
u64 m_frame_time_pause_accumulator = 0; u64 m_frame_time_pause_accumulator = 0;
// Note: Alpha should always be 255.
video::SColor m_ambient_light {255, 0, 0, 0};
}; };

@ -474,7 +474,9 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
get_sunlight_color(&sunlight, daynight_ratio); get_sunlight_color(&sunlight, daynight_ratio);
m_day_light.set(sunlight, services); m_day_light.set(sunlight, services);
video::SColorf ambient_light_f(m_client->getEnv().getAmbientLight()); auto lighting = m_client->getEnv().getLocalPlayer()->getLighting();
video::SColorf ambient_light_f(lighting.ambient_light);
m_ambient_light.set(ambient_light_f, services); m_ambient_light.set(ambient_light_f, services);
u32 animation_timer = m_client->getEnv().getFrameTime() % 1000000; u32 animation_timer = m_client->getEnv().getFrameTime() % 1000000;
@ -508,8 +510,6 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
m_texel_size0_vertex.set(m_texel_size0, services); m_texel_size0_vertex.set(m_texel_size0, services);
m_texel_size0_pixel.set(m_texel_size0, services); m_texel_size0_pixel.set(m_texel_size0, services);
auto lighting = m_client->getEnv().getLocalPlayer()->getLighting();
const AutoExposure &exposure_params = lighting.exposure; const AutoExposure &exposure_params = lighting.exposure;
std::array<float, 7> exposure_buffer = { std::array<float, 7> exposure_buffer = {
std::pow(2.0f, exposure_params.luminance_min), std::pow(2.0f, exposure_params.luminance_min),
@ -1448,7 +1448,7 @@ void Game::copyServerClientCache()
{ {
// It would be possible to let the client directly read the media files // It would be possible to let the client directly read the media files
// from where the server knows they are. But aside from being more complicated // from where the server knows they are. But aside from being more complicated
// it would also *not* fill the media cache and cause slower joining of // it would also *not* fill the media cache and cause slower joining of
// remote servers. // remote servers.
// (Imagine that you launch a game once locally and then connect to a server.) // (Imagine that you launch a game once locally and then connect to a server.)

@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client.h" #include "client.h"
#include "settings.h" #include "settings.h"
#include "profiler.h" #include "profiler.h"
#include "client/mapblock_mesh.h"
ClientParticleTexture::ClientParticleTexture(const ServerParticleTexture& p, ITextureSource *tsrc) ClientParticleTexture::ClientParticleTexture(const ServerParticleTexture& p, ITextureSource *tsrc)
{ {
@ -186,10 +187,15 @@ video::SColor Particle::updateLight(ClientEnvironment *env)
light = blend_light(env->getDayNightRatio(), LIGHT_SUN, 0); light = blend_light(env->getDayNightRatio(), LIGHT_SUN, 0);
u8 m_light = decode_light(light + m_p.glow); u8 m_light = decode_light(light + m_p.glow);
video::SColor light_color{0xFFFFFFFF};
final_color_blend(&light_color, m_light, env->getDayNightRatio(),
env->getLocalPlayer()->getLighting().ambient_light);
return video::SColor(255, return video::SColor(255,
m_light * m_base_color.getRed() / 255, light_color.getRed() * m_base_color.getRed() / 255,
m_light * m_base_color.getGreen() / 255, light_color.getGreen() * m_base_color.getGreen() / 255,
m_light * m_base_color.getBlue() / 255); light_color.getBlue() * m_base_color.getBlue() / 255);
} }
void Particle::updateVertices(ClientEnvironment *env, video::SColor color) void Particle::updateVertices(ClientEnvironment *env, video::SColor color)

@ -1826,5 +1826,4 @@ void Client::handleCommand_SetLighting(NetworkPacket *pkt)
if (pkt->getRemainingBytes() < 4) if (pkt->getRemainingBytes() < 4)
return; return;
*pkt >> lighting.ambient_light; *pkt >> lighting.ambient_light;
lighting.ambient_light.setAlpha(255); // alpha should always be 255
} }

@ -2539,8 +2539,7 @@ int ObjectRef::l_set_lighting(lua_State *L)
lua_getfield(L, 2, "ambient_light"); lua_getfield(L, 2, "ambient_light");
if (!lua_isnil(L, -1)) { if (!lua_isnil(L, -1)) {
read_color(L, -1, &lighting.ambient_light); read_color(L, -1, &lighting.ambient_light);
if (lighting.ambient_light.getAlpha() != 255) lighting.ambient_light.setAlpha(255); // alpha should always be 255
throw LuaError("ambient light alpha must be 255");
} }
lua_pop(L, 1); // ambient light lua_pop(L, 1); // ambient light
@ -2585,6 +2584,16 @@ int ObjectRef::l_get_lighting(lua_State *L)
lua_pushnumber(L, lighting.shadow_intensity); lua_pushnumber(L, lighting.shadow_intensity);
lua_setfield(L, -2, "intensity"); lua_setfield(L, -2, "intensity");
lua_setfield(L, -2, "shadows"); lua_setfield(L, -2, "shadows");
lua_newtable(L); // "ambient_light"
lua_pushnumber(L, lighting.ambient_light.getRed());
lua_setfield(L, -2, "r");
lua_pushnumber(L, lighting.ambient_light.getGreen());
lua_setfield(L, -2, "g");
lua_pushnumber(L, lighting.ambient_light.getBlue());
lua_setfield(L, -2, "b");
lua_pushnumber(L, 255);
lua_setfield(L, -2, "a");
lua_setfield(L, -2, "ambient_light");
lua_pushnumber(L, lighting.saturation); lua_pushnumber(L, lighting.saturation);
lua_setfield(L, -2, "saturation"); lua_setfield(L, -2, "saturation");
lua_newtable(L); // "exposure" lua_newtable(L); // "exposure"