textures.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. -- Node texture tests
  2. local S = minetest.get_translator("testnodes")
  3. minetest.register_node("testnodes:6sides", {
  4. description = S("Six Textures Test Node"),
  5. tiles = {
  6. "testnodes_normal1.png",
  7. "testnodes_normal2.png",
  8. "testnodes_normal3.png",
  9. "testnodes_normal4.png",
  10. "testnodes_normal5.png",
  11. "testnodes_normal6.png",
  12. },
  13. groups = { dig_immediate = 2 },
  14. })
  15. minetest.register_node("testnodes:anim", {
  16. description = S("Animated Test Node"),
  17. tiles = {
  18. { name = "testnodes_anim.png",
  19. animation = {
  20. type = "vertical_frames",
  21. aspect_w = 16,
  22. aspect_h = 16,
  23. length = 4.0,
  24. }, },
  25. },
  26. groups = { dig_immediate = 2 },
  27. })
  28. -- Node texture transparency test
  29. local alphas = { 64, 128, 191 }
  30. for a=1,#alphas do
  31. local alpha = alphas[a]
  32. -- Transparency taken from texture
  33. minetest.register_node("testnodes:alpha_texture_"..alpha, {
  34. description = S("Texture Alpha Test Node (@1)", alpha),
  35. drawtype = "glasslike",
  36. paramtype = "light",
  37. tiles = {
  38. "testnodes_alpha"..alpha..".png",
  39. },
  40. use_texture_alpha = "blend",
  41. groups = { dig_immediate = 3 },
  42. })
  43. -- Transparency set via texture modifier
  44. minetest.register_node("testnodes:alpha_"..alpha, {
  45. description = S("Alpha Test Node (@1)", alpha),
  46. drawtype = "glasslike",
  47. paramtype = "light",
  48. tiles = {
  49. "testnodes_alpha.png^[opacity:" .. alpha,
  50. },
  51. use_texture_alpha = "blend",
  52. groups = { dig_immediate = 3 },
  53. })
  54. end
  55. -- Generate PNG textures
  56. local function mandelbrot(w, h, iterations)
  57. local r = {}
  58. for y=0, h-1 do
  59. for x=0, w-1 do
  60. local re = (x - w/2) * 4/w
  61. local im = (y - h/2) * 4/h
  62. -- zoom in on a nice view
  63. re = re / 128 - 0.23
  64. im = im / 128 - 0.82
  65. local px, py = 0, 0
  66. local i = 0
  67. while px*px + py*py <= 4 and i < iterations do
  68. px, py = px*px - py*py + re, 2 * px * py + im
  69. i = i + 1
  70. end
  71. r[w*y+x+1] = i / iterations
  72. end
  73. end
  74. return r
  75. end
  76. local function gen_checkers(w, h, tile)
  77. local r = {}
  78. for y=0, h-1 do
  79. for x=0, w-1 do
  80. local hori = math.floor(x / tile) % 2 == 0
  81. local vert = math.floor(y / tile) % 2 == 0
  82. r[w*y+x+1] = hori ~= vert and 1 or 0
  83. end
  84. end
  85. return r
  86. end
  87. local fractal = mandelbrot(512, 512, 128)
  88. local frac_emb = mandelbrot(64, 64, 64)
  89. local checker = gen_checkers(512, 512, 32)
  90. local floor = math.floor
  91. local abs = math.abs
  92. local data_emb = {}
  93. local data_mb = {}
  94. local data_ck = {}
  95. for i=1, #frac_emb do
  96. data_emb[i] = {
  97. r = floor(abs(frac_emb[i] * 2 - 1) * 255),
  98. g = floor(abs(1 - frac_emb[i]) * 255),
  99. b = floor(frac_emb[i] * 255),
  100. a = frac_emb[i] < 0.95 and 255 or 0,
  101. }
  102. end
  103. for i=1, #fractal do
  104. data_mb[i] = {
  105. r = floor(fractal[i] * 255),
  106. g = floor(abs(fractal[i] * 2 - 1) * 255),
  107. b = floor(abs(1 - fractal[i]) * 255),
  108. a = 255,
  109. }
  110. data_ck[i] = checker[i] > 0 and "#F80" or "#000"
  111. end
  112. local textures_path = minetest.get_modpath( minetest.get_current_modname() ) .. "/textures/"
  113. minetest.safe_file_write(
  114. textures_path .. "testnodes_generated_mb.png",
  115. minetest.encode_png(512,512,data_mb)
  116. )
  117. minetest.safe_file_write(
  118. textures_path .. "testnodes_generated_ck.png",
  119. minetest.encode_png(512,512,data_ck)
  120. )
  121. minetest.register_node("testnodes:generated_png_mb", {
  122. description = S("Generated Mandelbrot PNG Test Node"),
  123. tiles = { "testnodes_generated_mb.png" },
  124. groups = { dig_immediate = 2 },
  125. })
  126. minetest.register_node("testnodes:generated_png_ck", {
  127. description = S("Generated Checker PNG Test Node"),
  128. tiles = { "testnodes_generated_ck.png" },
  129. groups = { dig_immediate = 2 },
  130. })
  131. local png_emb = "[png:" .. minetest.encode_base64(minetest.encode_png(64,64,data_emb))
  132. minetest.register_node("testnodes:generated_png_emb", {
  133. description = S("Generated In-Band Mandelbrot PNG Test Node"),
  134. tiles = { png_emb },
  135. groups = { dig_immediate = 2 },
  136. })
  137. minetest.register_node("testnodes:generated_png_src_emb", {
  138. description = S("Generated In-Band Source Blit Mandelbrot PNG Test Node"),
  139. tiles = { png_emb .. "^testnodes_damage_neg.png" },
  140. groups = { dig_immediate = 2 },
  141. })
  142. minetest.register_node("testnodes:generated_png_dst_emb", {
  143. description = S("Generated In-Band Dest Blit Mandelbrot PNG Test Node"),
  144. tiles = { "testnodes_generated_ck.png^" .. png_emb },
  145. groups = { dig_immediate = 2 },
  146. })
  147. --[[
  148. The following nodes can be used to demonstrate the TGA format support.
  149. Minetest supports TGA types 1, 2, 3 & 10. While adding the support for
  150. TGA type 9 (RLE-compressed, color-mapped) is easy, it is not advisable
  151. to do so, as it is not backwards compatible with any Minetest pre-5.5;
  152. content creators should therefore either use TGA type 1 or 10, or PNG.
  153. TODO: Types 1, 2 & 10 should have two test nodes each (i.e. bottom-top
  154. and top-bottom) for 16bpp (A1R5G5B5), 24bpp (B8G8R8), 32bpp (B8G8R8A8)
  155. colors.
  156. Note: Minetest requires the optional TGA footer for a texture to load.
  157. If a TGA image does not load in Minetest, append eight (8) null bytes,
  158. then the string “TRUEVISION-XFILE.”, then another null byte.
  159. ]]--
  160. minetest.register_node("testnodes:tga_type1_24bpp_bt", {
  161. description = S("TGA Type 1 (color-mapped RGB) 24bpp bottom-top Test Node"),
  162. drawtype = "glasslike",
  163. paramtype = "light",
  164. sunlight_propagates = true,
  165. tiles = { "testnodes_tga_type1_24bpp_bt.tga" },
  166. groups = { dig_immediate = 2 },
  167. })
  168. minetest.register_node("testnodes:tga_type1_24bpp_tb", {
  169. description = S("TGA Type 1 (color-mapped RGB) 24bpp top-bottom Test Node"),
  170. drawtype = "glasslike",
  171. paramtype = "light",
  172. sunlight_propagates = true,
  173. tiles = { "testnodes_tga_type1_24bpp_tb.tga" },
  174. groups = { dig_immediate = 2 },
  175. })
  176. minetest.register_node("testnodes:tga_type2_16bpp_bt", {
  177. description = S("TGA Type 2 (uncompressed RGB) 16bpp bottom-top Test Node"),
  178. drawtype = "glasslike",
  179. paramtype = "light",
  180. sunlight_propagates = true,
  181. tiles = { "testnodes_tga_type2_16bpp_bt.tga" },
  182. use_texture_alpha = "clip",
  183. groups = { dig_immediate = 2 },
  184. })
  185. minetest.register_node("testnodes:tga_type2_16bpp_tb", {
  186. description = S("TGA Type 2 (uncompressed RGB) 16bpp top-bottom Test Node"),
  187. drawtype = "glasslike",
  188. paramtype = "light",
  189. sunlight_propagates = true,
  190. tiles = { "testnodes_tga_type2_16bpp_tb.tga" },
  191. use_texture_alpha = "clip",
  192. groups = { dig_immediate = 2 },
  193. })
  194. minetest.register_node("testnodes:tga_type2_32bpp_bt", {
  195. description = S("TGA Type 2 (uncompressed RGB) 32bpp bottom-top Test Node"),
  196. drawtype = "glasslike",
  197. paramtype = "light",
  198. sunlight_propagates = true,
  199. tiles = { "testnodes_tga_type2_32bpp_bt.tga" },
  200. use_texture_alpha = "blend",
  201. groups = { dig_immediate = 2 },
  202. })
  203. minetest.register_node("testnodes:tga_type2_32bpp_tb", {
  204. description = S("TGA Type 2 (uncompressed RGB) 32bpp top-bottom Test Node"),
  205. drawtype = "glasslike",
  206. paramtype = "light",
  207. sunlight_propagates = true,
  208. tiles = { "testnodes_tga_type2_32bpp_tb.tga" },
  209. use_texture_alpha = "blend",
  210. groups = { dig_immediate = 2 },
  211. })
  212. minetest.register_node("testnodes:tga_type3_16bpp_bt", {
  213. description = S("TGA Type 3 (uncompressed grayscale) 16bpp bottom-top Test Node"),
  214. drawtype = "glasslike",
  215. paramtype = "light",
  216. sunlight_propagates = true,
  217. tiles = { "testnodes_tga_type3_16bpp_bt.tga" },
  218. use_texture_alpha = "blend",
  219. groups = { dig_immediate = 2 },
  220. })
  221. minetest.register_node("testnodes:tga_type3_16bpp_tb", {
  222. description = S("TGA Type 3 (uncompressed grayscale) 16bpp top-bottom Test Node"),
  223. drawtype = "glasslike",
  224. paramtype = "light",
  225. sunlight_propagates = true,
  226. tiles = { "testnodes_tga_type3_16bpp_tb.tga" },
  227. use_texture_alpha = "blend",
  228. groups = { dig_immediate = 2 },
  229. })
  230. minetest.register_node("testnodes:tga_type10_32bpp_bt", {
  231. description = S("TGA Type 10 (RLE-compressed RGB) 32bpp bottom-top Test Node"),
  232. tiles = { "testnodes_tga_type10_32bpp_bt.tga" },
  233. drawtype = "glasslike",
  234. paramtype = "light",
  235. sunlight_propagates = true,
  236. use_texture_alpha = "blend",
  237. groups = { dig_immediate = 2 },
  238. })
  239. minetest.register_node("testnodes:tga_type10_32bpp_tb", {
  240. description = S("TGA Type 10 (RLE-compressed RGB) 32bpp top-bottom Test Node"),
  241. drawtype = "glasslike",
  242. paramtype = "light",
  243. sunlight_propagates = true,
  244. tiles = { "testnodes_tga_type10_32bpp_tb.tga" },
  245. use_texture_alpha = "blend",
  246. groups = { dig_immediate = 2 },
  247. })