From d9df592da824629149bf744726beba33f604dc2d Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Thu, 21 Aug 2014 23:28:01 +0200 Subject: Pass light sources in blue channel of vertex color instead of decoded light for all special drawtypes. Plus some style fixes and optimizations. --- src/mapblock_mesh.cpp | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) (limited to 'src/mapblock_mesh.cpp') diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp index ad0fcb436..d3f7c2f39 100644 --- a/src/mapblock_mesh.cpp +++ b/src/mapblock_mesh.cpp @@ -193,10 +193,7 @@ static u8 getFaceLight(enum LightBank bank, MapNode n, MapNode n2, // Boost light level for light sources u8 light_source = MYMAX(ndef->get(n).light_source, ndef->get(n2).light_source); - //if(light_source >= light) - //return decode_light(undiminish_light(light_source)); if(light_source > light) - //return decode_light(light_source); light = light_source; return decode_light(light); @@ -272,16 +269,12 @@ static u8 getSmoothLight(enum LightBank bank, v3s16 p, MeshMakeData *data) if(ambient_occlusion > 4) { - //ambient_occlusion -= 4; - //light = (float)light / ((float)ambient_occlusion * 0.5 + 1.0); - float light_amount = (8 - ambient_occlusion) / 4.0; - float light_f = (float)light / 255.0; - light_f = pow(light_f, 2.2f); // gamma -> linear space - light_f = light_f * light_amount; - light_f = pow(light_f, 1.0f/2.2f); // linear -> gamma space - if(light_f > 1.0) - light_f = 1.0; - light = 255.0 * light_f + 0.5; + //calculate table index for gamma space multiplier + ambient_occlusion -= 5; + //table of precalculated gamma space multiply factors + //light^2.2 * factor (0.75, 0.5, 0.25, 0.0), so table holds factor ^ (1 / 2.2) + const float light_amount[4] = {0.877424315, 0.729740053, 0.532520545, 0.0}; + light = core::clamp(core::round32(light*light_amount[ambient_occlusion]), 0, 255); } return light; @@ -914,21 +907,18 @@ static void updateFastFaceRow( // Floating point conversion of the position vector v3f pf(p_corrected.X, p_corrected.Y, p_corrected.Z); // Center point of face (kind of) - v3f sp = pf - ((f32)continuous_tiles_count / 2. - 0.5) * translate_dir_f; + v3f sp = pf - ((f32)continuous_tiles_count / 2.0 - 0.5) * translate_dir_f; if(continuous_tiles_count != 1) sp += translate_dir_f; v3f scale(1,1,1); - if(translate_dir.X != 0) - { + if(translate_dir.X != 0) { scale.X = continuous_tiles_count; } - if(translate_dir.Y != 0) - { + if(translate_dir.Y != 0) { scale.Y = continuous_tiles_count; } - if(translate_dir.Z != 0) - { + if(translate_dir.Z != 0) { scale.Z = continuous_tiles_count; } @@ -937,7 +927,7 @@ static void updateFastFaceRow( dest); g_profiler->avg("Meshgen: faces drawn by tiling", 0); - for(int i=1; iavg("Meshgen: faces drawn by tiling", 1); } } @@ -965,8 +955,8 @@ static void updateAllFastFaceRows(MeshMakeData *data, /* Go through every y,z and get top(y+) faces in rows of x+ */ - for(s16 y=0; y