From: Perttu Ahola Date: Sun, 24 Apr 2011 18:15:50 +0000 (+0300) Subject: Optimized smooth lighting calculation code X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=2704bdc68e51c39f5ea475ba092c2d21281ccd53;p=zefram%2Fminetest%2Fminetest_engine.git Optimized smooth lighting calculation code --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bd5e776..d5b8028f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ project(minetest) set(VERSION_MAJOR 0) set(VERSION_MINOR 2) -set(VERSION_PATCH 20110424_0) +set(VERSION_PATCH 20110424_1_dev) set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") # Configuration options diff --git a/doc/changelog.txt b/doc/changelog.txt index 574ea60b..71cbd970 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -3,6 +3,9 @@ Minetest-c55 changelog This should contain all the major changes. For minor stuff, refer to the commit log of the repository. +X: +- Optimized smooth lighting + 2011-04-24: - Smooth lighting with simple ambient occlusion - Updated main menu diff --git a/src/game.cpp b/src/game.cpp index 7eb847e6..9054f00c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1229,6 +1229,17 @@ void the_game( s32 dx = input->getMousePos().X - displaycenter.X; s32 dy = input->getMousePos().Y - displaycenter.Y; //std::cout<<"window active, pos difference "<isKeyDown(irr::KEY_UP)) + dy -= dtime * keyspeed; + if(input->isKeyDown(irr::KEY_DOWN)) + dy += dtime * keyspeed; + if(input->isKeyDown(irr::KEY_LEFT)) + dx -= dtime * keyspeed; + if(input->isKeyDown(irr::KEY_RIGHT)) + dx += dtime * keyspeed; + camera_yaw -= dx*0.2; camera_pitch += dy*0.2; if(camera_pitch < -89.5) camera_pitch = -89.5; diff --git a/src/main.cpp b/src/main.cpp index 3bc4de77..51a40782 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -167,6 +167,10 @@ TODO: Better control of draw_control.wanted_max_blocks TODO: Get player texture (and some others) from the specified texture directory +SUGG: Simple light color information to air + +TODO: Block mesh generator to tile properly on smooth lighting + Configuration: -------------- @@ -189,6 +193,8 @@ TODO: Don't update all meshes always on single node changes, but - Tool/weapon visualization +FIXME: When disconnected to the menu, memory is not freed properly + Server: ------- diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 284c6430..c89cf46d 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -223,45 +223,6 @@ void makeFastFace(TileSpec tile, u8 li0, u8 li1, u8 li2, u8 li3, v3f p, ); } - /*v3f vertex_pos[4]; - // If looking towards z+, this is the face that is behind - // the center point, facing towards z+. - vertex_pos[0] = v3f(-BS/2,-BS/2,BS/2); - vertex_pos[1] = v3f( BS/2,-BS/2,BS/2); - vertex_pos[2] = v3f( BS/2, BS/2,BS/2); - vertex_pos[3] = v3f(-BS/2, BS/2,BS/2); - - if(dir == v3s16(0,0,1)) - { - for(u16 i=0; i<4; i++) - vertex_pos[i].rotateXZBy(0); - } - else if(dir == v3s16(0,0,-1)) - { - for(u16 i=0; i<4; i++) - vertex_pos[i].rotateXZBy(180); - } - else if(dir == v3s16(1,0,0)) - { - for(u16 i=0; i<4; i++) - vertex_pos[i].rotateXZBy(-90); - } - else if(dir == v3s16(-1,0,0)) - { - for(u16 i=0; i<4; i++) - vertex_pos[i].rotateXZBy(90); - } - else if(dir == v3s16(0,1,0)) - { - for(u16 i=0; i<4; i++) - vertex_pos[i].rotateYZBy(-90); - } - else if(dir == v3s16(0,-1,0)) - { - for(u16 i=0; i<4; i++) - vertex_pos[i].rotateYZBy(90); - }*/ - for(u16 i=0; i<4; i++) { vertex_pos[i].X *= scale.X; @@ -472,6 +433,73 @@ u8 getSmoothLight(v3s16 p, v3s16 corner, return getSmoothLight(p, vmanip, daynight_ratio); } +void getTileInfo( + // Input: + v3s16 blockpos_nodes, + v3s16 p, + v3s16 face_dir, + u32 daynight_ratio, + VoxelManipulator &vmanip, + NodeModMap &temp_mods, + bool smooth_lighting, + // Output: + bool &makes_face, + v3s16 &p_corrected, + v3s16 &face_dir_corrected, + u8 *lights, + TileSpec &tile + ) +{ + MapNode n0 = vmanip.getNodeNoEx(blockpos_nodes + p); + MapNode n1 = vmanip.getNodeNoEx(blockpos_nodes + p + face_dir); + TileSpec tile0 = getNodeTile(n0, p, face_dir, temp_mods); + TileSpec tile1 = getNodeTile(n1, p + face_dir, -face_dir, temp_mods); + + // This is hackish + u8 content0 = getNodeContent(p, n0, temp_mods); + u8 content1 = getNodeContent(p + face_dir, n1, temp_mods); + u8 mf = face_contents(content0, content1); + + if(mf == 0) + { + makes_face = false; + return; + } + + makes_face = true; + + if(mf == 1) + { + tile = tile0; + p_corrected = p; + face_dir_corrected = face_dir; + } + else + { + tile = tile1; + p_corrected = p + face_dir; + face_dir_corrected = -face_dir; + } + + if(smooth_lighting == false) + { + lights[0] = lights[1] = lights[2] = lights[3] = + decode_light(getFaceLight(daynight_ratio, n0, n1, face_dir)); + } + else + { + v3s16 vertex_dirs[4]; + getNodeVertexDirs(face_dir_corrected, vertex_dirs); + for(u16 i=0; i<4; i++) + { + lights[i] = getSmoothLight(blockpos_nodes + p_corrected, + vertex_dirs[i], vmanip, daynight_ratio); + } + } + + return; +} + /* startpos: translate_dir: unit vector with only one of x, y or z @@ -496,11 +524,14 @@ void updateFastFaceRow( u16 continuous_tiles_count = 0; - MapNode n0 = vmanip.getNodeNoEx(blockpos_nodes + p); - MapNode n1 = vmanip.getNodeNoEx(blockpos_nodes + p + face_dir); - TileSpec tile0 = getNodeTile(n0, p, face_dir, temp_mods); - TileSpec tile1 = getNodeTile(n1, p + face_dir, -face_dir, temp_mods); - u8 light = getFaceLight(daynight_ratio, n0, n1, face_dir); + bool makes_face; + v3s16 p_corrected; + v3s16 face_dir_corrected; + u8 lights[4]; + TileSpec tile; + getTileInfo(blockpos_nodes, p, face_dir, daynight_ratio, + vmanip, temp_mods, smooth_lighting, + makes_face, p_corrected, face_dir_corrected, lights, tile); for(u16 j=0; j