Merge pull request #482 from proller/liquid
[oweals/minetest.git] / src / light.cpp
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #include "light.h"
21
22 #if 1
23 // Middle-raised variation of a_n+1 = a_n * 0.786
24 // Length of LIGHT_MAX+1 means LIGHT_MAX is the last value.
25 // LIGHT_SUN is read as LIGHT_MAX from here.
26 u8 light_decode_table[LIGHT_MAX+1] = 
27 {
28 8,
29 11+2,
30 14+7,
31 18+10,
32 22+15,
33 29+20,
34 37+20,
35 47+15,
36 60+10,
37 76+7,
38 97+5,
39 123+2,
40 157,
41 200,
42 255,
43 };
44 #endif
45
46 #if 0
47 /*
48 Made using this and:
49 - adding 220 as the second last one
50 - replacing the third last one (212) with 195
51
52 #!/usr/bin/python
53
54 from math import *
55 from sys import stdout
56
57 # We want 0 at light=0 and 255 at light=LIGHT_MAX
58 LIGHT_MAX = 14
59 #FACTOR = 0.69
60 #FACTOR = 0.75
61 FACTOR = 0.83
62 START_FROM_ZERO = False
63
64 L = []
65 if START_FROM_ZERO:
66     for i in range(1,LIGHT_MAX+1):
67         L.append(int(round(255.0 * FACTOR ** (i-1))))
68     L.append(0)
69 else:
70     for i in range(1,LIGHT_MAX+1):
71         L.append(int(round(255.0 * FACTOR ** (i-1))))
72     L.append(255)
73
74 L.reverse()
75 for i in L:
76     stdout.write(str(i)+",\n")
77 */
78 u8 light_decode_table[LIGHT_MAX+1] = 
79 {
80 23,
81 27,
82 33,
83 40,
84 48,
85 57,
86 69,
87 83,
88 100,
89 121,
90 146,
91 176,
92 195,
93 220,
94 255,
95 };
96 #endif
97
98 #if 0
99 // This is good
100 // a_n+1 = a_n * 0.786
101 // Length of LIGHT_MAX+1 means LIGHT_MAX is the last value.
102 // LIGHT_SUN is read as LIGHT_MAX from here.
103 u8 light_decode_table[LIGHT_MAX+1] = 
104 {
105 8,
106 11,
107 14,
108 18,
109 22,
110 29,
111 37,
112 47,
113 60,
114 76,
115 97,
116 123,
117 157,
118 200,
119 255,
120 };
121 #endif
122
123 #if 0
124 // Use for debugging in dark
125 u8 light_decode_table[LIGHT_MAX+1] = 
126 {
127 58,
128 64,
129 72,
130 80,
131 88,
132 98,
133 109,
134 121,
135 135,
136 150,
137 167,
138 185,
139 206,
140 229,
141 255,
142 };
143 #endif
144
145 // This is reasonable with classic lighting with a light source
146 /*u8 light_decode_table[LIGHT_MAX+1] = 
147 {
148 2,
149 3,
150 4,
151 6,
152 9,
153 13,
154 18,
155 25,
156 32,
157 35,
158 45,
159 57,
160 69,
161 79,
162 255
163 };*/
164
165
166 // As in minecraft, a_n+1 = a_n * 0.8
167 // NOTE: This doesn't really work that well because this defines
168 //       LIGHT_MAX as dimmer than LIGHT_SUN
169 // NOTE: Uh, this has had 34 left out; forget this.
170 /*u8 light_decode_table[LIGHT_MAX+1] = 
171 {
172 8,
173 11,
174 14,
175 17,
176 21,
177 27,
178 42,
179 53,
180 66,
181 83,
182 104,
183 130,
184 163,
185 204,
186 255,
187 };*/
188
189 // This was a quick try of more light, manually quickly made
190 /*u8 light_decode_table[LIGHT_MAX+1] = 
191 {
192 0,
193 7,
194 11,
195 15,
196 21,
197 29,
198 42,
199 53,
200 69,
201 85,
202 109,
203 135,
204 167,
205 205,
206 255,
207 };*/
208
209 // This was used for a long time, manually made
210 /*u8 light_decode_table[LIGHT_MAX+1] = 
211 {
212 0,
213 6,
214 8,
215 11,
216 14,
217 19,
218 26,
219 34,
220 45,
221 61,
222 81,
223 108,
224 143,
225 191,
226 255,
227 };*/
228
229 /*u8 light_decode_table[LIGHT_MAX+1] = 
230 {
231 0,
232 3,
233 6,
234 10,
235 18,
236 25,
237 35,
238 50,
239 75,
240 95,
241 120,
242 150,
243 185,
244 215,
245 255,
246 };*/
247 /*u8 light_decode_table[LIGHT_MAX+1] = 
248 {
249 0,
250 5,
251 12,
252 22,
253 35,
254 50,
255 65,
256 85,
257 100,
258 120,
259 140,
260 160,
261 185,
262 215,
263 255,
264 };*/
265 // LIGHT_MAX is 14, 0-14 is 15 values
266 /*u8 light_decode_table[LIGHT_MAX+1] = 
267 {
268 0,
269 9,
270 12,
271 14,
272 16,
273 20,
274 26,
275 34,
276 45,
277 61,
278 81,
279 108,
280 143,
281 191,
282 255,
283 };*/
284
285 #if 0
286 /*
287 #!/usr/bin/python
288
289 from math import *
290 from sys import stdout
291
292 # We want 0 at light=0 and 255 at light=LIGHT_MAX
293 LIGHT_MAX = 14
294 #FACTOR = 0.69
295 FACTOR = 0.75
296
297 L = []
298 for i in range(1,LIGHT_MAX+1):
299     L.append(int(round(255.0 * FACTOR ** (i-1))))
300 L.append(0)
301
302 L.reverse()
303 for i in L:
304     stdout.write(str(i)+",\n")
305 */
306 u8 light_decode_table[LIGHT_MAX+1] = 
307 {
308 0,
309 6,
310 8,
311 11,
312 14,
313 19,
314 26,
315 34,
316 45,
317 61,
318 81,
319 108,
320 143,
321 191,
322 255,
323 };
324 #endif
325
326