aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/CMakeLists.txt4
-rw-r--r--src/client/client.cpp58
-rw-r--r--src/client/client.h10
-rw-r--r--src/client/clientevent.h2
-rw-r--r--src/client/clientlauncher.cpp26
-rw-r--r--src/client/clientlauncher.h1
-rw-r--r--src/client/clientmap.cpp241
-rw-r--r--src/client/clientmap.h11
-rw-r--r--src/client/clientmedia.cpp252
-rw-r--r--src/client/clientmedia.h159
-rw-r--r--src/client/clouds.cpp2
-rw-r--r--src/client/content_cao.cpp43
-rw-r--r--src/client/content_mapblock.cpp48
-rw-r--r--src/client/content_mapblock.h2
-rw-r--r--src/client/fontengine.cpp5
-rw-r--r--src/client/game.cpp241
-rw-r--r--src/client/game.h3
-rw-r--r--src/client/gameui.cpp40
-rw-r--r--src/client/gameui.h3
-rw-r--r--src/client/hud.cpp40
-rw-r--r--src/client/hud.h19
-rw-r--r--src/client/imagefilters.cpp9
-rw-r--r--src/client/inputhandler.cpp42
-rw-r--r--src/client/inputhandler.h45
-rw-r--r--src/client/joystick_controller.cpp24
-rw-r--r--src/client/joystick_controller.h5
-rw-r--r--src/client/localplayer.cpp24
-rw-r--r--src/client/mapblock_mesh.cpp32
-rw-r--r--src/client/render/core.cpp36
-rw-r--r--src/client/render/core.h5
-rw-r--r--src/client/renderingengine.cpp140
-rw-r--r--src/client/renderingengine.h19
-rw-r--r--src/client/shader.cpp72
-rw-r--r--src/client/shadows/dynamicshadows.cpp182
-rw-r--r--src/client/shadows/dynamicshadows.h109
-rw-r--r--src/client/shadows/dynamicshadowsrender.cpp630
-rw-r--r--src/client/shadows/dynamicshadowsrender.h147
-rw-r--r--src/client/shadows/shadowsScreenQuad.cpp61
-rw-r--r--src/client/shadows/shadowsScreenQuad.h54
-rw-r--r--src/client/shadows/shadowsshadercallbacks.cpp36
-rw-r--r--src/client/shadows/shadowsshadercallbacks.h48
-rw-r--r--src/client/sky.cpp38
-rw-r--r--src/client/sky.h7
-rw-r--r--src/client/sound_openal.cpp8
-rw-r--r--src/client/tile.cpp8
-rw-r--r--src/client/wieldmesh.cpp12
-rw-r--r--src/client/wieldmesh.h3
47 files changed, 2552 insertions, 454 deletions
diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt
index 140814911..8d058852a 100644
--- a/src/client/CMakeLists.txt
+++ b/src/client/CMakeLists.txt
@@ -58,5 +58,9 @@ set(client_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/sky.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tile.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wieldmesh.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/shadows/dynamicshadows.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/shadows/dynamicshadowsrender.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/shadows/shadowsshadercallbacks.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/shadows/shadowsScreenQuad.cpp
PARENT_SCOPE
)
diff --git a/src/client/client.cpp b/src/client/client.cpp
index 57f8e6593..3c4ea5f95 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -178,11 +178,7 @@ void Client::loadMods()
// Load "mod" scripts
for (const ModSpec &mod : m_mods) {
- if (!string_allowed(mod.name, MODNAME_ALLOWED_CHARS)) {
- throw ModError("Error loading mod \"" + mod.name +
- "\": Mod name does not follow naming conventions: "
- "Only characters [a-z0-9_] are allowed.");
- }
+ mod.checkAndLog();
scanModIntoMemory(mod.name, mod.path);
}
@@ -213,6 +209,9 @@ void Client::scanModSubfolder(const std::string &mod_name, const std::string &mo
std::string full_path = mod_path + DIR_DELIM + mod_subpath;
std::vector<fs::DirListNode> mod = fs::GetDirListing(full_path);
for (const fs::DirListNode &j : mod) {
+ if (j.name[0] == '.')
+ continue;
+
if (j.dir) {
scanModSubfolder(mod_name, mod_path, mod_subpath + j.name + DIR_DELIM);
continue;
@@ -559,6 +558,29 @@ void Client::step(float dtime)
m_media_downloader = NULL;
}
}
+ {
+ // Acknowledge dynamic media downloads to server
+ std::vector<u32> done;
+ for (auto it = m_pending_media_downloads.begin();
+ it != m_pending_media_downloads.end();) {
+ assert(it->second->isStarted());
+ it->second->step(this);
+ if (it->second->isDone()) {
+ done.emplace_back(it->first);
+
+ it = m_pending_media_downloads.erase(it);
+ } else {
+ it++;
+ }
+
+ if (done.size() == 255) { // maximum in one packet
+ sendHaveMedia(done);
+ done.clear();
+ }
+ }
+ if (!done.empty())
+ sendHaveMedia(done);
+ }
/*
If the server didn't update the inventory in a while, revert
@@ -774,7 +796,8 @@ void Client::request_media(const std::vector<std::string> &file_requests)
Send(&pkt);
infostream << "Client: Sending media request list to server ("
- << file_requests.size() << " files. packet size)" << std::endl;
+ << file_requests.size() << " files, packet size "
+ << pkt.getSize() << ")" << std::endl;
}
void Client::initLocalMapSaving(const Address &address,
@@ -1307,6 +1330,19 @@ void Client::sendPlayerPos()
sendPlayerPos(player->getLegitPosition());
}
+void Client::sendHaveMedia(const std::vector<u32> &tokens)
+{
+ NetworkPacket pkt(TOSERVER_HAVE_MEDIA, 1 + tokens.size() * 4);
+
+ sanity_check(tokens.size() < 256);
+
+ pkt << static_cast<u8>(tokens.size());
+ for (u32 token : tokens)
+ pkt << token;
+
+ Send(&pkt);
+}
+
void Client::removeNode(v3s16 p)
{
std::map<v3s16, MapBlock*> modified_blocks;
@@ -1679,13 +1715,13 @@ float Client::mediaReceiveProgress()
return 1.0; // downloader only exists when not yet done
}
-typedef struct TextureUpdateArgs {
+struct TextureUpdateArgs {
gui::IGUIEnvironment *guienv;
u64 last_time_ms;
u16 last_percent;
const wchar_t* text_base;
ITextureSource *tsrc;
-} TextureUpdateArgs;
+};
void Client::showUpdateProgressTexture(void *args, u32 progress, u32 max_progress)
{
@@ -1704,8 +1740,8 @@ void Client::showUpdateProgressTexture(void *args, u32 progress, u32 max_progres
if (do_draw) {
targs->last_time_ms = time_ms;
- std::basic_stringstream<wchar_t> strm;
- strm << targs->text_base << " " << targs->last_percent << "%...";
+ std::wostringstream strm;
+ strm << targs->text_base << L" " << targs->last_percent << L"%...";
m_rendering_engine->draw_load_screen(strm.str(), targs->guienv, targs->tsrc, 0,
72 + (u16) ((18. / 100.) * (double) targs->last_percent), true);
}
@@ -1758,7 +1794,7 @@ void Client::afterContentReceived()
tu_args.guienv = guienv;
tu_args.last_time_ms = porting::getTimeMs();
tu_args.last_percent = 0;
- tu_args.text_base = wgettext("Initializing nodes");
+ tu_args.text_base = wgettext("Initializing nodes");
tu_args.tsrc = m_tsrc;
m_nodedef->updateTextures(this, &tu_args);
delete[] tu_args.text_base;
diff --git a/src/client/client.h b/src/client/client.h
index 8d7f63c0c..1493d3ce3 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -52,6 +52,7 @@ class ISoundManager;
class NodeDefManager;
//class IWritableCraftDefManager;
class ClientMediaDownloader;
+class SingleMediaDownloader;
struct MapDrawControl;
class ModChannelMgr;
class MtEventManager;
@@ -244,6 +245,7 @@ public:
void sendDamage(u16 damage);
void sendRespawn();
void sendReady();
+ void sendHaveMedia(const std::vector<u32> &tokens);
ClientEnvironment& getEnv() { return m_env; }
ITextureSource *tsrc() { return getTextureSource(); }
@@ -324,6 +326,10 @@ public:
m_access_denied = true;
m_access_denied_reason = reason;
}
+ inline void setFatalError(const LuaError &e)
+ {
+ setFatalError(std::string("Lua: ") + e.what());
+ }
// Renaming accessDeniedReason to better name could be good as it's used to
// disconnect client when CSM failed.
@@ -542,9 +548,13 @@ private:
bool m_activeobjects_received = false;
bool m_mods_loaded = false;
+ std::vector<std::string> m_remote_media_servers;
+ // Media downloader, only exists during init
ClientMediaDownloader *m_media_downloader;
// Set of media filenames pushed by server at runtime
std::unordered_set<std::string> m_media_pushed_files;
+ // Pending downloads of dynamic media (key: token)
+ std::vector<std::pair<u32, std::unique_ptr<SingleMediaDownloader>>> m_pending_media_downloads;
// time_of_day speed approximation for old protocol
bool m_time_of_day_set = false;
diff --git a/src/client/clientevent.h b/src/client/clientevent.h
index 2215aecbd..17d3aedd6 100644
--- a/src/client/clientevent.h
+++ b/src/client/clientevent.h
@@ -59,7 +59,7 @@ struct ClientEventHudAdd
v2f pos, scale;
std::string name;
std::string text, text2;
- u32 number, item, dir;
+ u32 number, item, dir, style;
v2f align, offset;
v3f world_pos;
v2s32 size;
diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp
index 6db5f2e70..6ab610670 100644
--- a/src/client/clientlauncher.cpp
+++ b/src/client/clientlauncher.cpp
@@ -99,10 +99,6 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
init_args(start_data, cmd_args);
- // List video modes if requested
- if (list_video_modes)
- return m_rendering_engine->print_video_modes();
-
#if USE_SOUND
if (g_settings->getBool("enable_sound"))
g_sound_manager_singleton = createSoundManagerSingleton();
@@ -277,14 +273,6 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
chat_backend,
&reconnect_requested
);
- m_rendering_engine->get_scene_manager()->clear();
-
-#ifdef HAVE_TOUCHSCREENGUI
- delete g_touchscreengui;
- g_touchscreengui = NULL;
- receiver->m_touchscreengui = NULL;
-#endif
-
} //try
catch (con::PeerNotFoundException &e) {
error_message = gettext("Connection error (timed out?)");
@@ -300,6 +288,14 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
}
#endif
+ m_rendering_engine->get_scene_manager()->clear();
+
+#ifdef HAVE_TOUCHSCREENGUI
+ delete g_touchscreengui;
+ g_touchscreengui = NULL;
+ receiver->m_touchscreengui = NULL;
+#endif
+
// If no main menu, show error and exit
if (skip_main_menu) {
if (!error_message.empty()) {
@@ -336,8 +332,6 @@ void ClientLauncher::init_args(GameStartData &start_data, const Settings &cmd_ar
if (cmd_args.exists("name"))
start_data.name = cmd_args.get("name");
- list_video_modes = cmd_args.getFlag("videomodes");
-
random_input = g_settings->getBool("random_input")
|| cmd_args.getFlag("random-input");
}
@@ -518,8 +512,8 @@ bool ClientLauncher::launch_game(std::string &error_message,
// Load gamespec for required game
start_data.game_spec = findWorldSubgame(worldspec.path);
if (!start_data.game_spec.isValid()) {
- error_message = gettext("Could not find or load game \"")
- + worldspec.gameid + "\"";
+ error_message = gettext("Could not find or load game: ")
+ + worldspec.gameid;
errorstream << error_message << std::endl;
return false;
}
diff --git a/src/client/clientlauncher.h b/src/client/clientlauncher.h
index 79727e1fe..d1fd9a258 100644
--- a/src/client/clientlauncher.h
+++ b/src/client/clientlauncher.h
@@ -46,7 +46,6 @@ private:
void speed_tests();
- bool list_video_modes = false;
bool skip_main_menu = false;
bool random_input = false;
RenderingEngine *m_rendering_engine = nullptr;
diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp
index 29a7fd3ba..4a4784f91 100644
--- a/src/client/clientmap.cpp
+++ b/src/client/clientmap.cpp
@@ -72,8 +72,15 @@ ClientMap::ClientMap(
scene::ISceneNode(rendering_engine->get_scene_manager()->getRootSceneNode(),
rendering_engine->get_scene_manager(), id),
m_client(client),
+ m_rendering_engine(rendering_engine),
m_control(control)
{
+
+ /*
+ * @Liso: Sadly C++ doesn't have introspection, so the only way we have to know
+ * the class is whith a name ;) Name property cames from ISceneNode base class.
+ */
+ Name = "ClientMap";
m_box = aabb3f(-BS*1000000,-BS*1000000,-BS*1000000,
BS*1000000,BS*1000000,BS*1000000);
@@ -115,12 +122,21 @@ void ClientMap::OnRegisterSceneNode()
}
ISceneNode::OnRegisterSceneNode();
+
+ if (!m_added_to_shadow_renderer) {
+ m_added_to_shadow_renderer = true;
+ if (auto shadows = m_rendering_engine->get_shadow_renderer())
+ shadows->addNodeToShadowList(this);
+ }
}
void ClientMap::getBlocksInViewRange(v3s16 cam_pos_nodes,
- v3s16 *p_blocks_min, v3s16 *p_blocks_max)
+ v3s16 *p_blocks_min, v3s16 *p_blocks_max, float range)
{
- v3s16 box_nodes_d = m_control.wanted_range * v3s16(1, 1, 1);
+ if (range <= 0.0f)
+ range = m_control.wanted_range;
+
+ v3s16 box_nodes_d = range * v3s16(1, 1, 1);
// Define p_nodes_min/max as v3s32 because 'cam_pos_nodes -/+ box_nodes_d'
// can exceed the range of v3s16 when a large view range is used near the
// world edges.
@@ -321,7 +337,6 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
// Mesh animation
if (pass == scene::ESNRP_SOLID) {
- //MutexAutoLock lock(block->mesh_mutex);
MapBlockMesh *mapBlockMesh = block->mesh;
assert(mapBlockMesh);
// Pretty random but this should work somewhat nicely
@@ -342,8 +357,6 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
Get the meshbuffers of the block
*/
{
- //MutexAutoLock lock(block->mesh_mutex);
-
MapBlockMesh *mapBlockMesh = block->mesh;
assert(mapBlockMesh);
@@ -394,6 +407,17 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
"returning." << std::endl;
return;
}
+
+ // pass the shadow map texture to the buffer texture
+ ShadowRenderer *shadow = m_rendering_engine->get_shadow_renderer();
+ if (shadow && shadow->is_active()) {
+ auto &layer = list.m.TextureLayer[3];
+ layer.Texture = shadow->get_texture();
+ layer.TextureWrapU = video::E_TEXTURE_CLAMP::ETC_CLAMP_TO_EDGE;
+ layer.TextureWrapV = video::E_TEXTURE_CLAMP::ETC_CLAMP_TO_EDGE;
+ layer.TrilinearFilter = true;
+ }
+
driver->setMaterial(list.m);
drawcall_count += list.bufs.size();
@@ -610,3 +634,210 @@ void ClientMap::PrintInfo(std::ostream &out)
{
out<<"ClientMap: ";
}
+
+void ClientMap::renderMapShadows(video::IVideoDriver *driver,
+ const video::SMaterial &material, s32 pass, int frame, int total_frames)
+{
+ bool is_transparent_pass = pass != scene::ESNRP_SOLID;
+ std::string prefix;
+ if (is_transparent_pass)
+ prefix = "renderMap(SHADOW TRANS): ";
+ else
+ prefix = "renderMap(SHADOW SOLID): ";
+
+ u32 drawcall_count = 0;
+ u32 vertex_count = 0;
+
+ MeshBufListList drawbufs;
+
+ int count = 0;
+ int low_bound = is_transparent_pass ? 0 : m_drawlist_shadow.size() / total_frames * frame;
+ int high_bound = is_transparent_pass ? m_drawlist_shadow.size() : m_drawlist_shadow.size() / total_frames * (frame + 1);
+
+ // transparent pass should be rendered in one go
+ if (is_transparent_pass && frame != total_frames - 1) {
+ return;
+ }
+
+ for (auto &i : m_drawlist_shadow) {
+ // only process specific part of the list & break early
+ ++count;
+ if (count <= low_bound)
+ continue;
+ if (count > high_bound)
+ break;
+
+ v3s16 block_pos = i.first;
+ MapBlock *block = i.second;
+
+ // If the mesh of the block happened to get deleted, ignore it
+ if (!block->mesh)
+ continue;
+
+ /*
+ Get the meshbuffers of the block
+ */
+ {
+ MapBlockMesh *mapBlockMesh = block->mesh;
+ assert(mapBlockMesh);
+
+ for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) {
+ scene::IMesh *mesh = mapBlockMesh->getMesh(layer);
+ assert(mesh);
+
+ u32 c = mesh->getMeshBufferCount();
+ for (u32 i = 0; i < c; i++) {
+ scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
+
+ video::SMaterial &mat = buf->getMaterial();
+ auto rnd = driver->getMaterialRenderer(mat.MaterialType);
+ bool transparent = rnd && rnd->isTransparent();
+ if (transparent == is_transparent_pass)
+ drawbufs.add(buf, block_pos, layer);
+ }
+ }
+ }
+ }
+
+ TimeTaker draw("Drawing shadow mesh buffers");
+
+ core::matrix4 m; // Model matrix
+ v3f offset = intToFloat(m_camera_offset, BS);
+
+ // Render all layers in order
+ for (auto &lists : drawbufs.lists) {
+ for (MeshBufList &list : lists) {
+ // Check and abort if the machine is swapping a lot
+ if (draw.getTimerTime() > 1000) {
+ infostream << "ClientMap::renderMapShadows(): Rendering "
+ "took >1s, returning." << std::endl;
+ break;
+ }
+ for (auto &pair : list.bufs) {
+ scene::IMeshBuffer *buf = pair.second;
+
+ // override some material properties
+ video::SMaterial local_material = buf->getMaterial();
+ local_material.MaterialType = material.MaterialType;
+ local_material.BackfaceCulling = material.BackfaceCulling;
+ local_material.FrontfaceCulling = material.FrontfaceCulling;
+ local_material.BlendOperation = material.BlendOperation;
+ local_material.Lighting = false;
+ driver->setMaterial(local_material);
+
+ v3f block_wpos = intToFloat(pair.first * MAP_BLOCKSIZE, BS);
+ m.setTranslation(block_wpos - offset);
+
+ driver->setTransform(video::ETS_WORLD, m);
+ driver->drawMeshBuffer(buf);
+ vertex_count += buf->getVertexCount();
+ }
+
+ drawcall_count += list.bufs.size();
+ }
+ }
+
+ // restore the driver material state
+ video::SMaterial clean;
+ clean.BlendOperation = video::EBO_ADD;
+ driver->setMaterial(clean); // reset material to defaults
+ driver->draw3DLine(v3f(), v3f(), video::SColor(0));
+
+ g_profiler->avg(prefix + "draw meshes [ms]", draw.stop(true));
+ g_profiler->avg(prefix + "vertices drawn [#]", vertex_count);
+ g_profiler->avg(prefix + "drawcalls [#]", drawcall_count);
+}
+
+/*
+ Custom update draw list for the pov of shadow light.
+*/
+void ClientMap::updateDrawListShadow(const v3f &shadow_light_pos, const v3f &shadow_light_dir, float shadow_range)
+{
+ ScopeProfiler sp(g_profiler, "CM::updateDrawListShadow()", SPT_AVG);
+
+ const v3f camera_position = shadow_light_pos;
+ const v3f camera_direction = shadow_light_dir;
+ // I "fake" fov just to avoid creating a new function to handle orthographic
+ // projection.
+ const f32 camera_fov = m_camera_fov * 1.9f;
+
+ v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
+ v3s16 p_blocks_min;
+ v3s16 p_blocks_max;
+ getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max, shadow_range);
+
+ std::vector<v2s16> blocks_in_range;
+
+ for (auto &i : m_drawlist_shadow) {
+ MapBlock *block = i.second;
+ block->refDrop();
+ }
+ m_drawlist_shadow.clear();
+
+ // We need to append the blocks from the camera POV because sometimes
+ // they are not inside the light frustum and it creates glitches.
+ // FIXME: This could be removed if we figure out why they are missing
+ // from the light frustum.
+ for (auto &i : m_drawlist) {
+ i.second->refGrab();
+ m_drawlist_shadow[i.first] = i.second;
+ }
+
+ // Number of blocks currently loaded by the client
+ u32 blocks_loaded = 0;
+ // Number of blocks with mesh in rendering range
+ u32 blocks_in_range_with_mesh = 0;
+ // Number of blocks occlusion culled
+ u32 blocks_occlusion_culled = 0;
+
+ for (auto &sector_it : m_sectors) {
+ MapSector *sector = sector_it.second;
+ if (!sector)
+ continue;
+ blocks_loaded += sector->size();
+
+ MapBlockVect sectorblocks;
+ sector->getBlocks(sectorblocks);
+
+ /*
+ Loop through blocks in sector
+ */
+ for (MapBlock *block : sectorblocks) {
+ if (!block->mesh) {
+ // Ignore if mesh doesn't exist
+ continue;
+ }
+
+ float range = shadow_range;
+
+ float d = 0.0;
+ if (!isBlockInSight(block->getPos(), camera_position,
+ camera_direction, camera_fov, range, &d))
+ continue;
+
+ blocks_in_range_with_mesh++;
+
+ /*
+ Occlusion culling
+ */
+ if (isBlockOccluded(block, cam_pos_nodes)) {
+ blocks_occlusion_culled++;
+ continue;
+ }
+
+ // This block is in range. Reset usage timer.
+ block->resetUsageTimer();
+
+ // Add to set
+ if (m_drawlist_shadow.find(block->getPos()) == m_drawlist_shadow.end()) {
+ block->refGrab();
+ m_drawlist_shadow[block->getPos()] = block;
+ }
+ }
+ }
+
+ g_profiler->avg("SHADOW MapBlock meshes in range [#]", blocks_in_range_with_mesh);
+ g_profiler->avg("SHADOW MapBlocks occlusion culled [#]", blocks_occlusion_culled);
+ g_profiler->avg("SHADOW MapBlocks drawn [#]", m_drawlist_shadow.size());
+ g_profiler->avg("SHADOW MapBlocks loaded [#]", blocks_loaded);
+}
diff --git a/src/client/clientmap.h b/src/client/clientmap.h
index 80add4a44..97ce8d355 100644
--- a/src/client/clientmap.h
+++ b/src/client/clientmap.h
@@ -119,10 +119,14 @@ public:
}
void getBlocksInViewRange(v3s16 cam_pos_nodes,
- v3s16 *p_blocks_min, v3s16 *p_blocks_max);
+ v3s16 *p_blocks_min, v3s16 *p_blocks_max, float range=-1.0f);
void updateDrawList();
+ void updateDrawListShadow(const v3f &shadow_light_pos, const v3f &shadow_light_dir, float shadow_range);
void renderMap(video::IVideoDriver* driver, s32 pass);
+ void renderMapShadows(video::IVideoDriver *driver,
+ const video::SMaterial &material, s32 pass, int frame, int total_frames);
+
int getBackgroundBrightness(float max_d, u32 daylight_factor,
int oldvalue, bool *sunlight_seen_result);
@@ -132,9 +136,12 @@ public:
virtual void PrintInfo(std::ostream &out);
const MapDrawControl & getControl() const { return m_control; }
+ f32 getWantedRange() const { return m_control.wanted_range; }
f32 getCameraFov() const { return m_camera_fov; }
+
private:
Client *m_client;
+ RenderingEngine *m_rendering_engine;
aabb3f m_box = aabb3f(-BS * 1000000, -BS * 1000000, -BS * 1000000,
BS * 1000000, BS * 1000000, BS * 1000000);
@@ -147,10 +154,12 @@ private:
v3s16 m_camera_offset;
std::map<v3s16, MapBlock*> m_drawlist;
+ std::map<v3s16, MapBlock*> m_drawlist_shadow;
std::set<v2s16> m_last_drawn_sectors;
bool m_cache_trilinear_filter;
bool m_cache_bilinear_filter;
bool m_cache_anistropic_filter;
+ bool m_added_to_shadow_renderer{false};
};
diff --git a/src/client/clientmedia.cpp b/src/client/clientmedia.cpp
index 0f9ba5356..6c5d4a8bf 100644
--- a/src/client/clientmedia.cpp
+++ b/src/client/clientmedia.cpp
@@ -49,7 +49,6 @@ bool clientMediaUpdateCache(const std::string &raw_hash, const std::string &file
*/
ClientMediaDownloader::ClientMediaDownloader():
- m_media_cache(getMediaCacheDir()),
m_httpfetch_caller(HTTPFETCH_DISCARD)
{
}
@@ -66,6 +65,12 @@ ClientMediaDownloader::~ClientMediaDownloader()
delete remote;
}
+bool ClientMediaDownloader::loadMedia(Client *client, const std::string &data,
+ const std::string &name)
+{
+ return client->loadMedia(data, name);
+}
+
void ClientMediaDownloader::addFile(const std::string &name, const std::string &sha1)
{
assert(!m_initial_step_done); // pre-condition
@@ -105,7 +110,7 @@ void ClientMediaDownloader::addRemoteServer(const std::string &baseurl)
{
assert(!m_initial_step_done); // pre-condition
- #ifdef USE_CURL
+#ifdef USE_CURL
if (g_settings->getBool("enable_remote_media_server")) {
infostream << "Client: Adding remote server \""
@@ -117,13 +122,13 @@ void ClientMediaDownloader::addRemoteServer(const std::string &baseurl)
m_remotes.push_back(remote);
}
- #else
+#else
infostream << "Client: Ignoring remote server \""
<< baseurl << "\" because cURL support is not compiled in"
<< std::endl;
- #endif
+#endif
}
void ClientMediaDownloader::step(Client *client)
@@ -172,36 +177,21 @@ void ClientMediaDownloader::initialStep(Client *client)
// Check media cache
m_uncached_count = m_files.size();
for (auto &file_it : m_files) {
- std::string name = file_it.first;
+ const std::string &name = file_it.first;
FileStatus *filestatus = file_it.second;
const std::string &sha1 = filestatus->sha1;
- std::ostringstream tmp_os(std::ios_base::binary);
- bool found_in_cache = m_media_cache.load(hex_encode(sha1), tmp_os);
-
- // If found in cache, try to load it from there
- if (found_in_cache) {
- bool success = checkAndLoad(name, sha1,
- tmp_os.str(), true, client);
- if (success) {
- filestatus->received = true;
- m_uncached_count--;
- }
+ if (tryLoadFromCache(name, sha1, client)) {
+ filestatus->received = true;
+ m_uncached_count--;
}
}
assert(m_uncached_received_count == 0);
// Create the media cache dir if we are likely to write to it
- if (m_uncached_count != 0) {
- bool did = fs::CreateAllDirs(getMediaCacheDir());
- if (!did) {
- errorstream << "Client: "
- << "Could not create media cache directory: "
- << getMediaCacheDir()
- << std::endl;
- }
- }
+ if (m_uncached_count != 0)
+ createCacheDirs();
// If we found all files in the cache, report this fact to the server.
// If the server reported no remote servers, immediately start
@@ -301,8 +291,7 @@ void ClientMediaDownloader::remoteHashSetReceived(
// available on this server, add this server
// to the available_remotes array
- for(std::map<std::string, FileStatus*>::iterator
- it = m_files.upper_bound(m_name_bound);
+ for(auto it = m_files.upper_bound(m_name_bound);
it != m_files.end(); ++it) {
FileStatus *f = it->second;
if (!f->received && sha1_set.count(f->sha1))
@@ -328,8 +317,7 @@ void ClientMediaDownloader::remoteMediaReceived(
std::string name;
{
- std::unordered_map<unsigned long, std::string>::iterator it =
- m_remote_file_transfers.find(fetch_result.request_id);
+ auto it = m_remote_file_transfers.find(fetch_result.request_id);
assert(it != m_remote_file_transfers.end());
name = it->second;
m_remote_file_transfers.erase(it);
@@ -398,8 +386,7 @@ void ClientMediaDownloader::startRemoteMediaTransfers()
{
bool changing_name_bound = true;
- for (std::map<std::string, FileStatus*>::iterator
- files_iter = m_files.upper_bound(m_name_bound);
+ for (auto files_iter = m_files.upper_bound(m_name_bound);
files_iter != m_files.end(); ++files_iter) {
// Abort if active fetch limit is exceeded
@@ -477,19 +464,18 @@ void ClientMediaDownloader::startConventionalTransfers(Client *client)
}
}
-void ClientMediaDownloader::conventionalTransferDone(
+bool ClientMediaDownloader::conventionalTransferDone(
const std::string &name,
const std::string &data,
Client *client)
{
// Check that file was announced
- std::map<std::string, FileStatus*>::iterator
- file_iter = m_files.find(name);
+ auto file_iter = m_files.find(name);
if (file_iter == m_files.end()) {
errorstream << "Client: server sent media file that was"
<< "not announced, ignoring it: \"" << name << "\""
<< std::endl;
- return;
+ return false;
}
FileStatus *filestatus = file_iter->second;
assert(filestatus != NULL);
@@ -499,7 +485,7 @@ void ClientMediaDownloader::conventionalTransferDone(
errorstream << "Client: server sent media file that we already"
<< "received, ignoring it: \"" << name << "\""
<< std::endl;
- return;
+ return true;
}
// Mark file as received, regardless of whether loading it works and
@@ -512,9 +498,45 @@ void ClientMediaDownloader::conventionalTransferDone(
// Check that received file matches announced checksum
// If so, load it
checkAndLoad(name, filestatus->sha1, data, false, client);
+
+ return true;
+}
+
+/*
+ IClientMediaDownloader
+*/
+
+IClientMediaDownloader::IClientMediaDownloader():
+ m_media_cache(getMediaCacheDir()), m_write_to_cache(true)
+{
}
-bool ClientMediaDownloader::checkAndLoad(
+void IClientMediaDownloader::createCacheDirs()
+{
+ if (!m_write_to_cache)
+ return;
+
+ std::string path = getMediaCacheDir();
+ if (!fs::CreateAllDirs(path)) {
+ errorstream << "Client: Could not create media cache directory: "
+ << path << std::endl;
+ }
+}
+
+bool IClientMediaDownloader::tryLoadFromCache(const std::string &name,
+ const std::string &sha1, Client *client)
+{
+ std::ostringstream tmp_os(std::ios_base::binary);
+ bool found_in_cache = m_media_cache.load(hex_encode(sha1), tmp_os);
+
+ // If found in cache, try to load it from there
+ if (found_in_cache)
+ return checkAndLoad(name, sha1, tmp_os.str(), true, client);
+
+ return false;
+}
+
+bool IClientMediaDownloader::checkAndLoad(
const std::string &name, const std::string &sha1,
const std::string &data, bool is_from_cache, Client *client)
{
@@ -544,7 +566,7 @@ bool ClientMediaDownloader::checkAndLoad(
}
// Checksum is ok, try loading the file
- bool success = client->loadMedia(data, name);
+ bool success = loadMedia(client, data, name);
if (!success) {
infostream << "Client: "
<< "Failed to load " << cached_or_received << " media: "
@@ -559,7 +581,7 @@ bool ClientMediaDownloader::checkAndLoad(
<< std::endl;
// Update cache (unless we just loaded the file from the cache)
- if (!is_from_cache)
+ if (!is_from_cache && m_write_to_cache)
m_media_cache.update(sha1_hex, data);
return true;
@@ -587,12 +609,10 @@ std::string ClientMediaDownloader::serializeRequiredHashSet()
// Write list of hashes of files that have not been
// received (found in cache) yet
- for (std::map<std::string, FileStatus*>::iterator
- it = m_files.begin();
- it != m_files.end(); ++it) {
- if (!it->second->received) {
- FATAL_ERROR_IF(it->second->sha1.size() != 20, "Invalid SHA1 size");
- os << it->second->sha1;
+ for (const auto &it : m_files) {
+ if (!it.second->received) {
+ FATAL_ERROR_IF(it.second->sha1.size() != 20, "Invalid SHA1 size");
+ os << it.second->sha1;
}
}
@@ -628,3 +648,145 @@ void ClientMediaDownloader::deSerializeHashSet(const std::string &data,
result.insert(data.substr(pos, 20));
}
}
+
+/*
+ SingleMediaDownloader
+*/
+
+SingleMediaDownloader::SingleMediaDownloader(bool write_to_cache):
+ m_httpfetch_caller(HTTPFETCH_DISCARD)
+{
+ m_write_to_cache = write_to_cache;
+}
+
+SingleMediaDownloader::~SingleMediaDownloader()
+{
+ if (m_httpfetch_caller != HTTPFETCH_DISCARD)
+ httpfetch_caller_free(m_httpfetch_caller);
+}
+
+bool SingleMediaDownloader::loadMedia(Client *client, const std::string &data,
+ const std::string &name)
+{
+ return client->loadMedia(data, name, true);
+}
+
+void SingleMediaDownloader::addFile(const std::string &name, const std::string &sha1)
+{
+ assert(m_stage == STAGE_INIT); // pre-condition
+
+ assert(!name.empty());
+ assert(sha1.size() == 20);
+
+ FATAL_ERROR_IF(!m_file_name.empty(), "Cannot add a second file");
+ m_file_name = name;
+ m_file_sha1 = sha1;
+}
+
+void SingleMediaDownloader::addRemoteServer(const std::string &baseurl)
+{
+ assert(m_stage == STAGE_INIT); // pre-condition
+
+ if (g_settings->getBool("enable_remote_media_server"))
+ m_remotes.emplace_back(baseurl);
+}
+
+void SingleMediaDownloader::step(Client *client)
+{
+ if (m_stage == STAGE_INIT) {
+ m_stage = STAGE_CACHE_CHECKED;
+ initialStep(client);
+ }
+
+ // Remote media: check for completion of fetches
+ if (m_httpfetch_caller != HTTPFETCH_DISCARD) {
+ HTTPFetchResult fetch_result;
+ while (httpfetch_async_get(m_httpfetch_caller, fetch_result)) {
+ remoteMediaReceived(fetch_result, client);
+ }
+ }
+}
+
+bool SingleMediaDownloader::conventionalTransferDone(const std::string &name,
+ const std::string &data, Client *client)
+{
+ if (name != m_file_name)
+ return false;
+
+ // Mark file as received unconditionally and try to load it
+ m_stage = STAGE_DONE;
+ checkAndLoad(name, m_file_sha1, data, false, client);
+ return true;
+}
+
+void SingleMediaDownloader::initialStep(Client *client)
+{
+ if (tryLoadFromCache(m_file_name, m_file_sha1, client))
+ m_stage = STAGE_DONE;
+ if (isDone())
+ return;
+
+ createCacheDirs();
+
+ // If the server reported no remote servers, immediately fall back to
+ // conventional transfer.
+ if (!USE_CURL || m_remotes.empty()) {
+ startConventionalTransfer(client);
+ } else {
+ // Otherwise start by requesting the file from the first remote media server
+ m_httpfetch_caller = httpfetch_caller_alloc();
+ m_current_remote = 0;
+ startRemoteMediaTransfer();
+ }
+}
+
+void SingleMediaDownloader::remoteMediaReceived(
+ const HTTPFetchResult &fetch_result, Client *client)
+{
+ sanity_check(!isDone());
+ sanity_check(m_current_remote >= 0);
+
+ // If fetch succeeded, try to load it
+ if (fetch_result.succeeded) {
+ bool success = checkAndLoad(m_file_name, m_file_sha1,
+ fetch_result.data, false, client);
+ if (success) {
+ m_stage = STAGE_DONE;
+ return;
+ }
+ }
+
+ // Otherwise try the next remote server or fall back to conventional transfer
+ m_current_remote++;
+ if (m_current_remote >= (int)m_remotes.size()) {
+ infostream << "Client: Failed to remote-fetch \"" << m_file_name
+ << "\". Requesting it the usual way." << std::endl;
+ m_current_remote = -1;
+ startConventionalTransfer(client);
+ } else {
+ startRemoteMediaTransfer();
+ }
+}
+
+void SingleMediaDownloader::startRemoteMediaTransfer()
+{
+ std::string url = m_remotes.at(m_current_remote) + hex_encode(m_file_sha1);
+ verbosestream << "Client: Requesting remote media file "
+ << "\"" << m_file_name << "\" " << "\"" << url << "\"" << std::endl;
+
+ HTTPFetchRequest fetch_request;
+ fetch_request.url = url;
+ fetch_request.caller = m_httpfetch_caller;
+ fetch_request.request_id = m_httpfetch_next_id;
+ fetch_request.timeout = g_settings->getS32("curl_file_download_timeout");
+ httpfetch_async(fetch_request);
+
+ m_httpfetch_next_id++;
+}
+
+void SingleMediaDownloader::startConventionalTransfer(Client *client)
+{
+ std::vector<std::string> requests;
+ requests.emplace_back(m_file_name);
+ client->request_media(requests);
+}
diff --git a/src/client/clientmedia.h b/src/client/clientmedia.h
index e97a0f24b..aa7b0f398 100644
--- a/src/client/clientmedia.h
+++ b/src/client/clientmedia.h
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes.h"
#include "filecache.h"
+#include "util/basic_macros.h"
#include <ostream>
#include <map>
#include <set>
@@ -38,7 +39,62 @@ struct HTTPFetchResult;
bool clientMediaUpdateCache(const std::string &raw_hash,
const std::string &filedata);
-class ClientMediaDownloader
+// more of a base class than an interface but this name was most convenient...
+class IClientMediaDownloader
+{
+public:
+ DISABLE_CLASS_COPY(IClientMediaDownloader)
+
+ virtual bool isStarted() const = 0;
+
+ // If this returns true, the downloader is done and can be deleted
+ virtual bool isDone() const = 0;
+
+ // Add a file to the list of required file (but don't fetch it yet)
+ virtual void addFile(const std::string &name, const std::string &sha1) = 0;
+
+ // Add a remote server to the list; ignored if not built with cURL
+ virtual void addRemoteServer(const std::string &baseurl) = 0;
+
+ // Steps the media downloader:
+ // - May load media into client by calling client->loadMedia()
+ // - May check media cache for files
+ // - May add files to media cache
+ // - May start remote transfers by calling httpfetch_async
+ // - May check for completion of current remote transfers
+ // - May start conventional transfers by calling client->request_media()
+ // - May inform server that all media has been loaded
+ // by calling client->received_media()
+ // After step has been called once, don't call addFile/addRemoteServer.
+ virtual void step(Client *client) = 0;
+
+ // Must be called for each file received through TOCLIENT_MEDIA
+ // returns true if this file belongs to this downloader
+ virtual bool conventionalTransferDone(const std::string &name,
+ const std::string &data, Client *client) = 0;
+
+protected:
+ IClientMediaDownloader();
+ virtual ~IClientMediaDownloader() = default;
+
+ // Forwards the call to the appropriate Client method
+ virtual bool loadMedia(Client *client, const std::string &data,
+ const std::string &name) = 0;
+
+ void createCacheDirs();
+
+ bool tryLoadFromCache(const std::string &name, const std::string &sha1,
+ Client *client);
+
+ bool checkAndLoad(const std::string &name, const std::string &sha1,
+ const std::string &data, bool is_from_cache, Client *client);
+
+ // Filesystem-based media cache
+ FileCache m_media_cache;
+ bool m_write_to_cache;
+};
+
+class ClientMediaDownloader : public IClientMediaDownloader
{
public:
ClientMediaDownloader();
@@ -52,39 +108,29 @@ public:
return 0.0f;
}
- bool isStarted() const {
+ bool isStarted() const override {
return m_initial_step_done;
}
- // If this returns true, the downloader is done and can be deleted
- bool isDone() const {
+ bool isDone() const override {
return m_initial_step_done &&
m_uncached_received_count == m_uncached_count;
}
- // Add a file to the list of required file (but don't fetch it yet)
- void addFile(const std::string &name, const std::string &sha1);
+ void addFile(const std::string &name, const std::string &sha1) override;
- // Add a remote server to the list; ignored if not built with cURL
- void addRemoteServer(const std::string &baseurl);
+ void addRemoteServer(const std::string &baseurl) override;
- // Steps the media downloader:
- // - May load media into client by calling client->loadMedia()
- // - May check media cache for files
- // - May add files to media cache
- // - May start remote transfers by calling httpfetch_async
- // - May check for completion of current remote transfers
- // - May start conventional transfers by calling client->request_media()
- // - May inform server that all media has been loaded
- // by calling client->received_media()
- // After step has been called once, don't call addFile/addRemoteServer.
- void step(Client *client);
+ void step(Client *client) override;
- // Must be called for each file received through TOCLIENT_MEDIA
- void conventionalTransferDone(
+ bool conventionalTransferDone(
const std::string &name,
const std::string &data,
- Client *client);
+ Client *client) override;
+
+protected:
+ bool loadMedia(Client *client, const std::string &data,
+ const std::string &name) override;
private:
struct FileStatus {
@@ -107,13 +153,9 @@ private:
void startRemoteMediaTransfers();
void startConventionalTransfers(Client *client);
- bool checkAndLoad(const std::string &name, const std::string &sha1,
- const std::string &data, bool is_from_cache,
- Client *client);
-
- std::string serializeRequiredHashSet();
static void deSerializeHashSet(const std::string &data,
std::set<std::string> &result);
+ std::string serializeRequiredHashSet();
// Maps filename to file status
std::map<std::string, FileStatus*> m_files;
@@ -121,9 +163,6 @@ private:
// Array of remote media servers
std::vector<RemoteServerStatus*> m_remotes;
- // Filesystem-based media cache
- FileCache m_media_cache;
-
// Has an attempt been made to load media files from the file cache?
// Have hash sets been requested from remote servers?
bool m_initial_step_done = false;
@@ -149,3 +188,63 @@ private:
std::string m_name_bound = "";
};
+
+// A media downloader that only downloads a single file.
+// It does/doesn't do several things the normal downloader does:
+// - won't fetch hash sets from remote servers
+// - will mark loaded media as coming from file push
+// - writing to file cache is optional
+class SingleMediaDownloader : public IClientMediaDownloader
+{
+public:
+ SingleMediaDownloader(bool write_to_cache);
+ ~SingleMediaDownloader();
+
+ bool isStarted() const override {
+ return m_stage > STAGE_INIT;
+ }
+
+ bool isDone() const override {
+ return m_stage >= STAGE_DONE;
+ }
+
+ void addFile(const std::string &name, const std::string &sha1) override;
+
+ void addRemoteServer(const std::string &baseurl) override;
+
+ void step(Client *client) override;
+
+ bool conventionalTransferDone(const std::string &name,
+ const std::string &data, Client *client) override;
+
+protected:
+ bool loadMedia(Client *client, const std::string &data,
+ const std::string &name) override;
+
+private:
+ void initialStep(Client *client);
+ void remoteMediaReceived(const HTTPFetchResult &fetch_result, Client *client);
+ void startRemoteMediaTransfer();
+ void startConventionalTransfer(Client *client);
+
+ enum Stage {
+ STAGE_INIT,
+ STAGE_CACHE_CHECKED, // we have tried to load the file from cache
+ STAGE_DONE
+ };
+
+ // Information about the one file we want to fetch
+ std::string m_file_name;
+ std::string m_file_sha1;
+ s32 m_current_remote;
+
+ // Array of remote media servers
+ std::vector<std::string> m_remotes;
+
+ enum Stage m_stage = STAGE_INIT;
+
+ // Status of remote transfers
+ unsigned long m_httpfetch_caller;
+ unsigned long m_httpfetch_next_id = 0;
+
+};
diff --git a/src/client/clouds.cpp b/src/client/clouds.cpp
index 5008047af..383a1d799 100644
--- a/src/client/clouds.cpp
+++ b/src/client/clouds.cpp
@@ -352,7 +352,7 @@ void Clouds::update(const v3f &camera_p, const video::SColorf &color_diffuse)
// is the camera inside the cloud mesh?
m_camera_inside_cloud = false; // default
if (m_enable_3d) {
- float camera_height = camera_p.Y;
+ float camera_height = camera_p.Y - BS * m_camera_offset.Y;
if (camera_height >= m_box.MinEdge.Y &&
camera_height <= m_box.MaxEdge.Y) {
v2f camera_in_noise;
diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp
index 3a6ca3e29..5d8a597a2 100644
--- a/src/client/content_cao.cpp
+++ b/src/client/content_cao.cpp
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <IMeshManipulator.h>
#include <IAnimatedMeshSceneNode.h>
#include "client/client.h"
+#include "client/renderingengine.h"
#include "client/sound.h"
#include "client/tile.h"
#include "util/basic_macros.h"
@@ -346,18 +347,6 @@ void GenericCAO::initialize(const std::string &data)
infostream<<"GenericCAO: Got init data"<<std::endl;
processInitData(data);
- if (m_is_player) {
- // Check if it's the current player
- LocalPlayer *player = m_env->getLocalPlayer();
- if (player && strcmp(player->getName(), m_name.c_str()) == 0) {
- m_is_local_player = true;
- m_is_visible = false;
- player->setCAO(this);
-
- m_prop.show_on_minimap = false;
- }
- }
-
m_enable_shaders = g_settings->getBool("enable_shaders");
}
@@ -380,6 +369,16 @@ void GenericCAO::processInitData(const std::string &data)
m_rotation = readV3F32(is);
m_hp = readU16(is);
+ if (m_is_player) {
+ // Check if it's the current player
+ LocalPlayer *player = m_env->getLocalPlayer();
+ if (player && strcmp(player->getName(), m_name.c_str()) == 0) {
+ m_is_local_player = true;
+ m_is_visible = false;
+ player->setCAO(this);
+ }
+ }
+
const u8 num_messages = readU8(is);
for (int i = 0; i < num_messages; i++) {
@@ -560,6 +559,9 @@ void GenericCAO::removeFromScene(bool permanent)
clearParentAttachment();
}
+ if (auto shadow = RenderingEngine::get_shadow_renderer())
+ shadow->removeNodeFromShadowList(getSceneNode());
+
if (m_meshnode) {
m_meshnode->remove();
m_meshnode->drop();
@@ -808,10 +810,13 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
if (m_reset_textures_timer < 0)
updateTextures(m_current_texture_modifier);
- scene::ISceneNode *node = getSceneNode();
+ if (scene::ISceneNode *node = getSceneNode()) {
+ if (m_matrixnode)
+ node->setParent(m_matrixnode);
- if (node && m_matrixnode)
- node->setParent(m_matrixnode);
+ if (auto shadow = RenderingEngine::get_shadow_renderer())
+ shadow->addNodeToShadowList(node);
+ }
updateNametag();
updateMarker();
@@ -1011,9 +1016,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
const PlayerControl &controls = player->getPlayerControl();
bool walking = false;
- if ((controls.up || controls.down || controls.left || controls.right ||
- controls.forw_move_joystick_axis != 0.f ||
- controls.sidew_move_joystick_axis != 0.f) && ! g_settings->getBool("freecam"))
+ if (controls.movement_speed > 0.001f && ! g_settings->getBool("freecam"))
walking = true;
f32 new_speed = player->local_animation_speed;
@@ -1028,9 +1031,10 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
g_settings->getBool("free_move") &&
m_client->checkLocalPrivilege("fly")))) || g_settings->getBool("freecam"))
new_speed *= 1.5;
- // slowdown speed if sneeking
+ // slowdown speed if sneaking
if (controls.sneak && walking && ! g_settings->getBool("no_slow"))
new_speed /= 2;
+ new_speed *= controls.movement_speed;
if (walking && (controls.dig || controls.place)) {
new_anim = player->local_animations[3];
@@ -1744,6 +1748,7 @@ void GenericCAO::processMessage(const std::string &data)
m_tx_basepos = p;
m_anim_num_frames = num_frames;
+ m_anim_frame = 0;
m_anim_framelength = framelength;
m_tx_select_horiz_by_yawpitch = select_horiz_by_yawpitch;
diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp
index 810c57138..bb2d6398f 100644
--- a/src/client/content_mapblock.cpp
+++ b/src/client/content_mapblock.cpp
@@ -958,10 +958,38 @@ void MapblockMeshGenerator::drawPlantlikeQuad(float rotation, float quad_offset,
vertex.rotateXZBy(rotation + rotate_degree);
vertex += offset;
}
+
+ u8 wall = n.getWallMounted(nodedef);
+ if (wall != DWM_YN) {
+ for (v3f &vertex : vertices) {
+ switch (wall) {
+ case DWM_YP:
+ vertex.rotateYZBy(180);
+ vertex.rotateXZBy(180);
+ break;
+ case DWM_XP:
+ vertex.rotateXYBy(90);
+ break;
+ case DWM_XN:
+ vertex.rotateXYBy(-90);
+ vertex.rotateYZBy(180);
+ break;
+ case DWM_ZP:
+ vertex.rotateYZBy(-90);
+ vertex.rotateXYBy(90);
+ break;
+ case DWM_ZN:
+ vertex.rotateYZBy(90);
+ vertex.rotateXYBy(90);
+ break;
+ }
+ }
+ }
+
drawQuad(vertices, v3s16(0, 0, 0), plant_height);
}
-void MapblockMeshGenerator::drawPlantlike()
+void MapblockMeshGenerator::drawPlantlike(bool is_rooted)
{
draw_style = PLANT_STYLE_CROSS;
scale = BS / 2 * f->visual_scale;
@@ -998,6 +1026,22 @@ void MapblockMeshGenerator::drawPlantlike()
break;
}
+ if (is_rooted) {
+ u8 wall = n.getWallMounted(nodedef);
+ switch (wall) {
+ case DWM_YP:
+ offset.Y += BS*2;
+ break;
+ case DWM_XN:
+ case DWM_XP:
+ case DWM_ZN:
+ case DWM_ZP:
+ offset.X += -BS;
+ offset.Y += BS;
+ break;
+ }
+ }
+
switch (draw_style) {
case PLANT_STYLE_CROSS:
drawPlantlikeQuad(46);
@@ -1048,7 +1092,7 @@ void MapblockMeshGenerator::drawPlantlikeRootedNode()
MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
light = LightPair(getInteriorLight(ntop, 1, nodedef));
}
- drawPlantlike();
+ drawPlantlike(true);
p.Y--;
}
diff --git a/src/client/content_mapblock.h b/src/client/content_mapblock.h
index 237cc7847..7344f05ee 100644
--- a/src/client/content_mapblock.h
+++ b/src/client/content_mapblock.h
@@ -146,7 +146,7 @@ public:
void drawPlantlikeQuad(float rotation, float quad_offset = 0,
bool offset_top_only = false);
- void drawPlantlike();
+ void drawPlantlike(bool is_rooted = false);
// firelike-specific
void drawFirelikeQuad(float rotation, float opening_angle,
diff --git a/src/client/fontengine.cpp b/src/client/fontengine.cpp
index 0382c2f18..f64315db4 100644
--- a/src/client/fontengine.cpp
+++ b/src/client/fontengine.cpp
@@ -342,8 +342,9 @@ gui::IGUIFont *FontEngine::initSimpleFont(const FontSpec &spec)
(spec.mode == FM_SimpleMono) ? "mono_font_path" : "font_path");
size_t pos_dot = font_path.find_last_of('.');
- std::string basename = font_path;
- std::string ending = lowercase(font_path.substr(pos_dot));
+ std::string basename = font_path, ending;
+ if (pos_dot != std::string::npos)
+ ending = lowercase(font_path.substr(pos_dot));
if (ending == ".ttf") {
errorstream << "FontEngine: Found font \"" << font_path
diff --git a/src/client/game.cpp b/src/client/game.cpp
index 5bfe55e66..d2a751040 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -300,6 +300,7 @@ void Game::run()
m_game_ui->clearInfoText();
hud->resizeHotbar();
+
updateProfilers(stats, draw_times, dtime);
processUserInput(dtime);
// Update camera before player movement to avoid camera lag of one frame
@@ -311,10 +312,11 @@ void Game::run()
updatePlayerControl(cam_view);
step(&dtime);
processClientEvents(&cam_view_target);
+ updateDebugState();
updateCamera(draw_times.busy_time, dtime);
updateSound(dtime);
processPlayerInteraction(dtime, m_game_ui->m_flags.show_hud,
- m_game_ui->m_flags.show_debug);
+ m_game_ui->m_flags.show_basic_debug);
updateFrame(&graph, &stats, dtime, cam_view);
updateProfilerGraphs(&graph);
@@ -823,7 +825,7 @@ bool Game::getServerContent(bool *aborted)
dtime, progress);
delete[] text;
} else {
- std::stringstream message;
+ std::ostringstream message;
std::fixed(message);
message.precision(0);
float receive = client->mediaReceiveProgress() * 100;
@@ -932,6 +934,25 @@ void Game::processQueues()
shader_src->processQueue();
}
+void Game::updateDebugState()
+{
+ bool has_basic_debug = client->checkPrivilege("basic_debug");
+ bool has_debug = client->checkPrivilege("debug");
+
+ if (m_game_ui->m_flags.show_basic_debug) {
+ if (!has_basic_debug) {
+ m_game_ui->m_flags.show_basic_debug = false;
+ }
+ } else if (m_game_ui->m_flags.show_minimal_debug) {
+ if (has_basic_debug) {
+ m_game_ui->m_flags.show_basic_debug = true;
+ }
+ }
+ if (!has_basic_debug)
+ hud->disableBlockBounds();
+ if (!has_debug)
+ draw_control->show_wireframe = false;
+}
void Game::updateProfilers(const RunStats &stats, const FpsControl &draw_times,
f32 dtime)
@@ -1133,24 +1154,18 @@ void Game::processKeyInput()
} else if (wasKeyDown(KeyType::INC_VOLUME)) {
if (g_settings->getBool("enable_sound")) {
float new_volume = rangelim(g_settings->getFloat("sound_volume") + 0.1f, 0.0f, 1.0f);
- wchar_t buf[100];
g_settings->setFloat("sound_volume", new_volume);
- const wchar_t *str = wgettext("Volume changed to %d%%");
- swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, myround(new_volume * 100));
- delete[] str;
- m_game_ui->showStatusText(buf);
+ std::wstring msg = fwgettext("Volume changed to %d%%", myround(new_volume * 100));
+ m_game_ui->showStatusText(msg);
} else {
m_game_ui->showTranslatedStatusText("Sound system is disabled");
}
} else if (wasKeyDown(KeyType::DEC_VOLUME)) {
if (g_settings->getBool("enable_sound")) {
float new_volume = rangelim(g_settings->getFloat("sound_volume") - 0.1f, 0.0f, 1.0f);
- wchar_t buf[100];
g_settings->setFloat("sound_volume", new_volume);
- const wchar_t *str = wgettext("Volume changed to %d%%");
- swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, myround(new_volume * 100));
- delete[] str;
- m_game_ui->showStatusText(buf);
+ std::wstring msg = fwgettext("Volume changed to %d%%", myround(new_volume * 100));
+ m_game_ui->showStatusText(msg);
} else {
m_game_ui->showTranslatedStatusText("Sound system is disabled");
}
@@ -1164,7 +1179,7 @@ void Game::processKeyInput()
} else if (wasKeyDown(KeyType::SCREENSHOT)) {
client->makeScreenshot();
} else if (wasKeyDown(KeyType::TOGGLE_BLOCK_BOUNDS)) {
- hud->toggleBlockBounds();
+ toggleBlockBounds();
} else if (wasKeyDown(KeyType::TOGGLE_HUD)) {
m_game_ui->toggleHud();
} else if (wasKeyDown(KeyType::MINIMAP)) {
@@ -1452,6 +1467,32 @@ void Game::toggleCinematic()
m_game_ui->showTranslatedStatusText("Cinematic mode disabled");
}
+void Game::toggleBlockBounds()
+{
+ if (client->checkPrivilege("basic_debug")) {
+ enum Hud::BlockBoundsMode newmode = hud->toggleBlockBounds();
+ switch (newmode) {
+ case Hud::BLOCK_BOUNDS_OFF:
+ m_game_ui->showTranslatedStatusText("Block bounds hidden");
+ break;
+ case Hud::BLOCK_BOUNDS_CURRENT:
+ m_game_ui->showTranslatedStatusText("Block bounds shown for current block");
+ break;
+ case Hud::BLOCK_BOUNDS_NEAR:
+ m_game_ui->showTranslatedStatusText("Block bounds shown for nearby blocks");
+ break;
+ case Hud::BLOCK_BOUNDS_MAX:
+ m_game_ui->showTranslatedStatusText("Block bounds shown for all blocks");
+ break;
+ default:
+ break;
+ }
+
+ } else {
+ m_game_ui->showTranslatedStatusText("Can't show block bounds (need 'basic_debug' privilege)");
+ }
+}
+
// Autoforward by toggling continuous forward.
void Game::toggleAutoforward()
{
@@ -1515,24 +1556,41 @@ void Game::toggleFog()
void Game::toggleDebug()
{
- // Initial / 4x toggle: Chat only
- // 1x toggle: Debug text with chat
+ // Initial: No debug info
+ // 1x toggle: Debug text
// 2x toggle: Debug text with profiler graph
- // 3x toggle: Debug text and wireframe
- if (!m_game_ui->m_flags.show_debug) {
- m_game_ui->m_flags.show_debug = true;
+ // 3x toggle: Debug text and wireframe (needs "debug" priv)
+ // Next toggle: Back to initial
+ //
+ // The debug text can be in 2 modes: minimal and basic.
+ // * Minimal: Only technical client info that not gameplay-relevant
+ // * Basic: Info that might give gameplay advantage, e.g. pos, angle
+ // Basic mode is used when player has "basic_debug" priv,
+ // otherwise the Minimal mode is used.
+ if (!m_game_ui->m_flags.show_minimal_debug) {
+ m_game_ui->m_flags.show_minimal_debug = true;
+ if (client->checkPrivilege("basic_debug")) {
+ m_game_ui->m_flags.show_basic_debug = true;
+ }
m_game_ui->m_flags.show_profiler_graph = false;
draw_control->show_wireframe = false;
m_game_ui->showTranslatedStatusText("Debug info shown");
} else if (!m_game_ui->m_flags.show_profiler_graph && !draw_control->show_wireframe) {
+ if (client->checkPrivilege("basic_debug")) {
+ m_game_ui->m_flags.show_basic_debug = true;
+ }
m_game_ui->m_flags.show_profiler_graph = true;
m_game_ui->showTranslatedStatusText("Profiler graph shown");
} else if (!draw_control->show_wireframe && client->checkPrivilege("debug")) {
+ if (client->checkPrivilege("basic_debug")) {
+ m_game_ui->m_flags.show_basic_debug = true;
+ }
m_game_ui->m_flags.show_profiler_graph = false;
draw_control->show_wireframe = true;
m_game_ui->showTranslatedStatusText("Wireframe shown");
} else {
- m_game_ui->m_flags.show_debug = false;
+ m_game_ui->m_flags.show_minimal_debug = false;
+ m_game_ui->m_flags.show_basic_debug = false;
m_game_ui->m_flags.show_profiler_graph = false;
draw_control->show_wireframe = false;
if (client->checkPrivilege("debug")) {
@@ -1561,20 +1619,13 @@ void Game::increaseViewRange()
s16 range = g_settings->getS16("viewing_range");
s16 range_new = range + 10;
- wchar_t buf[255];
- const wchar_t *str;
if (range_new > 4000) {
range_new = 4000;
- str = wgettext("Viewing range is at maximum: %d");
- swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, range_new);
- delete[] str;
- m_game_ui->showStatusText(buf);
-
+ std::wstring msg = fwgettext("Viewing range is at maximum: %d", range_new);
+ m_game_ui->showStatusText(msg);
} else {
- str = wgettext("Viewing range changed to %d");
- swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, range_new);
- delete[] str;
- m_game_ui->showStatusText(buf);
+ std::wstring msg = fwgettext("Viewing range changed to %d", range_new);
+ m_game_ui->showStatusText(msg);
}
g_settings->set("viewing_range", itos(range_new));
}
@@ -1585,19 +1636,13 @@ void Game::decreaseViewRange()
s16 range = g_settings->getS16("viewing_range");
s16 range_new = range - 10;
- wchar_t buf[255];
- const wchar_t *str;
if (range_new < 20) {
range_new = 20;
- str = wgettext("Viewing range is at minimum: %d");
- swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, range_new);
- delete[] str;
- m_game_ui->showStatusText(buf);
+ std::wstring msg = fwgettext("Viewing range is at minimum: %d", range_new);
+ m_game_ui->showStatusText(msg);
} else {
- str = wgettext("Viewing range changed to %d");
- swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, range_new);
- delete[] str;
- m_game_ui->showStatusText(buf);
+ std::wstring msg = fwgettext("Viewing range changed to %d", range_new);
+ m_game_ui->showStatusText(msg);
}
g_settings->set("viewing_range", itos(range_new));
}
@@ -1694,7 +1739,7 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
if (m_cache_enable_joysticks) {
f32 sens_scale = getSensitivityScaleFactor();
- f32 c = m_cache_joystick_frustum_sensitivity * (1.f / 32767.f) * dtime * sens_scale;
+ f32 c = m_cache_joystick_frustum_sensitivity * dtime * sens_scale;
cam->camera_yaw -= input->joystick.getAxisWithoutDead(JA_FRUSTUM_HORIZONTAL) * c;
cam->camera_pitch += input->joystick.getAxisWithoutDead(JA_FRUSTUM_VERTICAL) * c;
}
@@ -1705,18 +1750,12 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
void Game::updatePlayerControl(const CameraOrientation &cam)
{
- //TimeTaker tt("update player control", NULL, PRECISION_NANO);
+ LocalPlayer *player = client->getEnv().getLocalPlayer();
- // DO NOT use the isKeyDown method for the forward, backward, left, right
- // buttons, as the code that uses the controls needs to be able to
- // distinguish between the two in order to know when to use joysticks.
+ //TimeTaker tt("update player control", NULL, PRECISION_NANO);
PlayerControl control(
- input->isKeyDown(KeyType::FORWARD),
- input->isKeyDown(KeyType::BACKWARD),
- input->isKeyDown(KeyType::LEFT),
- input->isKeyDown(KeyType::RIGHT),
- isKeyDown(KeyType::JUMP),
+ isKeyDown(KeyType::JUMP) || player->getAutojump(),
isKeyDown(KeyType::AUX1),
isKeyDown(KeyType::SNEAK),
isKeyDown(KeyType::ZOOM),
@@ -1724,22 +1763,16 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
isKeyDown(KeyType::PLACE),
cam.camera_pitch,
cam.camera_yaw,
- input->joystick.getAxisWithoutDead(JA_SIDEWARD_MOVE),
- input->joystick.getAxisWithoutDead(JA_FORWARD_MOVE)
+ input->getMovementSpeed(),
+ input->getMovementDirection()
);
- u32 keypress_bits = (
- ( (u32)(isKeyDown(KeyType::FORWARD) & 0x1) << 0) |
- ( (u32)(isKeyDown(KeyType::BACKWARD) & 0x1) << 1) |
- ( (u32)(isKeyDown(KeyType::LEFT) & 0x1) << 2) |
- ( (u32)(isKeyDown(KeyType::RIGHT) & 0x1) << 3) |
- ( (u32)(isKeyDown(KeyType::JUMP) & 0x1) << 4) |
- ( (u32)(isKeyDown(KeyType::AUX1) & 0x1) << 5) |
- ( (u32)(isKeyDown(KeyType::SNEAK) & 0x1) << 6) |
- ( (u32)(isKeyDown(KeyType::DIG) & 0x1) << 7) |
- ( (u32)(isKeyDown(KeyType::PLACE) & 0x1) << 8) |
- ( (u32)(isKeyDown(KeyType::ZOOM) & 0x1) << 9)
- );
+ // autoforward if set: move towards pointed position at maximum speed
+ if (player->getPlayerSettings().continuous_forward &&
+ client->activeObjectsReceived() && !player->isDead()) {
+ control.movement_speed = 1.0f;
+ control.movement_direction = 0.0f;
+ }
#ifdef ANDROID
/* For Android, simulate holding down AUX1 (fast move) if the user has
@@ -1749,23 +1782,38 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
*/
if (m_cache_hold_aux1) {
control.aux1 = control.aux1 ^ true;
- keypress_bits ^= ((u32)(1U << 5));
}
#endif
- LocalPlayer *player = client->getEnv().getLocalPlayer();
+ u32 keypress_bits = (
+ ( (u32)(control.jump & 0x1) << 4) |
+ ( (u32)(control.aux1 & 0x1) << 5) |
+ ( (u32)(control.sneak & 0x1) << 6) |
+ ( (u32)(control.dig & 0x1) << 7) |
+ ( (u32)(control.place & 0x1) << 8) |
+ ( (u32)(control.zoom & 0x1) << 9)
+ );
- // autojump if set: simulate "jump" key
- if (player->getAutojump()) {
- control.jump = true;
- keypress_bits |= 1U << 4;
- }
+ // Set direction keys to ensure mod compatibility
+ if (control.movement_speed > 0.001f) {
+ float absolute_direction;
- // autoforward if set: simulate "up" key
- if (player->getPlayerSettings().continuous_forward &&
- client->activeObjectsReceived() && !player->isDead()) {
- control.up = true;
- keypress_bits |= 1U << 0;
+ // Check in original orientation (absolute value indicates forward / backward)
+ absolute_direction = abs(control.movement_direction);
+ if (absolute_direction < (3.0f / 8.0f * M_PI))
+ keypress_bits |= (u32)(0x1 << 0); // Forward
+ if (absolute_direction > (5.0f / 8.0f * M_PI))
+ keypress_bits |= (u32)(0x1 << 1); // Backward
+
+ // Rotate entire coordinate system by 90 degrees (absolute value indicates left / right)
+ absolute_direction = control.movement_direction + M_PI_2;
+ if (absolute_direction >= M_PI)
+ absolute_direction -= 2 * M_PI;
+ absolute_direction = abs(absolute_direction);
+ if (absolute_direction < (3.0f / 8.0f * M_PI))
+ keypress_bits |= (u32)(0x1 << 2); // Left
+ if (absolute_direction > (5.0f / 8.0f * M_PI))
+ keypress_bits |= (u32)(0x1 << 3); // Right
}
client->setPlayerControl(control);
@@ -1970,6 +2018,7 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam)
e->size = event->hudadd->size;
e->z_index = event->hudadd->z_index;
e->text2 = event->hudadd->text2;
+ e->style = event->hudadd->style;
m_hud_server_to_client[server_id] = player->addHud(e);
delete event->hudadd;
@@ -2035,6 +2084,8 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca
CASE_SET(HUD_STAT_Z_INDEX, z_index, data);
CASE_SET(HUD_STAT_TEXT2, text2, sdata);
+
+ CASE_SET(HUD_STAT_STYLE, style, data);
}
#undef CASE_SET
@@ -3131,15 +3182,22 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
*/
runData.update_draw_list_timer += dtime;
+ float update_draw_list_delta = 0.2f;
+
v3f camera_direction = camera->getDirection();
- if (runData.update_draw_list_timer >= 0.2
+ if (runData.update_draw_list_timer >= update_draw_list_delta
|| runData.update_draw_list_last_cam_dir.getDistanceFrom(camera_direction) > 0.2
|| m_camera_offset_changed) {
+
runData.update_draw_list_timer = 0;
client->getEnv().getClientMap().updateDrawList();
runData.update_draw_list_last_cam_dir = camera_direction;
}
+ if (RenderingEngine::get_shadow_renderer()) {
+ updateShadows();
+ }
+
m_game_ui->update(*stats, client, draw_control, cam, runData.pointed_old, gui_chat_console, dtime);
/*
@@ -3205,7 +3263,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
if (! gui_chat_console->isOpen()) {
if (m_game_ui->m_flags.show_cheat_menu)
- m_cheat_menu->draw(driver, m_game_ui->m_flags.show_debug);
+ m_cheat_menu->draw(driver, m_game_ui->m_flags.show_minimal_debug);
if (g_settings->getBool("cheat_hud"))
m_cheat_menu->drawHUD(driver, dtime);
}
@@ -3277,7 +3335,34 @@ inline void Game::updateProfilerGraphs(ProfilerGraph *graph)
graph->put(values);
}
+/****************************************************************************
+ * Shadows
+ *****************************************************************************/
+void Game::updateShadows()
+{
+ ShadowRenderer *shadow = RenderingEngine::get_shadow_renderer();
+ if (!shadow)
+ return;
+ float in_timeofday = fmod(runData.time_of_day_smooth, 1.0f);
+
+ float timeoftheday = fmod(getWickedTimeOfDay(in_timeofday) + 0.75f, 0.5f) + 0.25f;
+ const float offset_constant = 10000.0f;
+
+ v3f light(0.0f, 0.0f, -1.0f);
+ light.rotateXZBy(90);
+ light.rotateXYBy(timeoftheday * 360 - 90);
+ light.rotateYZBy(sky->getSkyBodyOrbitTilt());
+
+ v3f sun_pos = light * offset_constant;
+
+ if (shadow->getDirectionalLightCount() == 0)
+ shadow->addDirectionalLight();
+ shadow->getDirectionalLight().setDirection(sun_pos);
+ shadow->setTimeOfDay(in_timeofday);
+
+ shadow->getDirectionalLight().update_frustum(camera, client, m_camera_offset_changed);
+}
/****************************************************************************
Misc
diff --git a/src/client/game.h b/src/client/game.h
index 8197b9a9b..cb40d4890 100644
--- a/src/client/game.h
+++ b/src/client/game.h
@@ -684,6 +684,7 @@ public:
bool handleCallbacks();
void processQueues();
void updateProfilers(const RunStats &stats, const FpsControl &draw_times, f32 dtime);
+ void updateDebugState();
void updateStats(RunStats *stats, const FpsControl &draw_times, f32 dtime);
void updateProfilerGraphs(ProfilerGraph *graph);
@@ -706,6 +707,7 @@ public:
void toggleScaffold();
void toggleNextItem();
void toggleCinematic();
+ void toggleBlockBounds();
void toggleAutoforward();
void toggleMinimap(bool shift_pressed);
@@ -752,6 +754,7 @@ public:
const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime);
void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
const CameraOrientation &cam);
+ void updateShadows();
// Misc
void limitFps(FpsControl *fps_timings, f32 *dtime);
diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp
index c97ae93b8..66a006ea1 100644
--- a/src/client/gameui.cpp
+++ b/src/client/gameui.cpp
@@ -74,11 +74,14 @@ void GameUI::init()
chat_font_size, FM_Unspecified));
}
- // At the middle of the screen
- // Object infos are shown in this
+
+ // Infotext of nodes and objects.
+ // If in debug mode, object debug infos shown here, too.
+ // Located on the left on the screen, below chat.
u32 chat_font_height = m_guitext_chat->getActiveFont()->getDimension(L"Ay").Height;
m_guitext_info = gui::StaticText::add(guienv, L"",
- core::rect<s32>(0, 0, 400, g_fontengine->getTextHeight() * 5 + 5) +
+ // Size is limited; text will be truncated after 6 lines.
+ core::rect<s32>(0, 0, 400, g_fontengine->getTextHeight() * 6) +
v2s32(100, chat_font_height *
(g_settings->getU16("recent_chat_messages") + 3)),
false, true, guiroot);
@@ -119,7 +122,8 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
m_guitext_coords->setVisible(show_coords);
- if (m_flags.show_debug) {
+ // Minimal debug text must only contain info that can't give a gameplay advantage
+ if (m_flags.show_minimal_debug) {
static float drawtime_avg = 0;
drawtime_avg = drawtime_avg * 0.95 + stats.drawtime * 0.05;
u16 fps = 1.0 / stats.dtime_jitter.avg;
@@ -145,9 +149,13 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
}
// Finally set the guitext visible depending on the flag
- m_guitext->setVisible(m_flags.show_debug);
+ m_guitext->setVisible(m_flags.show_minimal_debug);
+
+ // Basic debug text also shows info that might give a gameplay advantage
+ if (m_flags.show_basic_debug) {
+ LocalPlayer *player = client->getEnv().getLocalPlayer();
+ v3f player_position = player->getPosition();
- if (m_flags.show_debug) {
std::ostringstream os(std::ios_base::binary);
os << std::setprecision(1) << std::fixed
<< "pos: (" << (player_position.X / BS)
@@ -177,7 +185,7 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
));
}
- m_guitext2->setVisible(m_flags.show_debug);
+ m_guitext2->setVisible(m_flags.show_basic_debug);
setStaticText(m_guitext_info, m_infotext.c_str());
m_guitext_info->setVisible(m_flags.show_hud && g_menumgr.menuCount() == 0);
@@ -220,7 +228,8 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
void GameUI::initFlags()
{
m_flags = GameUI::Flags();
- m_flags.show_debug = g_settings->getBool("show_debug");
+ m_flags.show_minimal_debug = g_settings->getBool("show_debug");
+ m_flags.show_basic_debug = false;
}
void GameUI::showMinimap(bool show)
@@ -244,8 +253,10 @@ void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count)
s32 chat_y = window_size.Y - 150 - m_guitext_chat->getTextHeight();
- if (m_flags.show_debug)
- chat_y += 2 * g_fontengine->getLineHeight();
+ if (m_flags.show_minimal_debug)
+ chat_y += g_fontengine->getLineHeight();
+ if (m_flags.show_basic_debug)
+ chat_y += g_fontengine->getLineHeight();
core::rect<s32> chat_size(10, chat_y,
window_size.X - 20, 0);
@@ -320,12 +331,9 @@ void GameUI::toggleProfiler()
updateProfiler();
if (m_profiler_current_page != 0) {
- wchar_t buf[255];
- const wchar_t* str = wgettext("Profiler shown (page %d of %d)");
- swprintf(buf, sizeof(buf) / sizeof(wchar_t), str,
- m_profiler_current_page, m_profiler_max_page);
- delete[] str;
- showStatusText(buf);
+ std::wstring msg = fwgettext("Profiler shown (page %d of %d)",
+ m_profiler_current_page, m_profiler_max_page);
+ showStatusText(msg);
} else {
showTranslatedStatusText("Profiler hidden");
}
diff --git a/src/client/gameui.h b/src/client/gameui.h
index f04fd97b8..5404643e2 100644
--- a/src/client/gameui.h
+++ b/src/client/gameui.h
@@ -58,7 +58,8 @@ public:
bool show_chat = true;
bool show_hud = true;
bool show_minimap = false;
- bool show_debug = true;
+ bool show_minimal_debug = false;
+ bool show_basic_debug = false;
bool show_profiler_graph = false;
bool show_cheat_menu = true;
};
diff --git a/src/client/hud.cpp b/src/client/hud.cpp
index 391af0995..3f687b698 100644
--- a/src/client/hud.cpp
+++ b/src/client/hud.cpp
@@ -331,8 +331,8 @@ bool Hud::calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *p
void Hud::drawLuaElements(const v3s16 &camera_offset)
{
- u32 text_height = g_fontengine->getTextHeight();
- irr::gui::IGUIFont* font = g_fontengine->getFont();
+ const u32 text_height = g_fontengine->getTextHeight();
+ gui::IGUIFont *const font = g_fontengine->getFont();
// Reorder elements by z_index
std::vector<HudElement*> elems;
@@ -356,38 +356,34 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
floor(e->pos.Y * (float) m_screensize.Y + 0.5));
switch (e->type) {
case HUD_ELEM_TEXT: {
- irr::gui::IGUIFont *textfont = font;
unsigned int font_size = g_fontengine->getDefaultFontSize();
if (e->size.X > 0)
font_size *= e->size.X;
- if (font_size != g_fontengine->getDefaultFontSize())
- textfont = g_fontengine->getFont(font_size);
+#ifdef __ANDROID__
+ // The text size on Android is not proportional with the actual scaling
+ // FIXME: why do we have such a weird unportable hack??
+ if (font_size > 3 && e->offset.X < -20)
+ font_size -= 3;
+#endif
+ auto textfont = g_fontengine->getFont(FontSpec(font_size,
+ (e->style & HUD_STYLE_MONO) ? FM_Mono : FM_Unspecified,
+ e->style & HUD_STYLE_BOLD, e->style & HUD_STYLE_ITALIC));
video::SColor color(255, (e->number >> 16) & 0xFF,
(e->number >> 8) & 0xFF,
(e->number >> 0) & 0xFF);
std::wstring text = unescape_translate(utf8_to_wide(e->text));
core::dimension2d<u32> textsize = textfont->getDimension(text.c_str());
-#ifdef __ANDROID__
- // The text size on Android is not proportional with the actual scaling
- irr::gui::IGUIFont *font_scaled = font_size <= 3 ?
- textfont : g_fontengine->getFont(font_size - 3);
- if (e->offset.X < -20)
- textsize = font_scaled->getDimension(text.c_str());
-#endif
+
v2s32 offset((e->align.X - 1.0) * (textsize.Width / 2),
(e->align.Y - 1.0) * (textsize.Height / 2));
core::rect<s32> size(0, 0, e->scale.X * m_scale_factor,
text_height * e->scale.Y * m_scale_factor);
v2s32 offs(e->offset.X * m_scale_factor,
e->offset.Y * m_scale_factor);
-#ifdef __ANDROID__
- if (e->offset.X < -20)
- font_scaled->draw(text.c_str(), size + pos + offset + offs, color);
- else
-#endif
+
{
textfont->draw(text.c_str(), size + pos + offset + offs, color);
}
@@ -861,13 +857,19 @@ void Hud::drawSelectionMesh()
}
}
-void Hud::toggleBlockBounds()
+enum Hud::BlockBoundsMode Hud::toggleBlockBounds()
{
m_block_bounds_mode = static_cast<BlockBoundsMode>(m_block_bounds_mode + 1);
if (m_block_bounds_mode >= BLOCK_BOUNDS_MAX) {
m_block_bounds_mode = BLOCK_BOUNDS_OFF;
}
+ return m_block_bounds_mode;
+}
+
+void Hud::disableBlockBounds()
+{
+ m_block_bounds_mode = BLOCK_BOUNDS_OFF;
}
void Hud::drawBlockBounds()
@@ -889,7 +891,7 @@ void Hud::drawBlockBounds()
v3f offset = intToFloat(client->getCamera()->getOffset(), BS);
- s8 radius = m_block_bounds_mode == BLOCK_BOUNDS_ALL ? 2 : 0;
+ s8 radius = m_block_bounds_mode == BLOCK_BOUNDS_NEAR ? 2 : 0;
v3f halfNode = v3f(BS, BS, BS) / 2.0f;
diff --git a/src/client/hud.h b/src/client/hud.h
index d341105d2..fd79183a0 100644
--- a/src/client/hud.h
+++ b/src/client/hud.h
@@ -35,6 +35,14 @@ struct ItemStack;
class Hud
{
public:
+ enum BlockBoundsMode
+ {
+ BLOCK_BOUNDS_OFF,
+ BLOCK_BOUNDS_CURRENT,
+ BLOCK_BOUNDS_NEAR,
+ BLOCK_BOUNDS_MAX
+ } m_block_bounds_mode = BLOCK_BOUNDS_OFF;
+
video::SColor crosshair_argb;
video::SColor selectionbox_argb;
@@ -51,7 +59,8 @@ public:
Inventory *inventory);
~Hud();
- void toggleBlockBounds();
+ enum BlockBoundsMode toggleBlockBounds();
+ void disableBlockBounds();
void drawBlockBounds();
void drawHotbar(u16 playeritem);
@@ -126,14 +135,6 @@ private:
scene::SMeshBuffer m_rotation_mesh_buffer;
- enum BlockBoundsMode
- {
- BLOCK_BOUNDS_OFF,
- BLOCK_BOUNDS_CURRENT,
- BLOCK_BOUNDS_ALL,
- BLOCK_BOUNDS_MAX
- } m_block_bounds_mode = BLOCK_BOUNDS_OFF;
-
enum
{
HIGHLIGHT_BOX,
diff --git a/src/client/imagefilters.cpp b/src/client/imagefilters.cpp
index 7b2ef9822..97ad094e5 100644
--- a/src/client/imagefilters.cpp
+++ b/src/client/imagefilters.cpp
@@ -95,9 +95,14 @@ void imageCleanTransparent(video::IImage *src, u32 threshold)
Bitmap newmap = bitmap;
+ // Cap iterations to keep runtime reasonable, for higher-res textures we can
+ // get away with filling less pixels.
+ int iter_max = 11 - std::max(dim.Width, dim.Height) / 16;
+ iter_max = std::max(iter_max, 2);
+
// Then repeatedly look for transparent pixels, filling them in until
- // we're finished (capped at 50 iterations).
- for (u32 iter = 0; iter < 50; iter++) {
+ // we're finished.
+ for (int iter = 0; iter < iter_max; iter++) {
for (u32 ctry = 0; ctry < dim.Height; ctry++)
for (u32 ctrx = 0; ctrx < dim.Width; ctrx++) {
diff --git a/src/client/inputhandler.cpp b/src/client/inputhandler.cpp
index d833db2f1..d2d81be9c 100644
--- a/src/client/inputhandler.cpp
+++ b/src/client/inputhandler.cpp
@@ -148,11 +148,8 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
#endif
} else if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
- /* TODO add a check like:
- if (event.JoystickEvent != joystick_we_listen_for)
- return false;
- */
- return joystick->handleEvent(event.JoystickEvent);
+ // joystick may be nullptr if game is launched with '--random-input' parameter
+ return joystick && joystick->handleEvent(event.JoystickEvent);
} else if (event.EventType == irr::EET_MOUSE_INPUT_EVENT) {
// Handle mouse events
KeyPress key;
@@ -253,4 +250,39 @@ void RandomInputHandler::step(float dtime)
}
}
mousepos += mousespeed;
+ static bool useJoystick = false;
+ {
+ static float counterUseJoystick = 0;
+ counterUseJoystick -= dtime;
+ if (counterUseJoystick < 0.0) {
+ counterUseJoystick = 5.0; // switch between joystick and keyboard direction input
+ useJoystick = !useJoystick;
+ }
+ }
+ if (useJoystick) {
+ static float counterMovement = 0;
+ counterMovement -= dtime;
+ if (counterMovement < 0.0) {
+ counterMovement = 0.1 * Rand(1, 40);
+ movementSpeed = Rand(0,100)*0.01;
+ movementDirection = Rand(-100, 100)*0.01 * M_PI;
+ }
+ } else {
+ bool f = keydown[keycache.key[KeyType::FORWARD]],
+ l = keydown[keycache.key[KeyType::LEFT]];
+ if (f || l) {
+ movementSpeed = 1.0f;
+ if (f && !l)
+ movementDirection = 0.0;
+ else if (!f && l)
+ movementDirection = -M_PI_2;
+ else if (f && l)
+ movementDirection = -M_PI_4;
+ else
+ movementDirection = 0.0;
+ } else {
+ movementSpeed = 0.0;
+ movementDirection = 0.0;
+ }
+ }
}
diff --git a/src/client/inputhandler.h b/src/client/inputhandler.h
index efe9442d5..951ec8884 100644
--- a/src/client/inputhandler.h
+++ b/src/client/inputhandler.h
@@ -242,6 +242,9 @@ public:
virtual bool wasKeyReleased(GameKeyType k) = 0;
virtual bool cancelPressed() = 0;
+ virtual float getMovementSpeed() = 0;
+ virtual float getMovementDirection() = 0;
+
virtual void clearWasKeyPressed() {}
virtual void clearWasKeyReleased() {}
@@ -296,6 +299,44 @@ public:
{
return m_receiver->WasKeyReleased(keycache.key[k]) || joystick.wasKeyReleased(k);
}
+ virtual float getMovementSpeed()
+ {
+ bool f = m_receiver->IsKeyDown(keycache.key[KeyType::FORWARD]),
+ b = m_receiver->IsKeyDown(keycache.key[KeyType::BACKWARD]),
+ l = m_receiver->IsKeyDown(keycache.key[KeyType::LEFT]),
+ r = m_receiver->IsKeyDown(keycache.key[KeyType::RIGHT]);
+ if (f || b || l || r)
+ {
+ // if contradictory keys pressed, stay still
+ if (f && b && l && r)
+ return 0.0f;
+ else if (f && b && !l && !r)
+ return 0.0f;
+ else if (!f && !b && l && r)
+ return 0.0f;
+ return 1.0f; // If there is a keyboard event, assume maximum speed
+ }
+ return joystick.getMovementSpeed();
+ }
+ virtual float getMovementDirection()
+ {
+ float x = 0, z = 0;
+
+ /* Check keyboard for input */
+ if (m_receiver->IsKeyDown(keycache.key[KeyType::FORWARD]))
+ z += 1;
+ if (m_receiver->IsKeyDown(keycache.key[KeyType::BACKWARD]))
+ z -= 1;
+ if (m_receiver->IsKeyDown(keycache.key[KeyType::RIGHT]))
+ x += 1;
+ if (m_receiver->IsKeyDown(keycache.key[KeyType::LEFT]))
+ x -= 1;
+
+ if (x != 0 || z != 0) /* If there is a keyboard event, it takes priority */
+ return atan2(x, z);
+ else
+ return joystick.getMovementDirection();
+ }
virtual bool cancelPressed()
{
return wasKeyDown(KeyType::ESC) || m_receiver->WasKeyDown(CancelKey);
@@ -371,6 +412,8 @@ public:
virtual bool wasKeyPressed(GameKeyType k) { return false; }
virtual bool wasKeyReleased(GameKeyType k) { return false; }
virtual bool cancelPressed() { return false; }
+ virtual float getMovementSpeed() { return movementSpeed; }
+ virtual float getMovementDirection() { return movementDirection; }
virtual v2s32 getMousePos() { return mousepos; }
virtual void setMousePos(s32 x, s32 y) { mousepos = v2s32(x, y); }
@@ -384,4 +427,6 @@ private:
KeyList keydown;
v2s32 mousepos;
v2s32 mousespeed;
+ float movementSpeed;
+ float movementDirection;
};
diff --git a/src/client/joystick_controller.cpp b/src/client/joystick_controller.cpp
index 919db5315..630565d8d 100644
--- a/src/client/joystick_controller.cpp
+++ b/src/client/joystick_controller.cpp
@@ -160,6 +160,7 @@ JoystickController::JoystickController() :
for (float &i : m_past_pressed_time) {
i = 0;
}
+ m_layout.axes_deadzone = 0;
clear();
}
@@ -251,10 +252,27 @@ void JoystickController::clear()
memset(m_axes_vals, 0, sizeof(m_axes_vals));
}
-s16 JoystickController::getAxisWithoutDead(JoystickAxis axis)
+float JoystickController::getAxisWithoutDead(JoystickAxis axis)
{
s16 v = m_axes_vals[axis];
+
if (abs(v) < m_layout.axes_deadzone)
- return 0;
- return v;
+ return 0.0f;
+
+ v += (v < 0 ? m_layout.axes_deadzone : -m_layout.axes_deadzone);
+
+ return (float)v / ((float)(INT16_MAX - m_layout.axes_deadzone));
+}
+
+float JoystickController::getMovementDirection()
+{
+ return atan2(getAxisWithoutDead(JA_SIDEWARD_MOVE), -getAxisWithoutDead(JA_FORWARD_MOVE));
+}
+
+float JoystickController::getMovementSpeed()
+{
+ float speed = sqrt(pow(getAxisWithoutDead(JA_FORWARD_MOVE), 2) + pow(getAxisWithoutDead(JA_SIDEWARD_MOVE), 2));
+ if (speed > 1.0f)
+ speed = 1.0f;
+ return speed;
}
diff --git a/src/client/joystick_controller.h b/src/client/joystick_controller.h
index 3f361e4ef..cbc60886c 100644
--- a/src/client/joystick_controller.h
+++ b/src/client/joystick_controller.h
@@ -144,7 +144,10 @@ public:
return m_axes_vals[axis];
}
- s16 getAxisWithoutDead(JoystickAxis axis);
+ float getAxisWithoutDead(JoystickAxis axis);
+
+ float getMovementDirection();
+ float getMovementSpeed();
f32 doubling_dtime;
diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp
index e979c5600..0a0a57cce 100644
--- a/src/client/localplayer.cpp
+++ b/src/client/localplayer.cpp
@@ -571,23 +571,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
}
}
- if (control.up)
- speedH += v3f(0.0f, 0.0f, 1.0f);
-
- if (control.down)
- speedH -= v3f(0.0f, 0.0f, 1.0f);
-
- if (!control.up && !control.down)
- speedH -= v3f(0.0f, 0.0f, 1.0f) * (control.forw_move_joystick_axis / 32767.f);
-
- if (control.left)
- speedH += v3f(-1.0f, 0.0f, 0.0f);
-
- if (control.right)
- speedH += v3f(1.0f, 0.0f, 0.0f);
-
- if (!control.left && !control.right)
- speedH += v3f(1.0f, 0.0f, 0.0f) * (control.sidew_move_joystick_axis / 32767.f);
+ speedH = v3f(sin(control.movement_direction), 0.0f, cos(control.movement_direction));
if (m_autojump) {
// release autojump after a given time
@@ -644,6 +628,8 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
else
speedH = speedH.normalize() * movement_speed_walk;
+ speedH *= control.movement_speed; /* Apply analog input */
+
// Acceleration increase
f32 incH = 0.0f; // Horizontal (X, Z)
f32 incV = 0.0f; // Vertical (Y)
@@ -1133,9 +1119,7 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env,
if (m_autojump)
return;
- bool control_forward = control.up ||
- (!control.up && !control.down &&
- control.forw_move_joystick_axis < -0.05f);
+ bool control_forward = keyPressed & (1 << 0);
bool could_autojump =
m_can_jump && !control.jump && !control.sneak && control_forward;
diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp
index 8877e0549..52729632a 100644
--- a/src/client/mapblock_mesh.cpp
+++ b/src/client/mapblock_mesh.cpp
@@ -410,20 +410,20 @@ static void getNodeTextureCoords(v3f base, const v3f &scale, const v3s16 &dir, f
if (dir.X > 0 || dir.Y != 0 || dir.Z < 0)
base -= scale;
if (dir == v3s16(0,0,1)) {
- *u = -base.X - 1;
- *v = -base.Y - 1;
+ *u = -base.X;
+ *v = -base.Y;
} else if (dir == v3s16(0,0,-1)) {
*u = base.X + 1;
- *v = -base.Y - 2;
+ *v = -base.Y - 1;
} else if (dir == v3s16(1,0,0)) {
*u = base.Z + 1;
- *v = -base.Y - 2;
- } else if (dir == v3s16(-1,0,0)) {
- *u = -base.Z - 1;
*v = -base.Y - 1;
+ } else if (dir == v3s16(-1,0,0)) {
+ *u = -base.Z;
+ *v = -base.Y;
} else if (dir == v3s16(0,1,0)) {
*u = base.X + 1;
- *v = -base.Z - 2;
+ *v = -base.Z - 1;
} else if (dir == v3s16(0,-1,0)) {
*u = base.X + 1;
*v = base.Z + 1;
@@ -805,7 +805,7 @@ static void getTileInfo(
VoxelManipulator &vmanip = data->m_vmanip;
const NodeDefManager *ndef = data->m_client->ndef();
v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
-
+
const MapNode &n0 = vmanip.getNodeRefUnsafe(blockpos_nodes + p);
content_t c0 = n0.getContent();
@@ -894,6 +894,9 @@ static void updateFastFaceRow(
g_settings->getBool("enable_shaders") &&
g_settings->getBool("enable_waving_water");
+ static thread_local const bool force_not_tiling =
+ g_settings->getBool("enable_dynamic_shadows");
+
v3s16 p = startpos;
u16 continuous_tiles_count = 1;
@@ -925,7 +928,7 @@ static void updateFastFaceRow(
// the face must be drawn anyway
if (j != MAP_BLOCKSIZE - 1) {
p += translate_dir;
-
+
getTileInfo(data, p, face_dir,
next_makes_face, next_p_corrected,
next_face_dir_corrected, next_lights,
@@ -933,8 +936,9 @@ static void updateFastFaceRow(
next_tile,
xray,
xraySet);
-
- if (next_makes_face == makes_face
+
+ if (!force_not_tiling
+ && next_makes_face == makes_face
&& next_p_corrected == p_corrected + translate_dir
&& next_face_dir_corrected == face_dir_corrected
&& memcmp(next_lights, lights, sizeof(lights)) == 0
@@ -1077,16 +1081,16 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
std::set<content_t> xraySet, nodeESPSet;
if (xray)
xraySet = splitToContentT(g_settings->get("xray_nodes"), data->m_client->ndef());
-
+
nodeESPSet = splitToContentT(g_settings->get("node_esp_nodes"), data->m_client->ndef());
-
+
/*
We are including the faces of the trailing edges of the block.
This means that when something changes, the caller must
also update the meshes of the blocks at the leading edges.
NOTE: This is the slowest part of this method.
- */
+ */
{
// 4-23ms for MAP_BLOCKSIZE=16 (NOTE: probably outdated)
//TimeTaker timer2("updateAllFastFaceRows()");
diff --git a/src/client/render/core.cpp b/src/client/render/core.cpp
index 99af085f9..1028a96e1 100644
--- a/src/client/render/core.cpp
+++ b/src/client/render/core.cpp
@@ -28,25 +28,35 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/content_cao.h"
#include "mapblock.h"
#include "mapsector.h"
+#include "client/shadows/dynamicshadowsrender.h"
RenderingCore::RenderingCore(IrrlichtDevice *_device, Client *_client, Hud *_hud)
: device(_device), driver(device->getVideoDriver()), smgr(device->getSceneManager()),
guienv(device->getGUIEnvironment()), client(_client), camera(client->getCamera()),
- mapper(client->getMinimap()), hud(_hud)
+ mapper(client->getMinimap()), hud(_hud),
+ shadow_renderer(nullptr)
{
screensize = driver->getScreenSize();
virtual_size = screensize;
+
+ if (g_settings->getBool("enable_shaders") &&
+ g_settings->getBool("enable_dynamic_shadows")) {
+ shadow_renderer = new ShadowRenderer(device, client);
+ }
}
RenderingCore::~RenderingCore()
{
clearTextures();
+ delete shadow_renderer;
}
void RenderingCore::initialize()
{
// have to be called late as the VMT is not ready in the constructor:
initTextures();
+ if (shadow_renderer)
+ shadow_renderer->initialize();
}
void RenderingCore::updateScreenSize()
@@ -75,24 +85,27 @@ void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_min
draw_player_tracers = g_settings->getBool("enable_player_tracers");
draw_node_esp = g_settings->getBool("enable_node_esp");
draw_node_tracers = g_settings->getBool("enable_node_tracers");
- v3f entity_color = g_settings->getV3F("entity_esp_color");
+ v3f entity_color = g_settings->getV3F("entity_esp_color");
v3f player_color = g_settings->getV3F("player_esp_color");
entity_esp_color = video::SColor(255, entity_color.X, entity_color.Y, entity_color.Z);
player_esp_color = video::SColor(255, player_color.X, player_color.Y, player_color.Z);
-
+
+ if (shadow_renderer)
+ shadow_renderer->update();
+
beforeDraw();
drawAll();
}
void RenderingCore::drawTracersAndESP()
-{
+{
ClientEnvironment &env = client->getEnv();
Camera *camera = client->getCamera();
-
+
v3f camera_offset = intToFloat(camera->getOffset(), BS);
-
+
v3f eye_pos = (camera->getPosition() + camera->getDirection() - camera_offset);
-
+
video::SMaterial material, oldmaterial;
oldmaterial = driver->getMaterial2D();
material.setFlag(video::EMF_LIGHTING, false);
@@ -100,7 +113,7 @@ void RenderingCore::drawTracersAndESP()
material.setFlag(video::EMF_ZBUFFER, false);
material.setFlag(video::EMF_ZWRITE_ENABLE, false);
driver->setMaterial(material);
-
+
if (draw_entity_esp || draw_entity_tracers || draw_player_esp || draw_player_tracers) {
auto allObjects = env.getAllActiveObjects();
for (auto &it : allObjects) {
@@ -153,13 +166,16 @@ void RenderingCore::drawTracersAndESP()
}
}
}
-
+
driver->setMaterial(oldmaterial);
}
void RenderingCore::draw3D()
{
smgr->drawAll();
+ if (shadow_renderer)
+ shadow_renderer->drawDebug();
+
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
if (!show_hud)
return;
@@ -176,7 +192,7 @@ void RenderingCore::drawHUD()
if (show_hud) {
if (draw_crosshair)
hud->drawCrosshair();
-
+
hud->drawHotbar(client->getEnv().getLocalPlayer()->getWieldIndex());
hud->drawLuaElements(camera->getOffset());
camera->drawNametags();
diff --git a/src/client/render/core.h b/src/client/render/core.h
index 386c5a840..0864f25bd 100644
--- a/src/client/render/core.h
+++ b/src/client/render/core.h
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
#include "irrlichttypes_extrabloated.h"
+class ShadowRenderer;
class Camera;
class Client;
class Hud;
@@ -55,6 +56,8 @@ protected:
Minimap *mapper;
Hud *hud;
+ ShadowRenderer *shadow_renderer;
+
void updateScreenSize();
virtual void initTextures() {}
virtual void clearTextures() {}
@@ -81,4 +84,6 @@ public:
bool _draw_wield_tool, bool _draw_crosshair);
inline v2u32 getVirtualSize() const { return virtual_size; }
+
+ ShadowRenderer *get_shadow_renderer() { return shadow_renderer; };
};
diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp
index 138012414..2e4994a40 100644
--- a/src/client/renderingengine.cpp
+++ b/src/client/renderingengine.cpp
@@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include <IrrlichtDevice.h>
-#include <irrlicht.h>
#include "fontengine.h"
#include "client.h"
#include "clouds.h"
@@ -92,7 +91,6 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
// bpp, fsaa, vsync
bool vsync = g_settings->getBool("vsync");
- u16 bits = g_settings->getU16("fullscreen_bpp");
u16 fsaa = g_settings->getU16("fsaa");
// stereo buffer required for pageflip stereo
@@ -106,7 +104,7 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
u32 i;
for (i = 0; i != drivers.size(); i++) {
if (!strcasecmp(driverstring.c_str(),
- RenderingEngine::getVideoDriverName(drivers[i]))) {
+ RenderingEngine::getVideoDriverInfo(drivers[i]).name.c_str())) {
driverType = drivers[i];
break;
}
@@ -122,15 +120,13 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
params.LoggingLevel = irr::ELL_DEBUG;
params.DriverType = driverType;
params.WindowSize = core::dimension2d<u32>(screen_w, screen_h);
- params.Bits = bits;
params.AntiAlias = fsaa;
params.Fullscreen = fullscreen;
params.Stencilbuffer = false;
params.Stereobuffer = stereo_buffer;
params.Vsync = vsync;
params.EventReceiver = receiver;
- params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
- params.ZBufferBits = 24;
+ params.HighPrecisionFPU = true;
#ifdef __ANDROID__
params.PrivateData = porting::app_global;
#endif
@@ -171,60 +167,6 @@ void RenderingEngine::setResizable(bool resize)
m_device->setResizable(resize);
}
-bool RenderingEngine::print_video_modes()
-{
- IrrlichtDevice *nulldevice;
-
- bool vsync = g_settings->getBool("vsync");
- u16 fsaa = g_settings->getU16("fsaa");
- MyEventReceiver *receiver = new MyEventReceiver();
-
- SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
- params.DriverType = video::EDT_NULL;
- params.WindowSize = core::dimension2d<u32>(640, 480);
- params.Bits = 24;
- params.AntiAlias = fsaa;
- params.Fullscreen = false;
- params.Stencilbuffer = false;
- params.Vsync = vsync;
- params.EventReceiver = receiver;
- params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
-
- nulldevice = createDeviceEx(params);
-
- if (!nulldevice) {
- delete receiver;
- return false;
- }
-
- std::cout << _("Available video modes (WxHxD):") << std::endl;
-
- video::IVideoModeList *videomode_list = nulldevice->getVideoModeList();
-
- if (videomode_list != NULL) {
- s32 videomode_count = videomode_list->getVideoModeCount();
- core::dimension2d<u32> videomode_res;
- s32 videomode_depth;
- for (s32 i = 0; i < videomode_count; ++i) {
- videomode_res = videomode_list->getVideoModeResolution(i);
- videomode_depth = videomode_list->getVideoModeDepth(i);
- std::cout << videomode_res.Width << "x" << videomode_res.Height
- << "x" << videomode_depth << std::endl;
- }
-
- std::cout << _("Active video mode (WxHxD):") << std::endl;
- videomode_res = videomode_list->getDesktopResolution();
- videomode_depth = videomode_list->getDesktopDepth();
- std::cout << videomode_res.Width << "x" << videomode_res.Height << "x"
- << videomode_depth << std::endl;
- }
-
- nulldevice->drop();
- delete receiver;
-
- return videomode_list != NULL;
-}
-
void RenderingEngine::removeMesh(const scene::IMesh* mesh)
{
m_device->getSceneManager()->getMeshCache()->removeMesh(mesh);
@@ -310,7 +252,7 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name)
// force a shutdown of an application if it doesn't respond to the destroy
// window message.
- verbosestream << "Client: Setting Xorg _NET_WM_PID extened window manager property"
+ verbosestream << "Client: Setting Xorg _NET_WM_PID extended window manager property"
<< std::endl;
Atom NET_WM_PID = XInternAtom(x11_dpl, "_NET_WM_PID", false);
@@ -341,14 +283,6 @@ static bool getWindowHandle(irr::video::IVideoDriver *driver, HWND &hWnd)
const video::SExposedVideoData exposedData = driver->getExposedVideoData();
switch (driver->getDriverType()) {
-#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9
- case video::EDT_DIRECT3D8:
- hWnd = reinterpret_cast<HWND>(exposedData.D3D8.HWnd);
- break;
-#endif
- case video::EDT_DIRECT3D9:
- hWnd = reinterpret_cast<HWND>(exposedData.D3D9.HWnd);
- break;
#if ENABLE_GLES
case video::EDT_OGLES1:
case video::EDT_OGLES2:
@@ -581,32 +515,21 @@ void RenderingEngine::draw_menu_scene(gui::IGUIEnvironment *guienv,
get_video_driver()->endScene();
}
-std::vector<core::vector3d<u32>> RenderingEngine::getSupportedVideoModes()
-{
- IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
- sanity_check(nulldevice);
-
- std::vector<core::vector3d<u32>> mlist;
- video::IVideoModeList *modelist = nulldevice->getVideoModeList();
-
- s32 num_modes = modelist->getVideoModeCount();
- for (s32 i = 0; i != num_modes; i++) {
- core::dimension2d<u32> mode_res = modelist->getVideoModeResolution(i);
- u32 mode_depth = (u32)modelist->getVideoModeDepth(i);
- mlist.emplace_back(mode_res.Width, mode_res.Height, mode_depth);
- }
-
- nulldevice->drop();
- return mlist;
-}
-
std::vector<irr::video::E_DRIVER_TYPE> RenderingEngine::getSupportedVideoDrivers()
{
+ // Only check these drivers.
+ // We do not support software and D3D in any capacity.
+ static const irr::video::E_DRIVER_TYPE glDrivers[4] = {
+ irr::video::EDT_NULL,
+ irr::video::EDT_OPENGL,
+ irr::video::EDT_OGLES1,
+ irr::video::EDT_OGLES2,
+ };
std::vector<irr::video::E_DRIVER_TYPE> drivers;
- for (int i = 0; i != irr::video::EDT_COUNT; i++) {
- if (irr::IrrlichtDevice::isDriverSupported((irr::video::E_DRIVER_TYPE)i))
- drivers.push_back((irr::video::E_DRIVER_TYPE)i);
+ for (int i = 0; i < 4; i++) {
+ if (irr::IrrlichtDevice::isDriverSupported(glDrivers[i]))
+ drivers.push_back(glDrivers[i]);
}
return drivers;
@@ -630,36 +553,15 @@ void RenderingEngine::draw_scene(video::SColor skycolor, bool show_hud,
core->draw(skycolor, show_hud, show_minimap, draw_wield_tool, draw_crosshair);
}
-const char *RenderingEngine::getVideoDriverName(irr::video::E_DRIVER_TYPE type)
+const VideoDriverInfo &RenderingEngine::getVideoDriverInfo(irr::video::E_DRIVER_TYPE type)
{
- static const char *driver_ids[] = {
- "null",
- "software",
- "burningsvideo",
- "direct3d8",
- "direct3d9",
- "opengl",
- "ogles1",
- "ogles2",
+ static const std::unordered_map<int, VideoDriverInfo> driver_info_map = {
+ {(int)video::EDT_NULL, {"null", "NULL Driver"}},
+ {(int)video::EDT_OPENGL, {"opengl", "OpenGL"}},
+ {(int)video::EDT_OGLES1, {"ogles1", "OpenGL ES1"}},
+ {(int)video::EDT_OGLES2, {"ogles2", "OpenGL ES2"}},
};
-
- return driver_ids[type];
-}
-
-const char *RenderingEngine::getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type)
-{
- static const char *driver_names[] = {
- "NULL Driver",
- "Software Renderer",
- "Burning's Video",
- "Direct3D 8",
- "Direct3D 9",
- "OpenGL",
- "OpenGL ES1",
- "OpenGL ES2",
- };
-
- return driver_names[type];
+ return driver_info_map.at((int)type);
}
#ifndef __ANDROID__
diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h
index 28ddc8652..6f104bba9 100644
--- a/src/client/renderingengine.h
+++ b/src/client/renderingengine.h
@@ -25,6 +25,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <string>
#include "irrlichttypes_extrabloated.h"
#include "debug.h"
+#include "client/render/core.h"
+// include the shadow mapper classes too
+#include "client/shadows/dynamicshadowsrender.h"
+
+struct VideoDriverInfo {
+ std::string name;
+ std::string friendly_name;
+};
class ITextureSource;
class Camera;
@@ -45,8 +53,7 @@ public:
video::IVideoDriver *getVideoDriver() { return driver; }
- static const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type);
- static const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type);
+ static const VideoDriverInfo &getVideoDriverInfo(irr::video::E_DRIVER_TYPE type);
static float getDisplayDensity();
static v2u32 getDisplaySize();
@@ -113,7 +120,13 @@ public:
return m_device->run();
}
- static std::vector<core::vector3d<u32>> getSupportedVideoModes();
+ // FIXME: this is still global when it shouldn't be
+ static ShadowRenderer *get_shadow_renderer()
+ {
+ if (s_singleton && s_singleton->core)
+ return s_singleton->core->get_shadow_renderer();
+ return nullptr;
+ }
static std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();
private:
diff --git a/src/client/shader.cpp b/src/client/shader.cpp
index 58946b90f..dc9e9ae6d 100644
--- a/src/client/shader.cpp
+++ b/src/client/shader.cpp
@@ -225,6 +225,16 @@ class MainShaderConstantSetter : public IShaderConstantSetter
{
CachedVertexShaderSetting<float, 16> m_world_view_proj;
CachedVertexShaderSetting<float, 16> m_world;
+
+ // Shadow-related
+ CachedPixelShaderSetting<float, 16> m_shadow_view_proj;
+ CachedPixelShaderSetting<float, 3> m_light_direction;
+ CachedPixelShaderSetting<float> m_texture_res;
+ CachedPixelShaderSetting<float> m_shadow_strength;
+ CachedPixelShaderSetting<float> m_time_of_day;
+ CachedPixelShaderSetting<float> m_shadowfar;
+ CachedPixelShaderSetting<s32> m_shadow_texture;
+
#if ENABLE_GLES
// Modelview matrix
CachedVertexShaderSetting<float, 16> m_world_view;
@@ -243,6 +253,13 @@ public:
, m_texture("mTexture")
, m_normal("mNormal")
#endif
+ , m_shadow_view_proj("m_ShadowViewProj")
+ , m_light_direction("v_LightDirection")
+ , m_texture_res("f_textureresolution")
+ , m_shadow_strength("f_shadow_strength")
+ , m_time_of_day("f_timeofday")
+ , m_shadowfar("f_shadowfar")
+ , m_shadow_texture("ShadowMapSampler")
{}
~MainShaderConstantSetter() = default;
@@ -280,6 +297,36 @@ public:
};
m_normal.set(m, services);
#endif
+
+ // Set uniforms for Shadow shader
+ if (ShadowRenderer *shadow = RenderingEngine::get_shadow_renderer()) {
+ const auto &light = shadow->getDirectionalLight();
+
+ core::matrix4 shadowViewProj = light.getProjectionMatrix();
+ shadowViewProj *= light.getViewMatrix();
+ m_shadow_view_proj.set(shadowViewProj.pointer(), services);
+
+ float v_LightDirection[3];
+ light.getDirection().getAs3Values(v_LightDirection);
+ m_light_direction.set(v_LightDirection, services);
+
+ float TextureResolution = light.getMapResolution();
+ m_texture_res.set(&TextureResolution, services);
+
+ float ShadowStrength = shadow->getShadowStrength();
+ m_shadow_strength.set(&ShadowStrength, services);
+
+ float timeOfDay = shadow->getTimeOfDay();
+ m_time_of_day.set(&timeOfDay, services);
+
+ float shadowFar = shadow->getMaxShadowFar();
+ m_shadowfar.set(&shadowFar, services);
+
+ // I dont like using this hardcoded value. maybe something like
+ // MAX_TEXTURE - 1 or somthing like that??
+ s32 TextureLayerID = 3;
+ m_shadow_texture.set(&TextureLayerID, services);
+ }
}
};
@@ -627,8 +674,12 @@ ShaderInfo ShaderSource::generateShader(const std::string &name,
if (strstr(gl_renderer, "GC7000"))
use_discard = true;
#endif
- if (use_discard && shaderinfo.base_material != video::EMT_SOLID)
- shaders_header << "#define USE_DISCARD 1\n";
+ if (use_discard) {
+ if (shaderinfo.base_material == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
+ shaders_header << "#define USE_DISCARD 1\n";
+ else if (shaderinfo.base_material == video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF)
+ shaders_header << "#define USE_DISCARD_REF 1\n";
+ }
#define PROVIDE(constant) shaders_header << "#define " #constant " " << (int)constant << "\n"
@@ -682,6 +733,23 @@ ShaderInfo ShaderSource::generateShader(const std::string &name,
shaders_header << "#define FOG_START " << core::clamp(g_settings->getFloat("fog_start"), 0.0f, 0.99f) << "\n";
+ if (g_settings->getBool("enable_dynamic_shadows")) {
+ shaders_header << "#define ENABLE_DYNAMIC_SHADOWS 1\n";
+ if (g_settings->getBool("shadow_map_color"))
+ shaders_header << "#define COLORED_SHADOWS 1\n";
+
+ if (g_settings->getBool("shadow_poisson_filter"))
+ shaders_header << "#define POISSON_FILTER 1\n";
+
+ s32 shadow_filter = g_settings->getS32("shadow_filters");
+ shaders_header << "#define SHADOW_FILTER " << shadow_filter << "\n";
+
+ float shadow_soft_radius = g_settings->getFloat("shadow_soft_radius");
+ if (shadow_soft_radius < 1.0f)
+ shadow_soft_radius = 1.0f;
+ shaders_header << "#define SOFTSHADOWRADIUS " << shadow_soft_radius << "\n";
+ }
+
std::string common_header = shaders_header.str();
std::string vertex_shader = m_sourcecache.getOrLoad(name, "opengl_vertex.glsl");
diff --git a/src/client/shadows/dynamicshadows.cpp b/src/client/shadows/dynamicshadows.cpp
new file mode 100644
index 000000000..0c7eea0e7
--- /dev/null
+++ b/src/client/shadows/dynamicshadows.cpp
@@ -0,0 +1,182 @@
+/*
+Minetest
+Copyright (C) 2021 Liso <anlismon@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include <cmath>
+
+#include "client/shadows/dynamicshadows.h"
+#include "client/client.h"
+#include "client/clientenvironment.h"
+#include "client/clientmap.h"
+#include "client/camera.h"
+
+using m4f = core::matrix4;
+
+void DirectionalLight::createSplitMatrices(const Camera *cam)
+{
+ float radius;
+ v3f newCenter;
+ v3f look = cam->getDirection();
+
+ // camera view tangents
+ float tanFovY = tanf(cam->getFovY() * 0.5f);
+ float tanFovX = tanf(cam->getFovX() * 0.5f);
+
+ // adjusted frustum boundaries
+ float sfNear = future_frustum.zNear;
+ float sfFar = adjustDist(future_frustum.zFar, cam->getFovY());
+
+ // adjusted camera positions
+ v3f camPos2 = cam->getPosition();
+ v3f camPos = v3f(camPos2.X - cam->getOffset().X * BS,
+ camPos2.Y - cam->getOffset().Y * BS,
+ camPos2.Z - cam->getOffset().Z * BS);
+ camPos += look * sfNear;
+ camPos2 += look * sfNear;
+
+ // center point of light frustum
+ float end = sfNear + sfFar;
+ newCenter = camPos + look * (sfNear + 0.05f * end);
+ v3f world_center = camPos2 + look * (sfNear + 0.05f * end);
+
+ // Create a vector to the frustum far corner
+ const v3f &viewUp = cam->getCameraNode()->getUpVector();
+ v3f viewRight = look.crossProduct(viewUp);
+
+ v3f farCorner = look + viewRight * tanFovX + viewUp * tanFovY;
+ // Compute the frustumBoundingSphere radius
+ v3f boundVec = (camPos + farCorner * sfFar) - newCenter;
+ radius = boundVec.getLength() * 2.0f;
+ // boundVec.getLength();
+ float vvolume = radius * 2.0f;
+
+ float texelsPerUnit = getMapResolution() / vvolume;
+ m4f mTexelScaling;
+ mTexelScaling.setScale(texelsPerUnit);
+
+ m4f mLookAt, mLookAtInv;
+
+ mLookAt.buildCameraLookAtMatrixLH(v3f(0.0f, 0.0f, 0.0f), -direction, v3f(0.0f, 1.0f, 0.0f));
+
+ mLookAt *= mTexelScaling;
+ mLookAtInv = mLookAt;
+ mLookAtInv.makeInverse();
+
+ v3f frustumCenter = newCenter;
+ mLookAt.transformVect(frustumCenter);
+ frustumCenter.X = floorf(frustumCenter.X); // clamp to texel increment
+ frustumCenter.Y = floorf(frustumCenter.Y); // clamp to texel increment
+ frustumCenter.Z = floorf(frustumCenter.Z);
+ mLookAtInv.transformVect(frustumCenter);
+ // probar radius multipliacdor en funcion del I, a menor I mas multiplicador
+ v3f eye_displacement = direction * vvolume;
+
+ // we must compute the viewmat with the position - the camera offset
+ // but the future_frustum position must be the actual world position
+ v3f eye = frustumCenter - eye_displacement;
+ future_frustum.position = world_center - eye_displacement;
+ future_frustum.length = vvolume;
+ future_frustum.ViewMat.buildCameraLookAtMatrixLH(eye, frustumCenter, v3f(0.0f, 1.0f, 0.0f));
+ future_frustum.ProjOrthMat.buildProjectionMatrixOrthoLH(future_frustum.length,
+ future_frustum.length, -future_frustum.length,
+ future_frustum.length,false);
+ future_frustum.camera_offset = cam->getOffset();
+}
+
+DirectionalLight::DirectionalLight(const u32 shadowMapResolution,
+ const v3f &position, video::SColorf lightColor,
+ f32 farValue) :
+ diffuseColor(lightColor),
+ farPlane(farValue), mapRes(shadowMapResolution), pos(position)
+{}
+
+void DirectionalLight::update_frustum(const Camera *cam, Client *client, bool force)
+{
+ if (dirty && !force)
+ return;
+
+ float zNear = cam->getCameraNode()->getNearValue();
+ float zFar = getMaxFarValue();
+
+ ///////////////////////////////////
+ // update splits near and fars
+ future_frustum.zNear = zNear;
+ future_frustum.zFar = zFar;
+
+ // update shadow frustum
+ createSplitMatrices(cam);
+ // get the draw list for shadows
+ client->getEnv().getClientMap().updateDrawListShadow(
+ getPosition(), getDirection(), future_frustum.length);
+ should_update_map_shadow = true;
+ dirty = true;
+
+ // when camera offset changes, adjust the current frustum view matrix to avoid flicker
+ v3s16 cam_offset = cam->getOffset();
+ if (cam_offset != shadow_frustum.camera_offset) {
+ v3f rotated_offset;
+ shadow_frustum.ViewMat.rotateVect(rotated_offset, intToFloat(cam_offset - shadow_frustum.camera_offset, BS));
+ shadow_frustum.ViewMat.setTranslation(shadow_frustum.ViewMat.getTranslation() + rotated_offset);
+ shadow_frustum.camera_offset = cam_offset;
+ }
+}
+
+void DirectionalLight::commitFrustum()
+{
+ if (!dirty)
+ return;
+
+ shadow_frustum = future_frustum;
+ dirty = false;
+}
+
+void DirectionalLight::setDirection(v3f dir)
+{
+ direction = -dir;
+ direction.normalize();
+}
+
+v3f DirectionalLight::getPosition() const
+{
+ return shadow_frustum.position;
+}
+
+const m4f &DirectionalLight::getViewMatrix() const
+{
+ return shadow_frustum.ViewMat;
+}
+
+const m4f &DirectionalLight::getProjectionMatrix() const
+{
+ return shadow_frustum.ProjOrthMat;
+}
+
+const m4f &DirectionalLight::getFutureViewMatrix() const
+{
+ return future_frustum.ViewMat;
+}
+
+const m4f &DirectionalLight::getFutureProjectionMatrix() const
+{
+ return future_frustum.ProjOrthMat;
+}
+
+m4f DirectionalLight::getViewProjMatrix()
+{
+ return shadow_frustum.ProjOrthMat * shadow_frustum.ViewMat;
+}
diff --git a/src/client/shadows/dynamicshadows.h b/src/client/shadows/dynamicshadows.h
new file mode 100644
index 000000000..d8be66be8
--- /dev/null
+++ b/src/client/shadows/dynamicshadows.h
@@ -0,0 +1,109 @@
+/*
+Minetest
+Copyright (C) 2021 Liso <anlismon@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+
+#include "irrlichttypes_bloated.h"
+#include <matrix4.h>
+#include "util/basic_macros.h"
+
+class Camera;
+class Client;
+
+struct shadowFrustum
+{
+ float zNear{0.0f};
+ float zFar{0.0f};
+ float length{0.0f};
+ core::matrix4 ProjOrthMat;
+ core::matrix4 ViewMat;
+ v3f position;
+ v3s16 camera_offset;
+};
+
+class DirectionalLight
+{
+public:
+ DirectionalLight(const u32 shadowMapResolution,
+ const v3f &position,
+ video::SColorf lightColor = video::SColor(0xffffffff),
+ f32 farValue = 100.0f);
+ ~DirectionalLight() = default;
+
+ //DISABLE_CLASS_COPY(DirectionalLight)
+
+ void update_frustum(const Camera *cam, Client *client, bool force = false);
+
+ // when set direction is updated to negative normalized(direction)
+ void setDirection(v3f dir);
+ v3f getDirection() const{
+ return direction;
+ };
+ v3f getPosition() const;
+
+ /// Gets the light's matrices.
+ const core::matrix4 &getViewMatrix() const;
+ const core::matrix4 &getProjectionMatrix() const;
+ const core::matrix4 &getFutureViewMatrix() const;
+ const core::matrix4 &getFutureProjectionMatrix() const;
+ core::matrix4 getViewProjMatrix();
+
+ /// Gets the light's far value.
+ f32 getMaxFarValue() const
+ {
+ return farPlane;
+ }
+
+
+ /// Gets the light's color.
+ const video::SColorf &getLightColor() const
+ {
+ return diffuseColor;
+ }
+
+ /// Sets the light's color.
+ void setLightColor(const video::SColorf &lightColor)
+ {
+ diffuseColor = lightColor;
+ }
+
+ /// Gets the shadow map resolution for this light.
+ u32 getMapResolution() const
+ {
+ return mapRes;
+ }
+
+ bool should_update_map_shadow{true};
+
+ void commitFrustum();
+
+private:
+ void createSplitMatrices(const Camera *cam);
+
+ video::SColorf diffuseColor;
+
+ f32 farPlane;
+ u32 mapRes;
+
+ v3f pos;
+ v3f direction{0};
+ shadowFrustum shadow_frustum;
+ shadowFrustum future_frustum;
+ bool dirty{false};
+};
diff --git a/src/client/shadows/dynamicshadowsrender.cpp b/src/client/shadows/dynamicshadowsrender.cpp
new file mode 100644
index 000000000..a913a9290
--- /dev/null
+++ b/src/client/shadows/dynamicshadowsrender.cpp
@@ -0,0 +1,630 @@
+/*
+Minetest
+Copyright (C) 2021 Liso <anlismon@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include <cstring>
+#include "client/shadows/dynamicshadowsrender.h"
+#include "client/shadows/shadowsScreenQuad.h"
+#include "client/shadows/shadowsshadercallbacks.h"
+#include "settings.h"
+#include "filesys.h"
+#include "util/string.h"
+#include "client/shader.h"
+#include "client/client.h"
+#include "client/clientmap.h"
+#include "profiler.h"
+
+ShadowRenderer::ShadowRenderer(IrrlichtDevice *device, Client *client) :
+ m_device(device), m_smgr(device->getSceneManager()),
+ m_driver(device->getVideoDriver()), m_client(client), m_current_frame(0)
+{
+ m_shadows_enabled = true;
+
+ m_shadow_strength = g_settings->getFloat("shadow_strength");
+
+ m_shadow_map_max_distance = g_settings->getFloat("shadow_map_max_distance");
+
+ m_shadow_map_texture_size = g_settings->getFloat("shadow_map_texture_size");
+
+ m_shadow_map_texture_32bit = g_settings->getBool("shadow_map_texture_32bit");
+ m_shadow_map_colored = g_settings->getBool("shadow_map_color");
+ m_shadow_samples = g_settings->getS32("shadow_filters");
+ m_map_shadow_update_frames = g_settings->getS16("shadow_update_frames");
+}
+
+ShadowRenderer::~ShadowRenderer()
+{
+ if (m_shadow_depth_cb)
+ delete m_shadow_depth_cb;
+ if (m_shadow_mix_cb)
+ delete m_shadow_mix_cb;
+ m_shadow_node_array.clear();
+ m_light_list.clear();
+
+ if (shadowMapTextureDynamicObjects)
+ m_driver->removeTexture(shadowMapTextureDynamicObjects);
+
+ if (shadowMapTextureFinal)
+ m_driver->removeTexture(shadowMapTextureFinal);
+
+ if (shadowMapTextureColors)
+ m_driver->removeTexture(shadowMapTextureColors);
+
+ if (shadowMapClientMap)
+ m_driver->removeTexture(shadowMapClientMap);
+
+ if (shadowMapClientMapFuture)
+ m_driver->removeTexture(shadowMapClientMapFuture);
+}
+
+void ShadowRenderer::initialize()
+{
+ auto *gpu = m_driver->getGPUProgrammingServices();
+
+ // we need glsl
+ if (m_shadows_enabled && gpu && m_driver->queryFeature(video::EVDF_ARB_GLSL)) {
+ createShaders();
+ } else {
+ m_shadows_enabled = false;
+
+ warningstream << "Shadows: GLSL Shader not supported on this system."
+ << std::endl;
+ return;
+ }
+
+ m_texture_format = m_shadow_map_texture_32bit
+ ? video::ECOLOR_FORMAT::ECF_R32F
+ : video::ECOLOR_FORMAT::ECF_R16F;
+
+ m_texture_format_color = m_shadow_map_texture_32bit
+ ? video::ECOLOR_FORMAT::ECF_G32R32F
+ : video::ECOLOR_FORMAT::ECF_G16R16F;
+}
+
+
+size_t ShadowRenderer::addDirectionalLight()
+{
+ m_light_list.emplace_back(m_shadow_map_texture_size,
+ v3f(0.f, 0.f, 0.f),
+ video::SColor(255, 255, 255, 255), m_shadow_map_max_distance);
+ return m_light_list.size() - 1;
+}
+
+DirectionalLight &ShadowRenderer::getDirectionalLight(u32 index)
+{
+ return m_light_list[index];
+}
+
+size_t ShadowRenderer::getDirectionalLightCount() const
+{
+ return m_light_list.size();
+}
+
+f32 ShadowRenderer::getMaxShadowFar() const
+{
+ if (!m_light_list.empty()) {
+ float wanted_range = m_client->getEnv().getClientMap().getWantedRange();
+
+ float zMax = m_light_list[0].getMaxFarValue() > wanted_range
+ ? wanted_range
+ : m_light_list[0].getMaxFarValue();
+ return zMax * MAP_BLOCKSIZE;
+ }
+ return 0.0f;
+}
+
+void ShadowRenderer::addNodeToShadowList(
+ scene::ISceneNode *node, E_SHADOW_MODE shadowMode)
+{
+ m_shadow_node_array.emplace_back(NodeToApply(node, shadowMode));
+}
+
+void ShadowRenderer::removeNodeFromShadowList(scene::ISceneNode *node)
+{
+ for (auto it = m_shadow_node_array.begin(); it != m_shadow_node_array.end();) {
+ if (it->node == node) {
+ it = m_shadow_node_array.erase(it);
+ break;
+ } else {
+ ++it;
+ }
+ }
+}
+
+void ShadowRenderer::updateSMTextures()
+{
+ if (!m_shadows_enabled || m_smgr->getActiveCamera() == nullptr) {
+ return;
+ }
+
+ if (!shadowMapTextureDynamicObjects) {
+
+ shadowMapTextureDynamicObjects = getSMTexture(
+ std::string("shadow_dynamic_") + itos(m_shadow_map_texture_size),
+ m_texture_format, true);
+ }
+
+ if (!shadowMapClientMap) {
+
+ shadowMapClientMap = getSMTexture(
+ std::string("shadow_clientmap_") + itos(m_shadow_map_texture_size),
+ m_shadow_map_colored ? m_texture_format_color : m_texture_format,
+ true);
+ }
+
+ if (!shadowMapClientMapFuture && m_map_shadow_update_frames > 1) {
+ shadowMapClientMapFuture = getSMTexture(
+ std::string("shadow_clientmap_bb_") + itos(m_shadow_map_texture_size),
+ m_shadow_map_colored ? m_texture_format_color : m_texture_format,
+ true);
+ }
+
+ if (m_shadow_map_colored && !shadowMapTextureColors) {
+ shadowMapTextureColors = getSMTexture(
+ std::string("shadow_colored_") + itos(m_shadow_map_texture_size),
+ m_shadow_map_colored ? m_texture_format_color : m_texture_format,
+ true);
+ }
+
+ // The merge all shadowmaps texture
+ if (!shadowMapTextureFinal) {
+ video::ECOLOR_FORMAT frt;
+ if (m_shadow_map_texture_32bit) {
+ if (m_shadow_map_colored)
+ frt = video::ECOLOR_FORMAT::ECF_A32B32G32R32F;
+ else
+ frt = video::ECOLOR_FORMAT::ECF_R32F;
+ } else {
+ if (m_shadow_map_colored)
+ frt = video::ECOLOR_FORMAT::ECF_A16B16G16R16F;
+ else
+ frt = video::ECOLOR_FORMAT::ECF_R16F;
+ }
+ shadowMapTextureFinal = getSMTexture(
+ std::string("shadowmap_final_") + itos(m_shadow_map_texture_size),
+ frt, true);
+ }
+
+ if (!m_shadow_node_array.empty() && !m_light_list.empty()) {
+ bool reset_sm_texture = false;
+
+ // detect if SM should be regenerated
+ for (DirectionalLight &light : m_light_list) {
+ if (light.should_update_map_shadow) {
+ light.should_update_map_shadow = false;
+ m_current_frame = 0;
+ reset_sm_texture = true;
+ }
+ }
+
+ video::ITexture* shadowMapTargetTexture = shadowMapClientMapFuture;
+ if (shadowMapTargetTexture == nullptr)
+ shadowMapTargetTexture = shadowMapClientMap;
+
+ // Update SM incrementally:
+ for (DirectionalLight &light : m_light_list) {
+ // Static shader values.
+ m_shadow_depth_cb->MapRes = (f32)m_shadow_map_texture_size;
+ m_shadow_depth_cb->MaxFar = (f32)m_shadow_map_max_distance * BS;
+
+ // set the Render Target
+ // right now we can only render in usual RTT, not
+ // Depth texture is available in irrlicth maybe we
+ // should put some gl* fn here
+
+
+ if (m_current_frame < m_map_shadow_update_frames) {
+ m_driver->setRenderTarget(shadowMapTargetTexture, reset_sm_texture, true,
+ video::SColor(255, 255, 255, 255));
+ renderShadowMap(shadowMapTargetTexture, light);
+
+ // Render transparent part in one pass.
+ // This is also handled in ClientMap.
+ if (m_current_frame == m_map_shadow_update_frames - 1) {
+ if (m_shadow_map_colored) {
+ m_driver->setRenderTarget(0, false, false);
+ m_driver->setRenderTarget(shadowMapTextureColors,
+ true, false, video::SColor(255, 255, 255, 255));
+ }
+ renderShadowMap(shadowMapTextureColors, light,
+ scene::ESNRP_TRANSPARENT);
+ }
+ m_driver->setRenderTarget(0, false, false);
+ }
+
+ reset_sm_texture = false;
+ } // end for lights
+
+ // move to the next section
+ if (m_current_frame <= m_map_shadow_update_frames)
+ ++m_current_frame;
+
+ // pass finished, swap textures and commit light changes
+ if (m_current_frame == m_map_shadow_update_frames) {
+ if (shadowMapClientMapFuture != nullptr)
+ std::swap(shadowMapClientMapFuture, shadowMapClientMap);
+
+ // Let all lights know that maps are updated
+ for (DirectionalLight &light : m_light_list)
+ light.commitFrustum();
+ }
+ }
+}
+
+void ShadowRenderer::update(video::ITexture *outputTarget)
+{
+ if (!m_shadows_enabled || m_smgr->getActiveCamera() == nullptr) {
+ return;
+ }
+
+ updateSMTextures();
+
+ if (!m_shadow_node_array.empty() && !m_light_list.empty()) {
+
+ for (DirectionalLight &light : m_light_list) {
+ // Static shader values.
+ m_shadow_depth_cb->MapRes = (f32)m_shadow_map_texture_size;
+ m_shadow_depth_cb->MaxFar = (f32)m_shadow_map_max_distance * BS;
+
+ // render shadows for the n0n-map objects.
+ m_driver->setRenderTarget(shadowMapTextureDynamicObjects, true,
+ true, video::SColor(255, 255, 255, 255));
+ renderShadowObjects(shadowMapTextureDynamicObjects, light);
+ // clear the Render Target
+ m_driver->setRenderTarget(0, false, false);
+
+ // in order to avoid too many map shadow renders,
+ // we should make a second pass to mix clientmap shadows and
+ // entities shadows :(
+ m_screen_quad->getMaterial().setTexture(0, shadowMapClientMap);
+ // dynamic objs shadow texture.
+ if (m_shadow_map_colored)
+ m_screen_quad->getMaterial().setTexture(1, shadowMapTextureColors);
+ m_screen_quad->getMaterial().setTexture(2, shadowMapTextureDynamicObjects);
+
+ m_driver->setRenderTarget(shadowMapTextureFinal, false, false,
+ video::SColor(255, 255, 255, 255));
+ m_screen_quad->render(m_driver);
+ m_driver->setRenderTarget(0, false, false);
+
+ } // end for lights
+ }
+}
+
+void ShadowRenderer::drawDebug()
+{
+ /* this code just shows shadows textures in screen and in ONLY for debugging*/
+ #if 0
+ // this is debug, ignore for now.
+ m_driver->draw2DImage(shadowMapTextureFinal,
+ core::rect<s32>(0, 50, 128, 128 + 50),
+ core::rect<s32>({0, 0}, shadowMapTextureFinal->getSize()));
+
+ m_driver->draw2DImage(shadowMapClientMap,
+ core::rect<s32>(0, 50 + 128, 128, 128 + 50 + 128),
+ core::rect<s32>({0, 0}, shadowMapTextureFinal->getSize()));
+ m_driver->draw2DImage(shadowMapTextureDynamicObjects,
+ core::rect<s32>(0, 128 + 50 + 128, 128,
+ 128 + 50 + 128 + 128),
+ core::rect<s32>({0, 0}, shadowMapTextureDynamicObjects->getSize()));
+
+ if (m_shadow_map_colored) {
+
+ m_driver->draw2DImage(shadowMapTextureColors,
+ core::rect<s32>(128,128 + 50 + 128 + 128,
+ 128 + 128, 128 + 50 + 128 + 128 + 128),
+ core::rect<s32>({0, 0}, shadowMapTextureColors->getSize()));
+ }
+ #endif
+}
+
+
+video::ITexture *ShadowRenderer::getSMTexture(const std::string &shadow_map_name,
+ video::ECOLOR_FORMAT texture_format, bool force_creation)
+{
+ if (force_creation) {
+ return m_driver->addRenderTargetTexture(
+ core::dimension2du(m_shadow_map_texture_size,
+ m_shadow_map_texture_size),
+ shadow_map_name.c_str(), texture_format);
+ }
+
+ return m_driver->getTexture(shadow_map_name.c_str());
+}
+
+void ShadowRenderer::renderShadowMap(video::ITexture *target,
+ DirectionalLight &light, scene::E_SCENE_NODE_RENDER_PASS pass)
+{
+ m_driver->setTransform(video::ETS_VIEW, light.getFutureViewMatrix());
+ m_driver->setTransform(video::ETS_PROJECTION, light.getFutureProjectionMatrix());
+
+ // Operate on the client map
+ for (const auto &shadow_node : m_shadow_node_array) {
+ if (strcmp(shadow_node.node->getName(), "ClientMap") != 0)
+ continue;
+
+ ClientMap *map_node = static_cast<ClientMap *>(shadow_node.node);
+
+ video::SMaterial material;
+ if (map_node->getMaterialCount() > 0) {
+ // we only want the first material, which is the one with the albedo info
+ material = map_node->getMaterial(0);
+ }
+
+ material.BackfaceCulling = false;
+ material.FrontfaceCulling = true;
+ material.PolygonOffsetFactor = 4.0f;
+ material.PolygonOffsetDirection = video::EPO_BACK;
+ //material.PolygonOffsetDepthBias = 1.0f/4.0f;
+ //material.PolygonOffsetSlopeScale = -1.f;
+
+ if (m_shadow_map_colored && pass != scene::ESNRP_SOLID) {
+ material.MaterialType = (video::E_MATERIAL_TYPE) depth_shader_trans;
+ }
+ else {
+ material.MaterialType = (video::E_MATERIAL_TYPE) depth_shader;
+ material.BlendOperation = video::EBO_MIN;
+ }
+
+ // FIXME: I don't think this is needed here
+ map_node->OnAnimate(m_device->getTimer()->getTime());
+
+ m_driver->setTransform(video::ETS_WORLD,
+ map_node->getAbsoluteTransformation());
+
+ map_node->renderMapShadows(m_driver, material, pass, m_current_frame, m_map_shadow_update_frames);
+ break;
+ }
+}
+
+void ShadowRenderer::renderShadowObjects(
+ video::ITexture *target, DirectionalLight &light)
+{
+ m_driver->setTransform(video::ETS_VIEW, light.getViewMatrix());
+ m_driver->setTransform(video::ETS_PROJECTION, light.getProjectionMatrix());
+
+ for (const auto &shadow_node : m_shadow_node_array) {
+ // we only take care of the shadow casters
+ if (shadow_node.shadowMode == ESM_RECEIVE ||
+ strcmp(shadow_node.node->getName(), "ClientMap") == 0)
+ continue;
+
+ // render other objects
+ u32 n_node_materials = shadow_node.node->getMaterialCount();
+ std::vector<s32> BufferMaterialList;
+ std::vector<std::pair<bool, bool>> BufferMaterialCullingList;
+ std::vector<video::E_BLEND_OPERATION> BufferBlendOperationList;
+ BufferMaterialList.reserve(n_node_materials);
+ BufferMaterialCullingList.reserve(n_node_materials);
+ BufferBlendOperationList.reserve(n_node_materials);
+
+ // backup materialtype for each material
+ // (aka shader)
+ // and replace it by our "depth" shader
+ for (u32 m = 0; m < n_node_materials; m++) {
+ auto &current_mat = shadow_node.node->getMaterial(m);
+
+ BufferMaterialList.push_back(current_mat.MaterialType);
+ current_mat.MaterialType =
+ (video::E_MATERIAL_TYPE)depth_shader_entities;
+
+ BufferMaterialCullingList.emplace_back(
+ (bool)current_mat.BackfaceCulling, (bool)current_mat.FrontfaceCulling);
+ BufferBlendOperationList.push_back(current_mat.BlendOperation);
+
+ current_mat.BackfaceCulling = true;
+ current_mat.FrontfaceCulling = false;
+ current_mat.PolygonOffsetFactor = 1.0f/2048.0f;
+ current_mat.PolygonOffsetDirection = video::EPO_BACK;
+ //current_mat.PolygonOffsetDepthBias = 1.0 * 2.8e-6;
+ //current_mat.PolygonOffsetSlopeScale = -1.f;
+ }
+
+ m_driver->setTransform(video::ETS_WORLD,
+ shadow_node.node->getAbsoluteTransformation());
+ shadow_node.node->render();
+
+ // restore the material.
+
+ for (u32 m = 0; m < n_node_materials; m++) {
+ auto &current_mat = shadow_node.node->getMaterial(m);
+
+ current_mat.MaterialType = (video::E_MATERIAL_TYPE) BufferMaterialList[m];
+
+ current_mat.BackfaceCulling = BufferMaterialCullingList[m].first;
+ current_mat.FrontfaceCulling = BufferMaterialCullingList[m].second;
+ current_mat.BlendOperation = BufferBlendOperationList[m];
+ }
+
+ } // end for caster shadow nodes
+}
+
+void ShadowRenderer::mixShadowsQuad()
+{
+}
+
+/*
+ * @Liso's disclaimer ;) This function loads the Shadow Mapping Shaders.
+ * I used a custom loader because I couldn't figure out how to use the base
+ * Shaders system with custom IShaderConstantSetCallBack without messing up the
+ * code too much. If anyone knows how to integrate this with the standard MT
+ * shaders, please feel free to change it.
+ */
+
+void ShadowRenderer::createShaders()
+{
+ video::IGPUProgrammingServices *gpu = m_driver->getGPUProgrammingServices();
+
+ if (depth_shader == -1) {
+ std::string depth_shader_vs = getShaderPath("shadow_shaders", "pass1_vertex.glsl");
+ if (depth_shader_vs.empty()) {
+ m_shadows_enabled = false;
+ errorstream << "Error shadow mapping vs shader not found." << std::endl;
+ return;
+ }
+ std::string depth_shader_fs = getShaderPath("shadow_shaders", "pass1_fragment.glsl");
+ if (depth_shader_fs.empty()) {
+ m_shadows_enabled = false;
+ errorstream << "Error shadow mapping fs shader not found." << std::endl;
+ return;
+ }
+ m_shadow_depth_cb = new ShadowDepthShaderCB();
+
+ depth_shader = gpu->addHighLevelShaderMaterial(
+ readShaderFile(depth_shader_vs).c_str(), "vertexMain",
+ video::EVST_VS_1_1,
+ readShaderFile(depth_shader_fs).c_str(), "pixelMain",
+ video::EPST_PS_1_2, m_shadow_depth_cb, video::EMT_ONETEXTURE_BLEND);
+
+ if (depth_shader == -1) {
+ // upsi, something went wrong loading shader.
+ delete m_shadow_depth_cb;
+ m_shadows_enabled = false;
+ errorstream << "Error compiling shadow mapping shader." << std::endl;
+ return;
+ }
+
+ // HACK, TODO: investigate this better
+ // Grab the material renderer once more so minetest doesn't crash
+ // on exit
+ m_driver->getMaterialRenderer(depth_shader)->grab();
+ }
+
+ // This creates a clone of depth_shader with base material set to EMT_SOLID,
+ // because entities won't render shadows with base material EMP_ONETEXTURE_BLEND
+ if (depth_shader_entities == -1) {
+ std::string depth_shader_vs = getShaderPath("shadow_shaders", "pass1_vertex.glsl");
+ if (depth_shader_vs.empty()) {
+ m_shadows_enabled = false;
+ errorstream << "Error shadow mapping vs shader not found." << std::endl;
+ return;
+ }
+ std::string depth_shader_fs = getShaderPath("shadow_shaders", "pass1_fragment.glsl");
+ if (depth_shader_fs.empty()) {
+ m_shadows_enabled = false;
+ errorstream << "Error shadow mapping fs shader not found." << std::endl;
+ return;
+ }
+
+ depth_shader_entities = gpu->addHighLevelShaderMaterial(
+ readShaderFile(depth_shader_vs).c_str(), "vertexMain",
+ video::EVST_VS_1_1,
+ readShaderFile(depth_shader_fs).c_str(), "pixelMain",
+ video::EPST_PS_1_2, m_shadow_depth_cb);
+
+ if (depth_shader_entities == -1) {
+ // upsi, something went wrong loading shader.
+ m_shadows_enabled = false;
+ errorstream << "Error compiling shadow mapping shader (dynamic)." << std::endl;
+ return;
+ }
+
+ // HACK, TODO: investigate this better
+ // Grab the material renderer once more so minetest doesn't crash
+ // on exit
+ m_driver->getMaterialRenderer(depth_shader_entities)->grab();
+ }
+
+ if (mixcsm_shader == -1) {
+ std::string depth_shader_vs = getShaderPath("shadow_shaders", "pass2_vertex.glsl");
+ if (depth_shader_vs.empty()) {
+ m_shadows_enabled = false;
+ errorstream << "Error cascade shadow mapping fs shader not found." << std::endl;
+ return;
+ }
+
+ std::string depth_shader_fs = getShaderPath("shadow_shaders", "pass2_fragment.glsl");
+ if (depth_shader_fs.empty()) {
+ m_shadows_enabled = false;
+ errorstream << "Error cascade shadow mapping fs shader not found." << std::endl;
+ return;
+ }
+ m_shadow_mix_cb = new shadowScreenQuadCB();
+ m_screen_quad = new shadowScreenQuad();
+ mixcsm_shader = gpu->addHighLevelShaderMaterial(
+ readShaderFile(depth_shader_vs).c_str(), "vertexMain",
+ video::EVST_VS_1_1,
+ readShaderFile(depth_shader_fs).c_str(), "pixelMain",
+ video::EPST_PS_1_2, m_shadow_mix_cb);
+
+ m_screen_quad->getMaterial().MaterialType =
+ (video::E_MATERIAL_TYPE)mixcsm_shader;
+
+ if (mixcsm_shader == -1) {
+ // upsi, something went wrong loading shader.
+ delete m_shadow_mix_cb;
+ delete m_screen_quad;
+ m_shadows_enabled = false;
+ errorstream << "Error compiling cascade shadow mapping shader." << std::endl;
+ return;
+ }
+
+ // HACK, TODO: investigate this better
+ // Grab the material renderer once more so minetest doesn't crash
+ // on exit
+ m_driver->getMaterialRenderer(mixcsm_shader)->grab();
+ }
+
+ if (m_shadow_map_colored && depth_shader_trans == -1) {
+ std::string depth_shader_vs = getShaderPath("shadow_shaders", "pass1_trans_vertex.glsl");
+ if (depth_shader_vs.empty()) {
+ m_shadows_enabled = false;
+ errorstream << "Error shadow mapping vs shader not found." << std::endl;
+ return;
+ }
+ std::string depth_shader_fs = getShaderPath("shadow_shaders", "pass1_trans_fragment.glsl");
+ if (depth_shader_fs.empty()) {
+ m_shadows_enabled = false;
+ errorstream << "Error shadow mapping fs shader not found." << std::endl;
+ return;
+ }
+ m_shadow_depth_trans_cb = new ShadowDepthShaderCB();
+
+ depth_shader_trans = gpu->addHighLevelShaderMaterial(
+ readShaderFile(depth_shader_vs).c_str(), "vertexMain",
+ video::EVST_VS_1_1,
+ readShaderFile(depth_shader_fs).c_str(), "pixelMain",
+ video::EPST_PS_1_2, m_shadow_depth_trans_cb);
+
+ if (depth_shader_trans == -1) {
+ // upsi, something went wrong loading shader.
+ delete m_shadow_depth_trans_cb;
+ m_shadow_map_colored = false;
+ m_shadows_enabled = false;
+ errorstream << "Error compiling colored shadow mapping shader." << std::endl;
+ return;
+ }
+
+ // HACK, TODO: investigate this better
+ // Grab the material renderer once more so minetest doesn't crash
+ // on exit
+ m_driver->getMaterialRenderer(depth_shader_trans)->grab();
+ }
+}
+
+std::string ShadowRenderer::readShaderFile(const std::string &path)
+{
+ std::string prefix;
+ if (m_shadow_map_colored)
+ prefix.append("#define COLORED_SHADOWS 1\n");
+
+ std::string content;
+ fs::ReadFile(path, content);
+
+ return prefix + content;
+}
diff --git a/src/client/shadows/dynamicshadowsrender.h b/src/client/shadows/dynamicshadowsrender.h
new file mode 100644
index 000000000..e4b3c3e22
--- /dev/null
+++ b/src/client/shadows/dynamicshadowsrender.h
@@ -0,0 +1,147 @@
+/*
+Minetest
+Copyright (C) 2021 Liso <anlismon@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+
+#include <string>
+#include <vector>
+#include "irrlichttypes_extrabloated.h"
+#include "client/shadows/dynamicshadows.h"
+
+class ShadowDepthShaderCB;
+class shadowScreenQuad;
+class shadowScreenQuadCB;
+
+enum E_SHADOW_MODE : u8
+{
+ ESM_RECEIVE = 0,
+ ESM_BOTH,
+};
+
+struct NodeToApply
+{
+ NodeToApply(scene::ISceneNode *n,
+ E_SHADOW_MODE m = E_SHADOW_MODE::ESM_BOTH) :
+ node(n),
+ shadowMode(m){};
+ bool operator<(const NodeToApply &other) const { return node < other.node; };
+
+ scene::ISceneNode *node;
+
+ E_SHADOW_MODE shadowMode{E_SHADOW_MODE::ESM_BOTH};
+ bool dirty{false};
+};
+
+class ShadowRenderer
+{
+public:
+ ShadowRenderer(IrrlichtDevice *device, Client *client);
+
+ ~ShadowRenderer();
+
+ void initialize();
+
+ /// Adds a directional light shadow map (Usually just one (the sun) except in
+ /// Tattoine ).
+ size_t addDirectionalLight();
+ DirectionalLight &getDirectionalLight(u32 index = 0);
+ size_t getDirectionalLightCount() const;
+ f32 getMaxShadowFar() const;
+
+ /// Adds a shadow to the scene node.
+ /// The shadow mode can be ESM_BOTH, or ESM_RECEIVE.
+ /// ESM_BOTH casts and receives shadows
+ /// ESM_RECEIVE only receives but does not cast shadows.
+ ///
+ void addNodeToShadowList(scene::ISceneNode *node,
+ E_SHADOW_MODE shadowMode = ESM_BOTH);
+ void removeNodeFromShadowList(scene::ISceneNode *node);
+
+ void update(video::ITexture *outputTarget = nullptr);
+ void drawDebug();
+
+ video::ITexture *get_texture()
+ {
+ return shadowMapTextureFinal;
+ }
+
+
+ bool is_active() const { return m_shadows_enabled; }
+ void setTimeOfDay(float isDay) { m_time_day = isDay; };
+
+ s32 getShadowSamples() const { return m_shadow_samples; }
+ float getShadowStrength() const { return m_shadow_strength; }
+ float getTimeOfDay() const { return m_time_day; }
+
+private:
+ video::ITexture *getSMTexture(const std::string &shadow_map_name,
+ video::ECOLOR_FORMAT texture_format,
+ bool force_creation = false);
+
+ void renderShadowMap(video::ITexture *target, DirectionalLight &light,
+ scene::E_SCENE_NODE_RENDER_PASS pass =
+ scene::ESNRP_SOLID);
+ void renderShadowObjects(video::ITexture *target, DirectionalLight &light);
+ void mixShadowsQuad();
+ void updateSMTextures();
+
+ // a bunch of variables
+ IrrlichtDevice *m_device{nullptr};
+ scene::ISceneManager *m_smgr{nullptr};
+ video::IVideoDriver *m_driver{nullptr};
+ Client *m_client{nullptr};
+ video::ITexture *shadowMapClientMap{nullptr};
+ video::ITexture *shadowMapClientMapFuture{nullptr};
+ video::ITexture *shadowMapTextureFinal{nullptr};
+ video::ITexture *shadowMapTextureDynamicObjects{nullptr};
+ video::ITexture *shadowMapTextureColors{nullptr};
+
+ std::vector<DirectionalLight> m_light_list;
+ std::vector<NodeToApply> m_shadow_node_array;
+
+ float m_shadow_strength;
+ float m_shadow_map_max_distance;
+ float m_shadow_map_texture_size;
+ float m_time_day{0.0f};
+ int m_shadow_samples;
+ bool m_shadow_map_texture_32bit;
+ bool m_shadows_enabled;
+ bool m_shadow_map_colored;
+ u8 m_map_shadow_update_frames; /* Use this number of frames to update map shaodw */
+ u8 m_current_frame{0}; /* Current frame */
+
+ video::ECOLOR_FORMAT m_texture_format{video::ECOLOR_FORMAT::ECF_R16F};
+ video::ECOLOR_FORMAT m_texture_format_color{video::ECOLOR_FORMAT::ECF_R16G16};
+
+ // Shadow Shader stuff
+
+ void createShaders();
+ std::string readShaderFile(const std::string &path);
+
+ s32 depth_shader{-1};
+ s32 depth_shader_entities{-1};
+ s32 depth_shader_trans{-1};
+ s32 mixcsm_shader{-1};
+
+ ShadowDepthShaderCB *m_shadow_depth_cb{nullptr};
+ ShadowDepthShaderCB *m_shadow_depth_trans_cb{nullptr};
+
+ shadowScreenQuad *m_screen_quad{nullptr};
+ shadowScreenQuadCB *m_shadow_mix_cb{nullptr};
+};
diff --git a/src/client/shadows/shadowsScreenQuad.cpp b/src/client/shadows/shadowsScreenQuad.cpp
new file mode 100644
index 000000000..5f6d38157
--- /dev/null
+++ b/src/client/shadows/shadowsScreenQuad.cpp
@@ -0,0 +1,61 @@
+/*
+Minetest
+Copyright (C) 2021 Liso <anlismon@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "shadowsScreenQuad.h"
+
+shadowScreenQuad::shadowScreenQuad()
+{
+ Material.Wireframe = false;
+ Material.Lighting = false;
+
+ video::SColor color(0x0);
+ Vertices[0] = video::S3DVertex(
+ -1.0f, -1.0f, 0.0f, 0, 0, 1, color, 0.0f, 1.0f);
+ Vertices[1] = video::S3DVertex(
+ -1.0f, 1.0f, 0.0f, 0, 0, 1, color, 0.0f, 0.0f);
+ Vertices[2] = video::S3DVertex(
+ 1.0f, 1.0f, 0.0f, 0, 0, 1, color, 1.0f, 0.0f);
+ Vertices[3] = video::S3DVertex(
+ 1.0f, -1.0f, 0.0f, 0, 0, 1, color, 1.0f, 1.0f);
+ Vertices[4] = video::S3DVertex(
+ -1.0f, -1.0f, 0.0f, 0, 0, 1, color, 0.0f, 1.0f);
+ Vertices[5] = video::S3DVertex(
+ 1.0f, 1.0f, 0.0f, 0, 0, 1, color, 1.0f, 0.0f);
+}
+
+void shadowScreenQuad::render(video::IVideoDriver *driver)
+{
+ u16 indices[6] = {0, 1, 2, 3, 4, 5};
+ driver->setMaterial(Material);
+ driver->setTransform(video::ETS_WORLD, core::matrix4());
+ driver->drawIndexedTriangleList(&Vertices[0], 6, &indices[0], 2);
+}
+
+void shadowScreenQuadCB::OnSetConstants(
+ video::IMaterialRendererServices *services, s32 userData)
+{
+ s32 TextureId = 0;
+ m_sm_client_map_setting.set(&TextureId, services);
+
+ TextureId = 1;
+ m_sm_client_map_trans_setting.set(&TextureId, services);
+
+ TextureId = 2;
+ m_sm_dynamic_sampler_setting.set(&TextureId, services);
+}
diff --git a/src/client/shadows/shadowsScreenQuad.h b/src/client/shadows/shadowsScreenQuad.h
new file mode 100644
index 000000000..c18be9a2b
--- /dev/null
+++ b/src/client/shadows/shadowsScreenQuad.h
@@ -0,0 +1,54 @@
+/*
+Minetest
+Copyright (C) 2021 Liso <anlismon@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+#include "irrlichttypes_extrabloated.h"
+#include <IMaterialRendererServices.h>
+#include <IShaderConstantSetCallBack.h>
+#include "client/shader.h"
+
+class shadowScreenQuad
+{
+public:
+ shadowScreenQuad();
+
+ void render(video::IVideoDriver *driver);
+ video::SMaterial &getMaterial() { return Material; }
+
+private:
+ video::S3DVertex Vertices[6];
+ video::SMaterial Material;
+};
+
+class shadowScreenQuadCB : public video::IShaderConstantSetCallBack
+{
+public:
+ shadowScreenQuadCB() :
+ m_sm_client_map_setting("ShadowMapClientMap"),
+ m_sm_client_map_trans_setting("ShadowMapClientMapTraslucent"),
+ m_sm_dynamic_sampler_setting("ShadowMapSamplerdynamic")
+ {}
+
+ virtual void OnSetConstants(video::IMaterialRendererServices *services,
+ s32 userData);
+private:
+ CachedPixelShaderSetting<s32> m_sm_client_map_setting;
+ CachedPixelShaderSetting<s32> m_sm_client_map_trans_setting;
+ CachedPixelShaderSetting<s32> m_sm_dynamic_sampler_setting;
+};
diff --git a/src/client/shadows/shadowsshadercallbacks.cpp b/src/client/shadows/shadowsshadercallbacks.cpp
new file mode 100644
index 000000000..65a63f49c
--- /dev/null
+++ b/src/client/shadows/shadowsshadercallbacks.cpp
@@ -0,0 +1,36 @@
+/*
+Minetest
+Copyright (C) 2021 Liso <anlismon@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "client/shadows/shadowsshadercallbacks.h"
+
+void ShadowDepthShaderCB::OnSetConstants(
+ video::IMaterialRendererServices *services, s32 userData)
+{
+ video::IVideoDriver *driver = services->getVideoDriver();
+
+ core::matrix4 lightMVP = driver->getTransform(video::ETS_PROJECTION);
+ lightMVP *= driver->getTransform(video::ETS_VIEW);
+ lightMVP *= driver->getTransform(video::ETS_WORLD);
+
+ m_light_mvp_setting.set(lightMVP.pointer(), services);
+ m_map_resolution_setting.set(&MapRes, services);
+ m_max_far_setting.set(&MaxFar, services);
+ s32 TextureId = 0;
+ m_color_map_sampler_setting.set(&TextureId, services);
+}
diff --git a/src/client/shadows/shadowsshadercallbacks.h b/src/client/shadows/shadowsshadercallbacks.h
new file mode 100644
index 000000000..3549567c3
--- /dev/null
+++ b/src/client/shadows/shadowsshadercallbacks.h
@@ -0,0 +1,48 @@
+/*
+Minetest
+Copyright (C) 2021 Liso <anlismon@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+#include "irrlichttypes_extrabloated.h"
+#include <IMaterialRendererServices.h>
+#include <IShaderConstantSetCallBack.h>
+#include "client/shader.h"
+
+class ShadowDepthShaderCB : public video::IShaderConstantSetCallBack
+{
+public:
+ ShadowDepthShaderCB() :
+ m_light_mvp_setting("LightMVP"),
+ m_map_resolution_setting("MapResolution"),
+ m_max_far_setting("MaxFar"),
+ m_color_map_sampler_setting("ColorMapSampler")
+ {}
+
+ void OnSetMaterial(const video::SMaterial &material) override {}
+
+ void OnSetConstants(video::IMaterialRendererServices *services,
+ s32 userData) override;
+
+ f32 MaxFar{2048.0f}, MapRes{1024.0f};
+
+private:
+ CachedVertexShaderSetting<f32, 16> m_light_mvp_setting;
+ CachedVertexShaderSetting<f32> m_map_resolution_setting;
+ CachedVertexShaderSetting<f32> m_max_far_setting;
+ CachedPixelShaderSetting<s32> m_color_map_sampler_setting;
+};
diff --git a/src/client/sky.cpp b/src/client/sky.cpp
index 47296a7a5..1cf9a4afc 100644
--- a/src/client/sky.cpp
+++ b/src/client/sky.cpp
@@ -122,7 +122,14 @@ Sky::Sky(s32 id, RenderingEngine *rendering_engine, ITextureSource *tsrc, IShade
m_materials[i].Lighting = true;
m_materials[i].MaterialType = video::EMT_SOLID;
}
+
m_directional_colored_fog = g_settings->getBool("directional_colored_fog");
+
+ if (g_settings->getBool("enable_dynamic_shadows")) {
+ float val = g_settings->getFloat("shadow_sky_body_orbit_tilt");
+ m_sky_body_orbit_tilt = rangelim(val, 0.0f, 60.0f);
+ }
+
setStarCount(1000, true);
}
@@ -175,17 +182,7 @@ void Sky::render()
video::SColorf mooncolor_f(0.50, 0.57, 0.65, 1);
video::SColorf mooncolor2_f(0.85, 0.875, 0.9, 1);
- float nightlength = 0.415;
- float wn = nightlength / 2;
- float wicked_time_of_day = 0;
- if (m_time_of_day > wn && m_time_of_day < 1.0 - wn)
- wicked_time_of_day = (m_time_of_day - wn) / (1.0 - wn * 2) * 0.5 + 0.25;
- else if (m_time_of_day < 0.5)
- wicked_time_of_day = m_time_of_day / wn * 0.25;
- else
- wicked_time_of_day = 1.0 - ((1.0 - m_time_of_day) / wn * 0.25);
- /*std::cerr<<"time_of_day="<<m_time_of_day<<" -> "
- <<"wicked_time_of_day="<<wicked_time_of_day<<std::endl;*/
+ float wicked_time_of_day = getWickedTimeOfDay(m_time_of_day);
video::SColor suncolor = suncolor_f.toSColor();
video::SColor suncolor2 = suncolor2_f.toSColor();
@@ -739,10 +736,15 @@ void Sky::place_sky_body(
* day_position: turn the body around the Z axis, to place it depending of the time of the day
*/
{
+ v3f centrum(0, 0, -1);
+ centrum.rotateXZBy(horizon_position);
+ centrum.rotateXYBy(day_position);
+ centrum.rotateYZBy(m_sky_body_orbit_tilt);
for (video::S3DVertex &vertex : vertices) {
// Body is directed to -Z (south) by default
vertex.Pos.rotateXZBy(horizon_position);
vertex.Pos.rotateXYBy(day_position);
+ vertex.Pos.Z += centrum.Z;
}
}
@@ -931,3 +933,17 @@ void Sky::setSkyDefaults()
m_moon_params = sky_defaults.getMoonDefaults();
m_star_params = sky_defaults.getStarDefaults();
}
+
+float getWickedTimeOfDay(float time_of_day)
+{
+ float nightlength = 0.415f;
+ float wn = nightlength / 2;
+ float wicked_time_of_day = 0;
+ if (time_of_day > wn && time_of_day < 1.0f - wn)
+ wicked_time_of_day = (time_of_day - wn) / (1.0f - wn * 2) * 0.5f + 0.25f;
+ else if (time_of_day < 0.5f)
+ wicked_time_of_day = time_of_day / wn * 0.25f;
+ else
+ wicked_time_of_day = 1.0f - ((1.0f - time_of_day) / wn * 0.25f);
+ return wicked_time_of_day;
+}
diff --git a/src/client/sky.h b/src/client/sky.h
index 121a16bb7..83106453b 100644
--- a/src/client/sky.h
+++ b/src/client/sky.h
@@ -105,6 +105,8 @@ public:
ITextureSource *tsrc);
const video::SColorf &getCurrentStarColor() const { return m_star_color; }
+ float getSkyBodyOrbitTilt() const { return m_sky_body_orbit_tilt; }
+
private:
aabb3f m_box;
video::SMaterial m_materials[SKY_MATERIAL_COUNT];
@@ -159,6 +161,7 @@ private:
bool m_directional_colored_fog;
bool m_in_clouds = true; // Prevent duplicating bools to remember old values
bool m_enable_shaders = false;
+ float m_sky_body_orbit_tilt = 0.0f;
video::SColorf m_bgcolor_bright_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
video::SColorf m_skycolor_bright_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
@@ -205,3 +208,7 @@ private:
float horizon_position, float day_position);
void setSkyDefaults();
};
+
+// calculates value for sky body positions for the given observed time of day
+// this is used to draw both Sun/Moon and shadows
+float getWickedTimeOfDay(float time_of_day);
diff --git a/src/client/sound_openal.cpp b/src/client/sound_openal.cpp
index 8dceeede6..0eda8842b 100644
--- a/src/client/sound_openal.cpp
+++ b/src/client/sound_openal.cpp
@@ -362,6 +362,14 @@ public:
for (auto &buffer : m_buffers) {
for (SoundBuffer *sb : buffer.second) {
+ alDeleteBuffers(1, &sb->buffer_id);
+
+ ALenum error = alGetError();
+ if (error != AL_NO_ERROR) {
+ warningstream << "Audio: Failed to free stream for "
+ << buffer.first << ": " << alErrorString(error) << std::endl;
+ }
+
delete sb;
}
buffer.second.clear();
diff --git a/src/client/tile.cpp b/src/client/tile.cpp
index 96312ea27..a31e3aca1 100644
--- a/src/client/tile.cpp
+++ b/src/client/tile.cpp
@@ -81,12 +81,8 @@ static bool replace_ext(std::string &path, const char *ext)
std::string getImagePath(std::string path)
{
// A NULL-ended list of possible image extensions
- const char *extensions[] = {
- "png", "jpg", "bmp", "tga",
- "pcx", "ppm", "psd", "wal", "rgb",
- NULL
- };
- // If there is no extension, add one
+ const char *extensions[] = { "png", "jpg", "bmp", "tga", NULL };
+ // If there is no extension, assume PNG
if (removeStringEnd(path, extensions).empty())
path = path + ".png";
// Check paths until something is found to exist
diff --git a/src/client/wieldmesh.cpp b/src/client/wieldmesh.cpp
index 08fd49fc0..6beed3f3a 100644
--- a/src/client/wieldmesh.cpp
+++ b/src/client/wieldmesh.cpp
@@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/numeric.h"
#include <map>
#include <IMeshManipulator.h>
+#include "client/renderingengine.h"
#define WIELD_SCALE_FACTOR 30.0
#define WIELD_SCALE_FACTOR_EXTRUDED 40.0
@@ -220,11 +221,18 @@ WieldMeshSceneNode::WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id, bool l
m_meshnode->setReadOnlyMaterials(false);
m_meshnode->setVisible(false);
dummymesh->drop(); // m_meshnode grabbed it
+
+ m_shadow = RenderingEngine::get_shadow_renderer();
}
WieldMeshSceneNode::~WieldMeshSceneNode()
{
sanity_check(g_extrusion_mesh_cache);
+
+ // Remove node from shadow casters. m_shadow might be an invalid pointer!
+ if (auto shadow = RenderingEngine::get_shadow_renderer())
+ shadow->removeNodeFromShadowList(m_meshnode);
+
if (g_extrusion_mesh_cache->drop())
g_extrusion_mesh_cache = nullptr;
}
@@ -527,6 +535,10 @@ void WieldMeshSceneNode::changeToMesh(scene::IMesh *mesh)
// need to normalize normals when lighting is enabled (because of setScale())
m_meshnode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, m_lighting);
m_meshnode->setVisible(true);
+
+ // Add mesh to shadow caster
+ if (m_shadow)
+ m_shadow->addNodeToShadowList(m_meshnode);
}
void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
diff --git a/src/client/wieldmesh.h b/src/client/wieldmesh.h
index 933097230..d1eeb64f5 100644
--- a/src/client/wieldmesh.h
+++ b/src/client/wieldmesh.h
@@ -27,6 +27,7 @@ struct ItemStack;
class Client;
class ITextureSource;
struct ContentFeatures;
+class ShadowRenderer;
/*!
* Holds color information of an item mesh's buffer.
@@ -124,6 +125,8 @@ private:
// so this variable is just required so we can implement
// getBoundingBox() and is set to an empty box.
aabb3f m_bounding_box;
+
+ ShadowRenderer *m_shadow;
};
void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result);