@@ -144,6 +144,8 @@ static u16 getSmoothLightCombined(const v3s16 &p,
144144{
145145 const NodeDefManager *ndef = data->m_nodedef ;
146146
147+ assert (data->m_smooth_lighting );
148+
147149 u16 ambient_occlusion = 0 ;
148150 u16 light_count = 0 ;
149151 u8 light_source_max = 0 ;
@@ -160,12 +162,12 @@ static u16 getSmoothLightCombined(const v3s16 &p,
160162 if (n.getContent () == CONTENT_IGNORE)
161163 return true ;
162164 const ContentFeatures &f = ndef->get (n);
163- if (f.light_source > light_source_max)
164- light_source_max = f.light_source ;
165+ light_source_max = std::max (light_source_max, f.light_source );
165166 // Check f.solidness because fast-style leaves look better this way
166167 if (f.param_type == CPT_LIGHT && f.visuals ->solidness != 2 ) {
167- u8 light_level_day = n.getLight (LIGHTBANK_DAY, f.getLightingFlags ());
168- u8 light_level_night = n.getLight (LIGHTBANK_NIGHT, f.getLightingFlags ());
168+ const auto lf = f.getLightingFlags ();
169+ u8 light_level_day = n.getLight (LIGHTBANK_DAY, lf);
170+ u8 light_level_night = n.getLight (LIGHTBANK_NIGHT, lf);
169171 if (light_level_day == LIGHT_SUN)
170172 direct_sunlight = true ;
171173 light_day += decode_light (light_level_day);
@@ -219,25 +221,20 @@ static u16 getSmoothLightCombined(const v3s16 &p,
219221 }
220222
221223 if (ambient_occlusion > 4 ) {
222- static thread_local const float ao_gamma = rangelim (
223- g_settings->getFloat (" ambient_occlusion_gamma" ), 0.25 , 4.0 );
224-
225- // Table of gamma space multiply factors.
226- static thread_local const float light_amount[3 ] = {
227- powf (0.75 , 1.0 / ao_gamma),
228- powf (0.5 , 1.0 / ao_gamma),
229- powf (0.25 , 1.0 / ao_gamma)
230- };
231-
232- // calculate table index for gamma space multiplier
233- ambient_occlusion -= 5 ;
224+ float light_amount; // gamma space multiplier
225+ if (ambient_occlusion == 5 )
226+ light_amount = std::pow (0 .75f , data->m_ao_gamma_inv );
227+ else if (ambient_occlusion == 6 )
228+ light_amount = std::pow (0 .75f , data->m_ao_gamma_inv );
229+ else // >= 7
230+ light_amount = std::pow (0 .25f , data->m_ao_gamma_inv );
234231
235232 if (!skip_ambient_occlusion_day)
236233 light_day = rangelim (core::round32 (
237- light_day * light_amount[ambient_occlusion] ), 0 , 255 );
234+ light_day * light_amount), 0 , 255 );
238235 if (!skip_ambient_occlusion_night)
239236 light_night = rangelim (core::round32 (
240- light_night * light_amount[ambient_occlusion] ), 0 , 255 );
237+ light_night * light_amount), 0 , 255 );
241238 }
242239
243240 return light_day | (light_night << 8 );
0 commit comments