mirror of
https://github.com/minetest/minetest.git
synced 2024-07-04 15:05:27 +02:00
Moved ambient light applying to the vertex shaders, tiny code cleanups
This commit is contained in:
parent
4a351df32b
commit
1aa03addec
@ -9,7 +9,6 @@ uniform float fogShadingParameter;
|
|||||||
uniform highp vec3 cameraOffset;
|
uniform highp vec3 cameraOffset;
|
||||||
uniform float animationTimer;
|
uniform float animationTimer;
|
||||||
|
|
||||||
uniform vec3 ambientLight;
|
|
||||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||||
// shadow texture
|
// shadow texture
|
||||||
uniform sampler2D ShadowMapSampler;
|
uniform sampler2D ShadowMapSampler;
|
||||||
@ -378,7 +377,7 @@ void main(void)
|
|||||||
|
|
||||||
color = base.rgb;
|
color = base.rgb;
|
||||||
|
|
||||||
vec4 col = vec4(color.rgb * min(varColor.rgb + ambientLight, 1.0), 1.0);
|
vec4 col = vec4(color.rgb * varColor.rgb, 1.0);
|
||||||
|
|
||||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||||
if (f_shadow_strength > 0.0) {
|
if (f_shadow_strength > 0.0) {
|
||||||
|
@ -6,6 +6,8 @@ uniform vec3 dayLight;
|
|||||||
uniform highp vec3 cameraOffset;
|
uniform highp vec3 cameraOffset;
|
||||||
uniform float animationTimer;
|
uniform float animationTimer;
|
||||||
|
|
||||||
|
uniform vec3 ambientLight;
|
||||||
|
|
||||||
varying vec3 vNormal;
|
varying vec3 vNormal;
|
||||||
varying vec3 vPosition;
|
varying vec3 vPosition;
|
||||||
// World position in the visible world (i.e. relative to the cameraOffset.)
|
// World position in the visible world (i.e. relative to the cameraOffset.)
|
||||||
@ -220,6 +222,8 @@ void main(void)
|
|||||||
color.b += max(0.0, 0.021 - abs(0.2 * brightness - 0.021) +
|
color.b += max(0.0, 0.021 - abs(0.2 * brightness - 0.021) +
|
||||||
0.07 * brightness);
|
0.07 * brightness);
|
||||||
|
|
||||||
|
color.rgb += ambientLight;
|
||||||
|
|
||||||
varColor = clamp(color, 0.0, 1.0);
|
varColor = clamp(color, 0.0, 1.0);
|
||||||
|
|
||||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||||
|
@ -9,7 +9,6 @@ uniform float fogShadingParameter;
|
|||||||
uniform highp vec3 cameraOffset;
|
uniform highp vec3 cameraOffset;
|
||||||
uniform float animationTimer;
|
uniform float animationTimer;
|
||||||
|
|
||||||
uniform vec3 ambientLight;
|
|
||||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||||
// shadow texture
|
// shadow texture
|
||||||
uniform sampler2D ShadowMapSampler;
|
uniform sampler2D ShadowMapSampler;
|
||||||
@ -381,7 +380,7 @@ void main(void)
|
|||||||
|
|
||||||
color = base.rgb;
|
color = base.rgb;
|
||||||
|
|
||||||
vec4 col = vec4(color.rgb * min(varColor.rgb + ambientLight, 1.0), 1.0);
|
vec4 col = vec4(color.rgb * varColor.rgb, 1.0);
|
||||||
col.rgb *= vIDiff;
|
col.rgb *= vIDiff;
|
||||||
|
|
||||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||||
|
@ -2,6 +2,7 @@ uniform mat4 mWorld;
|
|||||||
uniform vec3 dayLight;
|
uniform vec3 dayLight;
|
||||||
uniform float animationTimer;
|
uniform float animationTimer;
|
||||||
uniform lowp vec4 emissiveColor;
|
uniform lowp vec4 emissiveColor;
|
||||||
|
uniform vec3 ambientLight;
|
||||||
|
|
||||||
varying vec3 vNormal;
|
varying vec3 vNormal;
|
||||||
varying vec3 vPosition;
|
varying vec3 vPosition;
|
||||||
@ -129,6 +130,8 @@ void main(void)
|
|||||||
color.b += max(0.0, 0.021 - abs(0.2 * brightness - 0.021) +
|
color.b += max(0.0, 0.021 - abs(0.2 * brightness - 0.021) +
|
||||||
0.07 * brightness);
|
0.07 * brightness);
|
||||||
|
|
||||||
|
color.rgb += ambientLight;
|
||||||
|
|
||||||
varColor = clamp(color, 0.0, 1.0);
|
varColor = clamp(color, 0.0, 1.0);
|
||||||
|
|
||||||
|
|
||||||
|
@ -8395,9 +8395,10 @@ 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 is ignored (always set to 255)
|
* `ambient_light` is a ColorSpec controlling color of global ambient light;
|
||||||
(global lighting; default: `{a = 255, r = 0, g = 0, b = 0}` / last set value).
|
(default: `{a = 255, r = 0, g = 0, b = 0}` / last set value).
|
||||||
* It works only if 'enable_shaders' is set to true.
|
* It works only if shaders are enabled.
|
||||||
|
* Alpha is ignored (it is always set to 255).
|
||||||
* `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
|
||||||
|
@ -149,6 +149,7 @@ 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; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ClientMap *m_map;
|
ClientMap *m_map;
|
||||||
LocalPlayer *m_local_player = nullptr;
|
LocalPlayer *m_local_player = nullptr;
|
||||||
|
@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "nodedef.h"
|
#include "nodedef.h"
|
||||||
#include <IMeshManipulator.h>
|
#include <IMeshManipulator.h>
|
||||||
#include "client/localplayer.h"
|
|
||||||
|
|
||||||
struct MeshMakeData;
|
struct MeshMakeData;
|
||||||
struct MeshCollector;
|
struct MeshCollector;
|
||||||
|
@ -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, 3> m_ambient_light{"ambientLight"};
|
CachedVertexShaderSetting<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"};
|
||||||
@ -527,6 +527,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
|
|||||||
m_bloom_radius_pixel.set(&m_bloom_radius, services);
|
m_bloom_radius_pixel.set(&m_bloom_radius, services);
|
||||||
m_bloom_strength_pixel.set(&m_bloom_strength, services);
|
m_bloom_strength_pixel.set(&m_bloom_strength, services);
|
||||||
}
|
}
|
||||||
|
|
||||||
float saturation = lighting.saturation;
|
float saturation = lighting.saturation;
|
||||||
m_saturation_pixel.set(&saturation, services);
|
m_saturation_pixel.set(&saturation, services);
|
||||||
|
|
||||||
@ -569,6 +570,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
|
|||||||
float moon_brightness = 0.f;
|
float moon_brightness = 0.f;
|
||||||
m_moon_brightness_pixel.set(&moon_brightness, services);
|
m_moon_brightness_pixel.set(&moon_brightness, services);
|
||||||
}
|
}
|
||||||
|
|
||||||
float volumetric_light_strength = lighting.volumetric_light_strength;
|
float volumetric_light_strength = lighting.volumetric_light_strength;
|
||||||
m_volumetric_light_strength_pixel.set(&volumetric_light_strength, services);
|
m_volumetric_light_strength_pixel.set(&volumetric_light_strength, services);
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,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)
|
video::SColor ambientLight)
|
||||||
{
|
{
|
||||||
static const video::SColorf artificialColor(1.04f, 1.04f, 1.04f);
|
static const video::SColorf artificialColor(1.04f, 1.04f, 1.04f);
|
||||||
|
|
||||||
@ -813,7 +813,8 @@ MapBlockMesh::~MapBlockMesh()
|
|||||||
delete block;
|
delete block;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_ratio)
|
bool MapBlockMesh::animate(bool faraway, float time, int crack,
|
||||||
|
u32 daynight_ratio)
|
||||||
{
|
{
|
||||||
if (!m_has_animation) {
|
if (!m_has_animation) {
|
||||||
m_animation_force_timer = 100000;
|
m_animation_force_timer = 100000;
|
||||||
@ -884,7 +885,8 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
|
|||||||
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, day_color);
|
final_color_blend(&(vertices[j.first].Color), j.second,
|
||||||
|
day_color);
|
||||||
}
|
}
|
||||||
m_last_daynight_ratio = daynight_ratio;
|
m_last_daynight_ratio = daynight_ratio;
|
||||||
}
|
}
|
||||||
@ -958,10 +960,8 @@ video::SColor encode_light(u16 light, u8 emissive_light)
|
|||||||
// Get components
|
// Get components
|
||||||
u32 day = (light & 0xff);
|
u32 day = (light & 0xff);
|
||||||
u32 night = (light >> 8);
|
u32 night = (light >> 8);
|
||||||
|
|
||||||
// Add emissive light
|
// Add emissive light
|
||||||
night += emissive_light * 2.5f;
|
night += emissive_light * 2.5f;
|
||||||
|
|
||||||
if (night > 255)
|
if (night > 255)
|
||||||
night = 255;
|
night = 255;
|
||||||
// Since we don't know if the day light is sunlight or
|
// Since we don't know if the day light is sunlight or
|
||||||
|
@ -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=video::SColor(255,0,0,0));
|
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
|
||||||
|
@ -186,11 +186,11 @@ video::SColor Particle::updateLight(ClientEnvironment *env)
|
|||||||
else
|
else
|
||||||
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);
|
light += m_p.glow;
|
||||||
|
|
||||||
video::SColor light_color{0xFFFFFFFF};
|
video::SColor light_color{0xFFFFFFFF};
|
||||||
|
|
||||||
final_color_blend(&light_color, m_light, env->getDayNightRatio(),
|
final_color_blend(&light_color, u16(light), env->getDayNightRatio(),
|
||||||
env->getLocalPlayer()->getLighting().ambient_light);
|
env->getLocalPlayer()->getLighting().ambient_light);
|
||||||
return video::SColor(255,
|
return video::SColor(255,
|
||||||
light_color.getRed() * m_base_color.getRed() / 255,
|
light_color.getRed() * m_base_color.getRed() / 255,
|
||||||
|
@ -47,7 +47,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "skyparams.h"
|
#include "skyparams.h"
|
||||||
#include "particles.h"
|
#include "particles.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "client/clientmap.h"
|
|
||||||
|
|
||||||
void Client::handleCommand_Deprecated(NetworkPacket* pkt)
|
void Client::handleCommand_Deprecated(NetworkPacket* pkt)
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,6 @@ 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"
|
||||||
@ -36,7 +35,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "server/player_sao.h"
|
#include "server/player_sao.h"
|
||||||
#include "server/serverinventorymgr.h"
|
#include "server/serverinventorymgr.h"
|
||||||
#include "server/unit_sao.h"
|
#include "server/unit_sao.h"
|
||||||
#include "light.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ObjectRef
|
ObjectRef
|
||||||
|
Loading…
Reference in New Issue
Block a user