3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "clientmap.h"
22 #include "mapblock_mesh.h"
23 #include <IMaterialRenderer.h>
26 #include "mapsector.h"
31 #include "camera.h" // CameraModes
32 #include "util/mathconstants.h"
35 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
40 MapDrawControl &control,
41 scene::ISceneNode* parent,
42 scene::ISceneManager* mgr,
45 Map(dout_client, gamedef),
46 scene::ISceneNode(parent, mgr, id),
49 m_camera_position(0,0,0),
50 m_camera_direction(0,0,1),
53 m_box = aabb3f(-BS*1000000,-BS*1000000,-BS*1000000,
54 BS*1000000,BS*1000000,BS*1000000);
56 /* TODO: Add a callback function so these can be updated when a setting
57 * changes. At this point in time it doesn't matter (e.g. /set
58 * is documented to change server settings only)
60 * TODO: Local caching of settings is not optimal and should at some stage
61 * be updated to use a global settings object for getting thse values
62 * (as opposed to the this local caching). This can be addressed in
65 m_cache_trilinear_filter = g_settings->getBool("trilinear_filter");
66 m_cache_bilinear_filter = g_settings->getBool("bilinear_filter");
67 m_cache_anistropic_filter = g_settings->getBool("anisotropic_filter");
71 ClientMap::~ClientMap()
73 /*MutexAutoLock lock(mesh_mutex);
82 MapSector * ClientMap::emergeSector(v2s16 p2d)
84 DSTACK(FUNCTION_NAME);
85 // Check that it doesn't exist already
87 return getSectorNoGenerate(p2d);
89 catch(InvalidPositionException &e)
94 ClientMapSector *sector = new ClientMapSector(this, p2d, m_gamedef);
97 //MutexAutoLock lock(m_sector_mutex); // Bulk comment-out
98 m_sectors[p2d] = sector;
104 void ClientMap::OnRegisterSceneNode()
108 SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID);
109 SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
112 ISceneNode::OnRegisterSceneNode();
115 static bool isOccluded(Map *map, v3s16 p0, v3s16 p1, float step, float stepfac,
116 float start_off, float end_off, u32 needed_count, INodeDefManager *nodemgr)
118 float d0 = (float)BS * p0.getDistanceFrom(p1);
120 v3f uf = v3f(u0.X, u0.Y, u0.Z) * BS;
122 v3f p0f = v3f(p0.X, p0.Y, p0.Z) * BS;
124 for(float s=start_off; s<d0+end_off; s+=step){
125 v3f pf = p0f + uf * s;
126 v3s16 p = floatToInt(pf, BS);
127 MapNode n = map->getNodeNoEx(p);
128 bool is_transparent = false;
129 const ContentFeatures &f = nodemgr->get(n);
131 is_transparent = (f.visual_solidness != 2);
133 is_transparent = (f.solidness != 2);
136 if(count >= needed_count)
144 void ClientMap::getBlocksInViewRange(v3s16 cam_pos_nodes,
145 v3s16 *p_blocks_min, v3s16 *p_blocks_max)
147 v3s16 box_nodes_d = m_control.wanted_range * v3s16(1, 1, 1);
148 // Define p_nodes_min/max as v3s32 because 'cam_pos_nodes -/+ box_nodes_d'
149 // can exceed the range of v3s16 when a large view range is used near the
152 cam_pos_nodes.X - box_nodes_d.X,
153 cam_pos_nodes.Y - box_nodes_d.Y,
154 cam_pos_nodes.Z - box_nodes_d.Z);
156 cam_pos_nodes.X + box_nodes_d.X,
157 cam_pos_nodes.Y + box_nodes_d.Y,
158 cam_pos_nodes.Z + box_nodes_d.Z);
159 // Take a fair amount as we will be dropping more out later
160 // Umm... these additions are a bit strange but they are needed.
161 *p_blocks_min = v3s16(
162 p_nodes_min.X / MAP_BLOCKSIZE - 3,
163 p_nodes_min.Y / MAP_BLOCKSIZE - 3,
164 p_nodes_min.Z / MAP_BLOCKSIZE - 3);
165 *p_blocks_max = v3s16(
166 p_nodes_max.X / MAP_BLOCKSIZE + 1,
167 p_nodes_max.Y / MAP_BLOCKSIZE + 1,
168 p_nodes_max.Z / MAP_BLOCKSIZE + 1);
171 void ClientMap::updateDrawList(video::IVideoDriver* driver)
173 ScopeProfiler sp(g_profiler, "CM::updateDrawList()", SPT_AVG);
174 g_profiler->add("CM::updateDrawList() count", 1);
176 INodeDefManager *nodemgr = m_gamedef->ndef();
178 for (std::map<v3s16, MapBlock*>::iterator i = m_drawlist.begin();
179 i != m_drawlist.end(); ++i) {
180 MapBlock *block = i->second;
185 v3f camera_position = m_camera_position;
186 v3f camera_direction = m_camera_direction;
187 f32 camera_fov = m_camera_fov;
189 // Use a higher fov to accomodate faster camera movements.
190 // Blocks are cropped better when they are drawn.
191 // Or maybe they aren't? Well whatever.
194 v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
197 getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max);
199 // Number of blocks in rendering range
200 u32 blocks_in_range = 0;
201 // Number of blocks occlusion culled
202 u32 blocks_occlusion_culled = 0;
203 // Number of blocks in rendering range but don't have a mesh
204 u32 blocks_in_range_without_mesh = 0;
205 // Blocks that had mesh that would have been drawn according to
206 // rendering range (if max blocks limit didn't kick in)
207 u32 blocks_would_have_drawn = 0;
208 // Blocks that were drawn and had a mesh
209 u32 blocks_drawn = 0;
210 // Blocks which had a corresponding meshbuffer for this pass
211 //u32 blocks_had_pass_meshbuf = 0;
212 // Blocks from which stuff was actually drawn
213 //u32 blocks_without_stuff = 0;
214 // Distance to farthest drawn block
215 float farthest_drawn = 0;
217 for (std::map<v2s16, MapSector*>::iterator si = m_sectors.begin();
218 si != m_sectors.end(); ++si) {
219 MapSector *sector = si->second;
220 v2s16 sp = sector->getPos();
222 if (m_control.range_all == false) {
223 if (sp.X < p_blocks_min.X || sp.X > p_blocks_max.X ||
224 sp.Y < p_blocks_min.Z || sp.Y > p_blocks_max.Z)
228 MapBlockVect sectorblocks;
229 sector->getBlocks(sectorblocks);
232 Loop through blocks in sector
235 u32 sector_blocks_drawn = 0;
237 for (MapBlockVect::iterator i = sectorblocks.begin();
238 i != sectorblocks.end(); ++i) {
239 MapBlock *block = *i;
242 Compare block position to camera position, skip
243 if not seen on display
246 if (block->mesh != NULL)
247 block->mesh->updateCameraOffset(m_camera_offset);
249 float range = 100000 * BS;
250 if (m_control.range_all == false)
251 range = m_control.wanted_range * BS;
254 if (!isBlockInSight(block->getPos(), camera_position,
255 camera_direction, camera_fov, range, &d))
258 // This is ugly (spherical distance limit?)
259 /*if(m_control.range_all == false &&
260 d - 0.5*BS*MAP_BLOCKSIZE > range)
266 Ignore if mesh doesn't exist
269 //MutexAutoLock lock(block->mesh_mutex);
271 if (block->mesh == NULL) {
272 blocks_in_range_without_mesh++;
281 // No occlusion culling when free_move is on and camera is
283 bool occlusion_culling_enabled = true;
284 if (g_settings->getBool("free_move")) {
285 MapNode n = getNodeNoEx(cam_pos_nodes);
286 if (n.getContent() == CONTENT_IGNORE ||
287 nodemgr->get(n).solidness == 2)
288 occlusion_culling_enabled = false;
291 v3s16 cpn = block->getPos() * MAP_BLOCKSIZE;
292 cpn += v3s16(MAP_BLOCKSIZE / 2, MAP_BLOCKSIZE / 2, MAP_BLOCKSIZE / 2);
295 float startoff = BS * 1;
296 // The occlusion search of 'isOccluded()' must stop short of the target
297 // point by distance 'endoff' (end offset) to not enter the target mapblock.
298 // For the 8 mapblock corners 'endoff' must therefore be the maximum diagonal
299 // of a mapblock, because we must consider all view angles.
300 // sqrt(1^2 + 1^2 + 1^2) = 1.732
301 float endoff = -BS * MAP_BLOCKSIZE * 1.732050807569;
302 v3s16 spn = cam_pos_nodes;
303 s16 bs2 = MAP_BLOCKSIZE / 2 + 1;
304 // to reduce the likelihood of falsely occluded blocks
305 // require at least two solid blocks
306 // this is a HACK, we should think of a more precise algorithm
307 u32 needed_count = 2;
308 if (occlusion_culling_enabled &&
309 // For the central point of the mapblock 'endoff' can be halved
310 isOccluded(this, spn, cpn,
311 step, stepfac, startoff, endoff / 2.0f, needed_count, nodemgr) &&
312 isOccluded(this, spn, cpn + v3s16(bs2,bs2,bs2),
313 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
314 isOccluded(this, spn, cpn + v3s16(bs2,bs2,-bs2),
315 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
316 isOccluded(this, spn, cpn + v3s16(bs2,-bs2,bs2),
317 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
318 isOccluded(this, spn, cpn + v3s16(bs2,-bs2,-bs2),
319 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
320 isOccluded(this, spn, cpn + v3s16(-bs2,bs2,bs2),
321 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
322 isOccluded(this, spn, cpn + v3s16(-bs2,bs2,-bs2),
323 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
324 isOccluded(this, spn, cpn + v3s16(-bs2,-bs2,bs2),
325 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
326 isOccluded(this, spn, cpn + v3s16(-bs2,-bs2,-bs2),
327 step, stepfac, startoff, endoff, needed_count, nodemgr)) {
328 blocks_occlusion_culled++;
332 // This block is in range. Reset usage timer.
333 block->resetUsageTimer();
335 // Limit block count in case of a sudden increase
336 blocks_would_have_drawn++;
337 if (blocks_drawn >= m_control.wanted_max_blocks &&
338 !m_control.range_all &&
339 d > m_control.wanted_range * BS)
344 m_drawlist[block->getPos()] = block;
346 sector_blocks_drawn++;
348 if (d / BS > farthest_drawn)
349 farthest_drawn = d / BS;
351 } // foreach sectorblocks
353 if (sector_blocks_drawn != 0)
354 m_last_drawn_sectors.insert(sp);
357 m_control.blocks_would_have_drawn = blocks_would_have_drawn;
358 m_control.blocks_drawn = blocks_drawn;
359 m_control.farthest_drawn = farthest_drawn;
361 g_profiler->avg("CM: blocks in range", blocks_in_range);
362 g_profiler->avg("CM: blocks occlusion culled", blocks_occlusion_culled);
363 if (blocks_in_range != 0)
364 g_profiler->avg("CM: blocks in range without mesh (frac)",
365 (float)blocks_in_range_without_mesh / blocks_in_range);
366 g_profiler->avg("CM: blocks drawn", blocks_drawn);
367 g_profiler->avg("CM: farthest drawn", farthest_drawn);
368 g_profiler->avg("CM: wanted max blocks", m_control.wanted_max_blocks);
374 std::vector<scene::IMeshBuffer*> bufs;
377 struct MeshBufListList
379 std::vector<MeshBufList> lists;
386 void add(scene::IMeshBuffer *buf)
388 for(std::vector<MeshBufList>::iterator i = lists.begin();
389 i != lists.end(); ++i){
391 video::SMaterial &m = buf->getMaterial();
393 // comparing a full material is quite expensive so we don't do it if
394 // not even first texture is equal
395 if (l.m.TextureLayer[0].Texture != m.TextureLayer[0].Texture)
399 l.bufs.push_back(buf);
404 l.m = buf->getMaterial();
405 l.bufs.push_back(buf);
410 void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
412 DSTACK(FUNCTION_NAME);
414 bool is_transparent_pass = pass == scene::ESNRP_TRANSPARENT;
417 if (pass == scene::ESNRP_SOLID)
418 prefix = "CM: solid: ";
420 prefix = "CM: transparent: ";
423 This is called two times per frame, reset on the non-transparent one
425 if (pass == scene::ESNRP_SOLID)
426 m_last_drawn_sectors.clear();
429 Get time for measuring timeout.
431 Measuring time is very useful for long delays when the
432 machine is swapping a lot.
437 Get animation parameters
439 float animation_time = m_client->getAnimationTime();
440 int crack = m_client->getCrackLevel();
441 u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
443 v3f camera_position = m_camera_position;
444 v3f camera_direction = m_camera_direction;
445 f32 camera_fov = m_camera_fov;
448 Get all blocks and draw all visible ones
451 v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
454 getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max);
456 u32 vertex_count = 0;
457 u32 meshbuffer_count = 0;
459 // For limiting number of mesh animations per frame
460 u32 mesh_animate_count = 0;
461 u32 mesh_animate_count_far = 0;
463 // Blocks that were drawn and had a mesh
464 u32 blocks_drawn = 0;
465 // Blocks which had a corresponding meshbuffer for this pass
466 u32 blocks_had_pass_meshbuf = 0;
467 // Blocks from which stuff was actually drawn
468 u32 blocks_without_stuff = 0;
471 Draw the selected MapBlocks
475 ScopeProfiler sp(g_profiler, prefix + "drawing blocks", SPT_AVG);
477 MeshBufListList drawbufs;
479 for (std::map<v3s16, MapBlock*>::iterator i = m_drawlist.begin();
480 i != m_drawlist.end(); ++i) {
481 MapBlock *block = i->second;
483 // If the mesh of the block happened to get deleted, ignore it
484 if (block->mesh == NULL)
488 if (!isBlockInSight(block->getPos(), camera_position,
489 camera_direction, camera_fov, 100000 * BS, &d))
494 //MutexAutoLock lock(block->mesh_mutex);
495 MapBlockMesh *mapBlockMesh = block->mesh;
496 assert(mapBlockMesh);
497 // Pretty random but this should work somewhat nicely
498 bool faraway = d >= BS * 50;
499 //bool faraway = d >= m_control.wanted_range * BS;
500 if (mapBlockMesh->isAnimationForced() || !faraway ||
501 mesh_animate_count_far < (m_control.range_all ? 200 : 50)) {
502 bool animated = mapBlockMesh->animate(faraway, animation_time,
503 crack, daynight_ratio);
505 mesh_animate_count++;
506 if (animated && faraway)
507 mesh_animate_count_far++;
509 mapBlockMesh->decreaseAnimationForceTimer();
514 Get the meshbuffers of the block
517 //MutexAutoLock lock(block->mesh_mutex);
519 MapBlockMesh *mapBlockMesh = block->mesh;
520 assert(mapBlockMesh);
522 scene::IMesh *mesh = mapBlockMesh->getMesh();
525 u32 c = mesh->getMeshBufferCount();
526 for (u32 i = 0; i < c; i++)
528 scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
530 buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, m_cache_trilinear_filter);
531 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, m_cache_bilinear_filter);
532 buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, m_cache_anistropic_filter);
533 buf->getMaterial().setFlag(video::EMF_WIREFRAME, m_control.show_wireframe);
535 const video::SMaterial& material = buf->getMaterial();
536 video::IMaterialRenderer* rnd =
537 driver->getMaterialRenderer(material.MaterialType);
538 bool transparent = (rnd && rnd->isTransparent());
539 if (transparent == is_transparent_pass) {
540 if (buf->getVertexCount() == 0)
541 errorstream << "Block [" << analyze_block(block)
542 << "] contains an empty meshbuf" << std::endl;
549 std::vector<MeshBufList> &lists = drawbufs.lists;
551 int timecheck_counter = 0;
552 for (std::vector<MeshBufList>::iterator i = lists.begin();
553 i != lists.end(); ++i) {
555 if (timecheck_counter > 50) {
556 timecheck_counter = 0;
558 if (time2 > time1 + 4) {
559 infostream << "ClientMap::renderMap(): "
560 "Rendering takes ages, returning."
566 MeshBufList &list = *i;
568 driver->setMaterial(list.m);
570 for (std::vector<scene::IMeshBuffer*>::iterator j = list.bufs.begin();
571 j != list.bufs.end(); ++j) {
572 scene::IMeshBuffer *buf = *j;
573 driver->drawMeshBuffer(buf);
574 vertex_count += buf->getVertexCount();
581 // Log only on solid pass because values are the same
582 if (pass == scene::ESNRP_SOLID) {
583 g_profiler->avg("CM: animated meshes", mesh_animate_count);
584 g_profiler->avg("CM: animated meshes (far)", mesh_animate_count_far);
587 g_profiler->avg(prefix + "vertices drawn", vertex_count);
588 if (blocks_had_pass_meshbuf != 0)
589 g_profiler->avg(prefix + "meshbuffers per block",
590 (float)meshbuffer_count / (float)blocks_had_pass_meshbuf);
591 if (blocks_drawn != 0)
592 g_profiler->avg(prefix + "empty blocks (frac)",
593 (float)blocks_without_stuff / blocks_drawn);
595 /*infostream<<"renderMap(): is_transparent_pass="<<is_transparent_pass
596 <<", rendered "<<vertex_count<<" vertices."<<std::endl;*/
599 static bool getVisibleBrightness(Map *map, v3f p0, v3f dir, float step,
600 float step_multiplier, float start_distance, float end_distance,
601 INodeDefManager *ndef, u32 daylight_factor, float sunlight_min_d,
602 int *result, bool *sunlight_seen)
604 int brightness_sum = 0;
605 int brightness_count = 0;
606 float distance = start_distance;
609 pf += dir * distance;
611 bool nonlight_seen = false;
612 bool allow_allowing_non_sunlight_propagates = false;
613 bool allow_non_sunlight_propagates = false;
614 // Check content nearly at camera position
616 v3s16 p = floatToInt(p0 /*+ dir * 3*BS*/, BS);
617 MapNode n = map->getNodeNoEx(p);
618 if(ndef->get(n).param_type == CPT_LIGHT &&
619 !ndef->get(n).sunlight_propagates)
620 allow_allowing_non_sunlight_propagates = true;
622 // If would start at CONTENT_IGNORE, start closer
624 v3s16 p = floatToInt(pf, BS);
625 MapNode n = map->getNodeNoEx(p);
626 if(n.getContent() == CONTENT_IGNORE){
628 pf = p0 + dir * 2*newd;
633 for(int i=0; distance < end_distance; i++){
636 step *= step_multiplier;
638 v3s16 p = floatToInt(pf, BS);
639 MapNode n = map->getNodeNoEx(p);
640 if(allow_allowing_non_sunlight_propagates && i == 0 &&
641 ndef->get(n).param_type == CPT_LIGHT &&
642 !ndef->get(n).sunlight_propagates){
643 allow_non_sunlight_propagates = true;
645 if(ndef->get(n).param_type != CPT_LIGHT ||
646 (!ndef->get(n).sunlight_propagates &&
647 !allow_non_sunlight_propagates)){
648 nonlight_seen = true;
654 if(distance >= sunlight_min_d && *sunlight_seen == false
655 && nonlight_seen == false)
656 if(n.getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN)
657 *sunlight_seen = true;
659 brightness_sum += decode_light(n.getLightBlend(daylight_factor, ndef));
663 if(brightness_count == 0)
665 *result = brightness_sum / brightness_count;
666 /*std::cerr<<"Sampled "<<brightness_count<<" points; result="
667 <<(*result)<<std::endl;*/
671 int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
672 int oldvalue, bool *sunlight_seen_result)
674 const bool debugprint = false;
675 INodeDefManager *ndef = m_gamedef->ndef();
676 static v3f z_directions[50] = {
679 static f32 z_offsets[sizeof(z_directions)/sizeof(*z_directions)] = {
682 if(z_directions[0].X < -99){
683 for(u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++){
684 z_directions[i] = v3f(
685 0.01 * myrand_range(-100, 100),
687 0.01 * myrand_range(-100, 100)
689 z_offsets[i] = 0.01 * myrand_range(0,100);
693 std::cerr<<"In goes "<<PP(m_camera_direction)<<", out comes ";
694 int sunlight_seen_count = 0;
695 float sunlight_min_d = max_d*0.8;
696 if(sunlight_min_d > 35*BS)
697 sunlight_min_d = 35*BS;
698 std::vector<int> values;
699 for(u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++){
700 v3f z_dir = z_directions[i];
702 core::CMatrix4<f32> a;
703 a.buildRotateFromTo(v3f(0,1,0), z_dir);
704 v3f dir = m_camera_direction;
709 step = max_d / 35 * 1.5;
710 float off = step * z_offsets[i];
711 bool sunlight_seen_now = false;
712 bool ok = getVisibleBrightness(this, m_camera_position, dir,
713 step, 1.0, max_d*0.6+off, max_d, ndef, daylight_factor,
715 &br, &sunlight_seen_now);
716 if(sunlight_seen_now)
717 sunlight_seen_count++;
720 values.push_back(br);
721 // Don't try too much if being in the sun is clear
722 if(sunlight_seen_count >= 20)
725 int brightness_sum = 0;
726 int brightness_count = 0;
727 std::sort(values.begin(), values.end());
728 u32 num_values_to_use = values.size();
729 if(num_values_to_use >= 10)
730 num_values_to_use -= num_values_to_use/2;
731 else if(num_values_to_use >= 7)
732 num_values_to_use -= num_values_to_use/3;
733 u32 first_value_i = (values.size() - num_values_to_use) / 2;
735 for(u32 i=0; i < first_value_i; i++)
736 std::cerr<<values[i]<<" ";
739 for(u32 i=first_value_i; i < first_value_i+num_values_to_use; i++){
741 std::cerr<<values[i]<<" ";
742 brightness_sum += values[i];
747 for(u32 i=first_value_i+num_values_to_use; i < values.size(); i++)
748 std::cerr<<values[i]<<" ";
751 if(brightness_count == 0){
752 MapNode n = getNodeNoEx(floatToInt(m_camera_position, BS));
753 if(ndef->get(n).param_type == CPT_LIGHT){
754 ret = decode_light(n.getLightBlend(daylight_factor, ndef));
759 /*float pre = (float)brightness_sum / (float)brightness_count;
765 ret = MYMAX(0, MYMIN(255, preint));*/
766 ret = brightness_sum / brightness_count;
769 std::cerr<<"Result: "<<ret<<" sunlight_seen_count="
770 <<sunlight_seen_count<<std::endl;
771 *sunlight_seen_result = (sunlight_seen_count > 0);
775 void ClientMap::renderPostFx(CameraMode cam_mode)
777 INodeDefManager *nodemgr = m_gamedef->ndef();
779 // Sadly ISceneManager has no "post effects" render pass, in that case we
780 // could just register for that and handle it in renderMap().
782 MapNode n = getNodeNoEx(floatToInt(m_camera_position, BS));
784 // - If the player is in a solid node, make everything black.
785 // - If the player is in liquid, draw a semi-transparent overlay.
786 // - Do not if player is in third person mode
787 const ContentFeatures& features = nodemgr->get(n);
788 video::SColor post_effect_color = features.post_effect_color;
789 if(features.solidness == 2 && !(g_settings->getBool("noclip") &&
790 m_gamedef->checkLocalPrivilege("noclip")) &&
791 cam_mode == CAMERA_MODE_FIRST)
793 post_effect_color = video::SColor(255, 0, 0, 0);
795 if (post_effect_color.getAlpha() != 0)
797 // Draw a full-screen rectangle
798 video::IVideoDriver* driver = SceneManager->getVideoDriver();
799 v2u32 ss = driver->getScreenSize();
800 core::rect<s32> rect(0,0, ss.X, ss.Y);
801 driver->draw2DRectangle(post_effect_color, rect);
805 void ClientMap::PrintInfo(std::ostream &out)