mirror of
https://github.com/minetest/minetest.git
synced 2024-07-04 15:05:27 +02:00
Ambient light improvements
This commit is contained in:
parent
811f5bacde
commit
8a7676d2f6
@ -8395,9 +8395,8 @@ 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 table controlling amount and color of ambient light (global lighting)
|
* `ambient_light` is a ColorSpec controlling lightness & color of ambient light; alpha must be 255
|
||||||
* `luminance` sets the amount of ambient light in range (0... LIGHT_SUN) like `light_source` has (default: `0`)
|
(global lighting; default: `{a = 255, r = 0, g = 0, b = 0}` / last set value).
|
||||||
* `color` sets the color of ambient light (ColorSpec) (default: `{a = 255, r = 255, g = 255, b = 255}`). Alpha is ignored.
|
|
||||||
* `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
|
||||||
|
@ -249,9 +249,7 @@ void ClientEnvironment::step(float dtime)
|
|||||||
m_script->environment_step(dtime);
|
m_script->environment_step(dtime);
|
||||||
|
|
||||||
// Update the ambient light
|
// Update the ambient light
|
||||||
AmbientLight &ambient_light = getLocalPlayer()->getLighting().ambient_light;
|
auto new_ambient_light_clr = getLocalPlayer()->getLighting().ambient_light;
|
||||||
|
|
||||||
video::SColor new_ambient_light_clr = encodeAmbientLight(ambient_light.luminance, ambient_light.color);
|
|
||||||
|
|
||||||
if (new_ambient_light_clr != m_ambient_light) {
|
if (new_ambient_light_clr != m_ambient_light) {
|
||||||
getClientMap().forceUpdateLightColor();
|
getClientMap().forceUpdateLightColor();
|
||||||
|
@ -167,5 +167,6 @@ 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;
|
||||||
video::SColor m_ambient_light {0, 0, 0, 0};
|
// Note: Alpha should always be 255.
|
||||||
|
video::SColor m_ambient_light {255, 0, 0, 0};
|
||||||
};
|
};
|
||||||
|
@ -719,7 +719,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||||||
const float animation_time = m_client->getAnimationTime();
|
const float animation_time = m_client->getAnimationTime();
|
||||||
const int crack = m_client->getCrackLevel();
|
const int crack = m_client->getCrackLevel();
|
||||||
const u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
|
const u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
|
||||||
const video::SColor &ambient_light = m_client->getEnv().getAmbientLight();
|
const auto ambient_light = m_client->getEnv().getAmbientLight();
|
||||||
|
|
||||||
const v3f camera_position = m_camera_position;
|
const v3f camera_position = m_camera_position;
|
||||||
|
|
||||||
|
@ -1011,19 +1011,6 @@ video::SColor encode_light(u16 light, u8 emissive_light)
|
|||||||
return video::SColor(r, b, b, b);
|
return video::SColor(r, b, b, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
video::SColor encodeAmbientLight(u8 light, video::SColor color)
|
|
||||||
{
|
|
||||||
video::SColor res_color(0, 0, 0, 0);
|
|
||||||
|
|
||||||
float light_f = light / 15.f;
|
|
||||||
|
|
||||||
res_color.setRed(core::round32(light_f * color.getRed()));
|
|
||||||
res_color.setGreen(core::round32(light_f * color.getGreen()));
|
|
||||||
res_color.setBlue(core::round32(light_f * color.getBlue()));
|
|
||||||
|
|
||||||
return res_color;
|
|
||||||
}
|
|
||||||
|
|
||||||
u8 get_solid_sides(MeshMakeData *data)
|
u8 get_solid_sides(MeshMakeData *data)
|
||||||
{
|
{
|
||||||
std::unordered_map<v3s16, u8> results;
|
std::unordered_map<v3s16, u8> results;
|
||||||
|
@ -298,8 +298,6 @@ class MapBlockMesh
|
|||||||
*/
|
*/
|
||||||
video::SColor encode_light(u16 light, u8 emissive_light);
|
video::SColor encode_light(u16 light, u8 emissive_light);
|
||||||
|
|
||||||
video::SColor encodeAmbientLight(u8 light, video::SColor color);
|
|
||||||
|
|
||||||
// Compute light at node
|
// Compute light at node
|
||||||
u16 getInteriorLight(MapNode n, s32 increment, const NodeDefManager *ndef);
|
u16 getInteriorLight(MapNode n, s32 increment, const NodeDefManager *ndef);
|
||||||
u16 getFaceLight(MapNode n, MapNode n2, const NodeDefManager *ndef);
|
u16 getFaceLight(MapNode n, MapNode n2, const NodeDefManager *ndef);
|
||||||
|
@ -47,26 +47,11 @@ struct AutoExposure
|
|||||||
AutoExposure();
|
AutoExposure();
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* Parameters for adjusting ambient light affecting on colors of map nodes and entities
|
|
||||||
*/
|
|
||||||
struct AmbientLight
|
|
||||||
{
|
|
||||||
AmbientLight() : luminance(0), color(255, 255, 255, 255)
|
|
||||||
{}
|
|
||||||
/// @brief Minimal threshold of luminance of ambience. Can be from 0 - 14.
|
|
||||||
u8 luminance;
|
|
||||||
|
|
||||||
/// @brief Color of ambient light. Default is white color.
|
|
||||||
video::SColor color;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Describes ambient light settings for a player
|
|
||||||
*/
|
|
||||||
struct Lighting
|
struct Lighting
|
||||||
{
|
{
|
||||||
AutoExposure exposure;
|
AutoExposure exposure;
|
||||||
AmbientLight ambient_light;
|
/// @brief Ambient light color & intensity for nodes & entities. Alpha is ignored.
|
||||||
|
video::SColor ambient_light = {255, 0, 0, 0};
|
||||||
float shadow_intensity {0.0f};
|
float shadow_intensity {0.0f};
|
||||||
float saturation {1.0f};
|
float saturation {1.0f};
|
||||||
float volumetric_light_strength {0.0f};
|
float volumetric_light_strength {0.0f};
|
||||||
|
@ -1802,22 +1802,29 @@ void Client::handleCommand_SetLighting(NetworkPacket *pkt)
|
|||||||
{
|
{
|
||||||
Lighting& lighting = m_env.getLocalPlayer()->getLighting();
|
Lighting& lighting = m_env.getLocalPlayer()->getLighting();
|
||||||
|
|
||||||
if (pkt->getRemainingBytes() >= 4)
|
if (pkt->getRemainingBytes() < 4)
|
||||||
*pkt >> lighting.shadow_intensity;
|
return;
|
||||||
if (pkt->getRemainingBytes() >= 4)
|
*pkt >> lighting.shadow_intensity;
|
||||||
*pkt >> lighting.saturation;
|
|
||||||
if (pkt->getRemainingBytes() >= 24) {
|
if (pkt->getRemainingBytes() < 4)
|
||||||
*pkt >> lighting.exposure.luminance_min
|
return;
|
||||||
>> lighting.exposure.luminance_max
|
*pkt >> lighting.saturation;
|
||||||
>> lighting.exposure.exposure_correction
|
|
||||||
>> lighting.exposure.speed_dark_bright
|
if (pkt->getRemainingBytes() < 24)
|
||||||
>> lighting.exposure.speed_bright_dark
|
return;
|
||||||
>> lighting.exposure.center_weight_power;
|
*pkt >> lighting.exposure.luminance_min
|
||||||
}
|
>> lighting.exposure.luminance_max
|
||||||
if (pkt->getRemainingBytes() >= 4)
|
>> lighting.exposure.exposure_correction
|
||||||
*pkt >> lighting.volumetric_light_strength;
|
>> lighting.exposure.speed_dark_bright
|
||||||
if (pkt->getRemainingBytes() >= 1) {
|
>> lighting.exposure.speed_bright_dark
|
||||||
*pkt >> lighting.ambient_light.luminance
|
>> lighting.exposure.center_weight_power;
|
||||||
>> lighting.ambient_light.color;
|
|
||||||
}
|
if (pkt->getRemainingBytes() < 4)
|
||||||
|
return;
|
||||||
|
*pkt >> lighting.volumetric_light_strength;
|
||||||
|
|
||||||
|
if (pkt->getRemainingBytes() < 4)
|
||||||
|
return;
|
||||||
|
*pkt >> lighting.ambient_light;
|
||||||
|
lighting.ambient_light.setAlpha(255); // alpha should always be 255
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "lua_api/l_object.h"
|
#include "lua_api/l_object.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include "common/c_types.h"
|
||||||
#include "lua_api/l_internal.h"
|
#include "lua_api/l_internal.h"
|
||||||
#include "lua_api/l_inventory.h"
|
#include "lua_api/l_inventory.h"
|
||||||
#include "lua_api/l_item.h"
|
#include "lua_api/l_item.h"
|
||||||
@ -2536,14 +2537,10 @@ int ObjectRef::l_set_lighting(lua_State *L)
|
|||||||
lua_pop(L, 1); // shadows
|
lua_pop(L, 1); // shadows
|
||||||
|
|
||||||
lua_getfield(L, 2, "ambient_light");
|
lua_getfield(L, 2, "ambient_light");
|
||||||
if(lua_istable(L, -1)) {
|
if (!lua_isnil(L, -1)) {
|
||||||
getintfield(L, -1, "luminance", lighting.ambient_light.luminance);
|
read_color(L, -1, &lighting.ambient_light);
|
||||||
lighting.ambient_light.luminance = rangelim(lighting.ambient_light.luminance, 0, LIGHT_SUN);
|
if (lighting.ambient_light.getAlpha() != 255)
|
||||||
|
throw LuaError("ambient light alpha must be 255");
|
||||||
lua_getfield(L, -1, "color");
|
|
||||||
if (!lua_isnil(L, -1))
|
|
||||||
read_color(L, -1, &lighting.ambient_light.color);
|
|
||||||
lua_pop(L, 1);
|
|
||||||
}
|
}
|
||||||
lua_pop(L, 1); // ambient light
|
lua_pop(L, 1); // ambient light
|
||||||
|
|
||||||
@ -2566,7 +2563,7 @@ int ObjectRef::l_set_lighting(lua_State *L)
|
|||||||
lighting.volumetric_light_strength = rangelim(lighting.volumetric_light_strength, 0.0f, 1.0f);
|
lighting.volumetric_light_strength = rangelim(lighting.volumetric_light_strength, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
lua_pop(L, 1); // volumetric_light
|
lua_pop(L, 1); // volumetric_light
|
||||||
}
|
}
|
||||||
|
|
||||||
getServer(L)->setLighting(player, lighting);
|
getServer(L)->setLighting(player, lighting);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1895,8 +1895,7 @@ void Server::SendSetLighting(session_t peer_id, const Lighting &lighting)
|
|||||||
|
|
||||||
pkt << lighting.volumetric_light_strength;
|
pkt << lighting.volumetric_light_strength;
|
||||||
|
|
||||||
pkt << lighting.ambient_light.luminance
|
pkt << lighting.ambient_light;
|
||||||
<< lighting.ambient_light.color;
|
|
||||||
|
|
||||||
Send(&pkt);
|
Send(&pkt);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user