light.cpp 3.8 KB

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