mirror of
https://github.com/minetest/minetest.git
synced 2024-07-04 15:05:27 +02:00
Support ambient light only for the shaders
This commit is contained in:
parent
8a7676d2f6
commit
41ab0eb0fd
@ -8397,6 +8397,7 @@ child will follow movement and rotation of that bone.
|
|||||||
* `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 must be 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.
|
||||||
* `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
|
||||||
|
@ -251,10 +251,10 @@ void ClientEnvironment::step(float dtime)
|
|||||||
// Update the ambient light
|
// Update the ambient light
|
||||||
auto new_ambient_light_clr = getLocalPlayer()->getLighting().ambient_light;
|
auto new_ambient_light_clr = getLocalPlayer()->getLighting().ambient_light;
|
||||||
|
|
||||||
if (new_ambient_light_clr != m_ambient_light) {
|
bool enable_shaders = g_settings->getBool("enable_shaders");
|
||||||
getClientMap().forceUpdateLightColor();
|
|
||||||
|
if (enable_shaders && (new_ambient_light_clr != m_ambient_light))
|
||||||
m_ambient_light = new_ambient_light_clr;
|
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();
|
||||||
@ -270,7 +270,12 @@ void ClientEnvironment::step(float dtime)
|
|||||||
|
|
||||||
u16 light = getInteriorLight(node_at_lplayer, 0, m_client->ndef());
|
u16 light = getInteriorLight(node_at_lplayer, 0, m_client->ndef());
|
||||||
lplayer->light_color = encode_light(light, 0); // this transfers light.alpha
|
lplayer->light_color = encode_light(light, 0); // this transfers light.alpha
|
||||||
final_color_blend(&lplayer->light_color, light, day_night_ratio, m_ambient_light);
|
|
||||||
|
video::SColor ambient_light(255, 0, 0, 0);
|
||||||
|
|
||||||
|
if (enable_shaders)
|
||||||
|
ambient_light = m_ambient_light;
|
||||||
|
final_color_blend(&lplayer->light_color, light, day_night_ratio, ambient_light);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -719,7 +719,6 @@ 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 auto ambient_light = m_client->getEnv().getAmbientLight();
|
|
||||||
|
|
||||||
const v3f camera_position = m_camera_position;
|
const v3f camera_position = m_camera_position;
|
||||||
|
|
||||||
@ -778,11 +777,10 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||||||
// Pretty random but this should work somewhat nicely
|
// Pretty random but this should work somewhat nicely
|
||||||
bool faraway = d >= BS * 50;
|
bool faraway = d >= BS * 50;
|
||||||
if (block_mesh->isAnimationForced() || !faraway ||
|
if (block_mesh->isAnimationForced() || !faraway ||
|
||||||
mesh_animate_count < (m_control.range_all ? 200 : 50) ||
|
mesh_animate_count < (m_control.range_all ? 200 : 50)) {
|
||||||
m_force_update_light_color) {
|
|
||||||
|
|
||||||
bool animated = block_mesh->animate(faraway, animation_time,
|
bool animated = block_mesh->animate(faraway, animation_time,
|
||||||
crack, daynight_ratio, ambient_light);
|
crack, daynight_ratio);
|
||||||
if (animated)
|
if (animated)
|
||||||
mesh_animate_count++;
|
mesh_animate_count++;
|
||||||
} else {
|
} else {
|
||||||
@ -826,8 +824,6 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_force_update_light_color = false;
|
|
||||||
|
|
||||||
// Capture draw order for all solid meshes
|
// Capture draw order for all solid meshes
|
||||||
for (auto &map : grouped_buffers.maps) {
|
for (auto &map : grouped_buffers.maps) {
|
||||||
for (auto &list : map) {
|
for (auto &list : map) {
|
||||||
|
@ -114,8 +114,6 @@ class ClientMap : public Map, public scene::ISceneNode
|
|||||||
|
|
||||||
void onSettingChanged(const std::string &name);
|
void onSettingChanged(const std::string &name);
|
||||||
|
|
||||||
void forceUpdateLightColor() { m_force_update_light_color = true; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// use drop() instead
|
// use drop() instead
|
||||||
virtual ~ClientMap();
|
virtual ~ClientMap();
|
||||||
@ -197,6 +195,4 @@ class ClientMap : public Map, public scene::ISceneNode
|
|||||||
|
|
||||||
bool m_loops_occlusion_culler;
|
bool m_loops_occlusion_culler;
|
||||||
bool m_enable_raytraced_culling;
|
bool m_enable_raytraced_culling;
|
||||||
|
|
||||||
bool m_force_update_light_color = false;
|
|
||||||
};
|
};
|
||||||
|
@ -909,8 +909,7 @@ void GenericCAO::updateLight(u32 day_night_ratio)
|
|||||||
if (m_enable_shaders)
|
if (m_enable_shaders)
|
||||||
light = encode_light(light_at_pos, m_prop.glow);
|
light = encode_light(light_at_pos, m_prop.glow);
|
||||||
else
|
else
|
||||||
final_color_blend(&light, light_at_pos, day_night_ratio,
|
final_color_blend(&light, light_at_pos, day_night_ratio);
|
||||||
m_client->getEnv().getAmbientLight());
|
|
||||||
|
|
||||||
if (light != m_last_light) {
|
if (light != m_last_light) {
|
||||||
m_last_light = light;
|
m_last_light = light;
|
||||||
|
@ -382,7 +382,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
|
|||||||
CachedPixelShaderSetting<float>
|
CachedPixelShaderSetting<float>
|
||||||
m_animation_timer_delta_pixel{"animationTimerDelta"};
|
m_animation_timer_delta_pixel{"animationTimerDelta"};
|
||||||
CachedPixelShaderSetting<float, 3> m_day_light{"dayLight"};
|
CachedPixelShaderSetting<float, 3> m_day_light{"dayLight"};
|
||||||
CachedPixelShaderSetting<float, 1> m_ambient_light{"ambientLight"};
|
CachedPixelShaderSetting<float, 3> m_ambient_light{"ambientLight"};
|
||||||
CachedPixelShaderSetting<float, 3> m_minimap_yaw{"yawVec"};
|
CachedPixelShaderSetting<float, 3> m_minimap_yaw{"yawVec"};
|
||||||
CachedPixelShaderSetting<float, 3> m_camera_offset_pixel{"cameraOffset"};
|
CachedPixelShaderSetting<float, 3> m_camera_offset_pixel{"cameraOffset"};
|
||||||
CachedVertexShaderSetting<float, 3> m_camera_offset_vertex{"cameraOffset"};
|
CachedVertexShaderSetting<float, 3> m_camera_offset_vertex{"cameraOffset"};
|
||||||
@ -474,14 +474,7 @@ 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);
|
||||||
|
|
||||||
auto ambient_light = m_client->getEnv().getAmbientLight();
|
video::SColorf ambient_light_f(m_client->getEnv().getAmbientLight());
|
||||||
|
|
||||||
float ambient_light_f[3] = {
|
|
||||||
ambient_light.getRed() / 255.f,
|
|
||||||
ambient_light.getGreen() / 255.f,
|
|
||||||
ambient_light.getBlue() / 255.f
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
||||||
@ -515,6 +508,8 @@ 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),
|
||||||
@ -3536,7 +3531,7 @@ PointedThing Game::updatePointedThing(
|
|||||||
|
|
||||||
u32 daynight_ratio = client->getEnv().getDayNightRatio();
|
u32 daynight_ratio = client->getEnv().getDayNightRatio();
|
||||||
video::SColor c;
|
video::SColor c;
|
||||||
final_color_blend(&c, light_level, daynight_ratio, client->getEnv().getAmbientLight());
|
final_color_blend(&c, light_level, daynight_ratio);
|
||||||
|
|
||||||
// Modify final color a bit with time
|
// Modify final color a bit with time
|
||||||
u32 timer = client->getEnv().getFrameTime() % 5000;
|
u32 timer = client->getEnv().getFrameTime() % 5000;
|
||||||
|
@ -725,15 +725,13 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs
|
|||||||
video::SColorf sunlight;
|
video::SColorf sunlight;
|
||||||
get_sunlight_color(&sunlight, 0);
|
get_sunlight_color(&sunlight, 0);
|
||||||
|
|
||||||
auto ambientlight = client->getEnv().getAmbientLight();
|
|
||||||
|
|
||||||
std::map<u32, video::SColor> colors;
|
std::map<u32, video::SColor> colors;
|
||||||
const u32 vertex_count = p.vertices.size();
|
const u32 vertex_count = p.vertices.size();
|
||||||
for (u32 j = 0; j < vertex_count; j++) {
|
for (u32 j = 0; j < vertex_count; j++) {
|
||||||
video::SColor *vc = &p.vertices[j].Color;
|
video::SColor *vc = &p.vertices[j].Color;
|
||||||
video::SColor copy = *vc;
|
video::SColor copy = *vc;
|
||||||
if (vc->getAlpha() == 0) // No sunlight - no need to animate
|
if (vc->getAlpha() == 0) // No sunlight - no need to animate
|
||||||
final_color_blend(vc, copy, sunlight, ambientlight); // Finalize color
|
final_color_blend(vc, copy, sunlight); // Finalize color
|
||||||
else // Record color to animate
|
else // Record color to animate
|
||||||
colors[j] = copy;
|
colors[j] = copy;
|
||||||
|
|
||||||
@ -745,17 +743,6 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs
|
|||||||
m_daynight_diffs[{layer, i}] = std::move(colors);
|
m_daynight_diffs[{layer, i}] = std::move(colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the ambient light to all vertices
|
|
||||||
/*auto ambient_light = data->m_client->getEnv().getAmbientLight();
|
|
||||||
|
|
||||||
for (u32 i = 0; i < p.vertices.size(); i++) {
|
|
||||||
video::SColor &vert_c = p.vertices[i].Color;
|
|
||||||
|
|
||||||
vert_c.setRed(vert_c.getRed() + ambient_light.getRed());
|
|
||||||
vert_c.setGreen(vert_c.getGreen() + ambient_light.getGreen());
|
|
||||||
vert_c.setBlue(vert_c.getBlue() + ambient_light.getBlue());
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Create material
|
// Create material
|
||||||
video::SMaterial material;
|
video::SMaterial material;
|
||||||
material.Lighting = false;
|
material.Lighting = false;
|
||||||
@ -826,8 +813,7 @@ MapBlockMesh::~MapBlockMesh()
|
|||||||
delete block;
|
delete block;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MapBlockMesh::animate(bool faraway, float time, int crack,
|
bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_ratio)
|
||||||
u32 daynight_ratio, video::SColor ambient_light)
|
|
||||||
{
|
{
|
||||||
if (!m_has_animation) {
|
if (!m_has_animation) {
|
||||||
m_animation_force_timer = 100000;
|
m_animation_force_timer = 100000;
|
||||||
@ -886,11 +872,11 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
video::SColorf day_color;
|
|
||||||
get_sunlight_color(&day_color, daynight_ratio);
|
|
||||||
|
|
||||||
// Day-night transition
|
// Day-night transition
|
||||||
if (!m_enable_shaders && (daynight_ratio != m_last_daynight_ratio)) {
|
if (!m_enable_shaders && (daynight_ratio != m_last_daynight_ratio)) {
|
||||||
|
video::SColorf day_color;
|
||||||
|
get_sunlight_color(&day_color, daynight_ratio);
|
||||||
|
|
||||||
for (auto &daynight_diff : m_daynight_diffs) {
|
for (auto &daynight_diff : m_daynight_diffs) {
|
||||||
auto *mesh = m_mesh[daynight_diff.first.first];
|
auto *mesh = m_mesh[daynight_diff.first.first];
|
||||||
mesh->setDirty(scene::EBT_VERTEX); // force reload to VBO
|
mesh->setDirty(scene::EBT_VERTEX); // force reload to VBO
|
||||||
@ -898,25 +884,11 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack,
|
|||||||
getMeshBuffer(daynight_diff.first.second);
|
getMeshBuffer(daynight_diff.first.second);
|
||||||
video::S3DVertex *vertices = (video::S3DVertex *)buf->getVertices();
|
video::S3DVertex *vertices = (video::S3DVertex *)buf->getVertices();
|
||||||
for (const auto &j : daynight_diff.second)
|
for (const auto &j : daynight_diff.second)
|
||||||
final_color_blend(&(vertices[j.first].Color), j.second,
|
final_color_blend(&(vertices[j.first].Color), j.second, day_color);
|
||||||
day_color, video::SColor(255, 0, 0, 0));
|
|
||||||
}
|
}
|
||||||
m_last_daynight_ratio = daynight_ratio;
|
m_last_daynight_ratio = daynight_ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ambient light
|
|
||||||
if (!m_enable_shaders) {
|
|
||||||
for (u32 i = 0; i < MAX_TILE_LAYERS; i++)
|
|
||||||
for (u32 j = 0; j < m_mesh[i]->getMeshBufferCount(); j++) {
|
|
||||||
scene::IMeshBuffer *buf = m_mesh[i]->getMeshBuffer(j);
|
|
||||||
video::S3DVertex *vertices = (video::S3DVertex *)buf->getVertices();
|
|
||||||
|
|
||||||
for (u32 k = 0; k < buf->getVertexCount(); k++)
|
|
||||||
final_color_blend(&(vertices[k].Color), vertices[k].Color,
|
|
||||||
day_color, ambient_light);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ class MapBlockMesh
|
|||||||
// daynight_ratio: 0 .. 1000
|
// daynight_ratio: 0 .. 1000
|
||||||
// crack: -1 .. CRACK_ANIMATION_LENGTH-1 (-1 for off)
|
// crack: -1 .. CRACK_ANIMATION_LENGTH-1 (-1 for off)
|
||||||
// Returns true if anything has been changed.
|
// Returns true if anything has been changed.
|
||||||
bool animate(bool faraway, float time, int crack, u32 daynight_ratio, video::SColor ambient_light);
|
bool animate(bool faraway, float time, int crack, u32 daynight_ratio);
|
||||||
|
|
||||||
scene::IMesh *getMesh()
|
scene::IMesh *getMesh()
|
||||||
{
|
{
|
||||||
@ -318,7 +318,7 @@ void get_sunlight_color(video::SColorf *sunlight, u32 daynight_ratio);
|
|||||||
* night light
|
* night light
|
||||||
*/
|
*/
|
||||||
void final_color_blend(video::SColor *result,
|
void final_color_blend(video::SColor *result,
|
||||||
u16 light, u32 daynight_ratio, video::SColor ambientLight);
|
u16 light, u32 daynight_ratio, video::SColor ambientLight=video::SColor(255,0,0,0));
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Gives the final SColor shown on screen.
|
* Gives the final SColor shown on screen.
|
||||||
@ -329,7 +329,7 @@ void final_color_blend(video::SColor *result,
|
|||||||
*/
|
*/
|
||||||
void final_color_blend(video::SColor *result,
|
void final_color_blend(video::SColor *result,
|
||||||
const video::SColor &data, const video::SColorf &dayLight,
|
const video::SColor &data, const video::SColorf &dayLight,
|
||||||
const video::SColor &ambientLight);
|
const video::SColor &ambientLight=video::SColor(255,0,0,0));
|
||||||
|
|
||||||
// Retrieves the TileSpec of a face of a node
|
// Retrieves the TileSpec of a face of a node
|
||||||
// Adds MATERIAL_FLAG_CRACK if the node is cracked
|
// Adds MATERIAL_FLAG_CRACK if the node is cracked
|
||||||
|
@ -51,7 +51,7 @@ struct Lighting
|
|||||||
{
|
{
|
||||||
AutoExposure exposure;
|
AutoExposure exposure;
|
||||||
/// @brief Ambient light color & intensity for nodes & entities. Alpha is ignored.
|
/// @brief Ambient light color & intensity for nodes & entities. Alpha is ignored.
|
||||||
video::SColor ambient_light = {255, 0, 0, 0};
|
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};
|
||||||
|
Loading…
Reference in New Issue
Block a user