3 Copyright (C) 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.
22 #include "util/numeric.h"
26 // Length of LIGHT_MAX+1 means LIGHT_MAX is the last value.
27 // LIGHT_SUN is read as LIGHT_MAX from here.
29 u8 light_LUT[LIGHT_MAX+1] =
31 /* Middle-raised variation of a_n+1 = a_n * 0.786
32 * Length of LIGHT_MAX+1 means LIGHT_MAX is the last value.
33 * LIGHT_SUN is read as LIGHT_MAX from here.
52 const u8 *light_decode_table = light_LUT;
54 /** Initialize or update the light value tables using the specified \p gamma.
55 * If \p gamma == 1.0 then the light table is linear. Typically values for
56 * gamma range between 1.8 and 2.2.
58 * @note The value for gamma will be restricted to the range 1.1 <= gamma <= 3.0.
60 * @note This function is not, currently, a simple linear to gamma encoding
61 * because adjustments are made so that a gamma of 1.8 gives the same
62 * results as those hardcoded for use by the server.
64 void set_light_table(float gamma)
66 static const float brightness_step = 255.0f / (LIGHT_MAX + 1);
68 /* These are adjustment values that are added to the calculated light value
69 * after gamma is applied. Currently they are used so that given a gamma
70 * of 1.8 the light values set by this function are the same as those
71 * hardcoded in the initalizer list for the declaration of light_LUT.
73 static const int adjustments[LIGHT_MAX + 1] = {
91 gamma = rangelim(gamma, 1.0, 3.0);
93 float brightness = brightness_step;
95 for (size_t i = 0; i < LIGHT_MAX; i++) {
96 light_LUT[i] = (u8)(255 * powf(brightness / 255.0f, gamma));
97 light_LUT[i] = rangelim(light_LUT[i] + adjustments[i], 0, 255);
98 if (i > 1 && light_LUT[i] < light_LUT[i-1])
99 light_LUT[i] = light_LUT[i-1] + 1;
100 brightness += brightness_step;
102 light_LUT[LIGHT_MAX] = 255;
111 - adding 220 as the second last one
112 - replacing the third last one (212) with 195
117 from sys import stdout
119 # We want 0 at light=0 and 255 at light=LIGHT_MAX
124 START_FROM_ZERO = False
128 for i in range(1,LIGHT_MAX+1):
129 L.append(int(round(255.0 * FACTOR ** (i-1))))
132 for i in range(1,LIGHT_MAX+1):
133 L.append(int(round(255.0 * FACTOR ** (i-1))))
138 stdout.write(str(i)+",\n")
140 u8 light_decode_table[LIGHT_MAX+1] =
162 // a_n+1 = a_n * 0.786
163 // Length of LIGHT_MAX+1 means LIGHT_MAX is the last value.
164 // LIGHT_SUN is read as LIGHT_MAX from here.
165 u8 light_decode_table[LIGHT_MAX+1] =
186 // Use for debugging in dark
187 u8 light_decode_table[LIGHT_MAX+1] =
207 // This is reasonable with classic lighting with a light source
208 /*u8 light_decode_table[LIGHT_MAX+1] =
228 // As in minecraft, a_n+1 = a_n * 0.8
229 // NOTE: This doesn't really work that well because this defines
230 // LIGHT_MAX as dimmer than LIGHT_SUN
231 // NOTE: Uh, this has had 34 left out; forget this.
232 /*u8 light_decode_table[LIGHT_MAX+1] =
251 // This was a quick try of more light, manually quickly made
252 /*u8 light_decode_table[LIGHT_MAX+1] =
271 // This was used for a long time, manually made
272 /*u8 light_decode_table[LIGHT_MAX+1] =
291 /*u8 light_decode_table[LIGHT_MAX+1] =
309 /*u8 light_decode_table[LIGHT_MAX+1] =
327 // LIGHT_MAX is 14, 0-14 is 15 values
328 /*u8 light_decode_table[LIGHT_MAX+1] =
352 from sys import stdout
354 # We want 0 at light=0 and 255 at light=LIGHT_MAX
360 for i in range(1,LIGHT_MAX+1):
361 L.append(int(round(255.0 * FACTOR ** (i-1))))
366 stdout.write(str(i)+",\n")
368 u8 light_decode_table[LIGHT_MAX+1] =