aboutsummaryrefslogtreecommitdiff
path: root/games/devtest/mods/testnodes/textures.lua
blob: 2faacdd78be85cbf3a76f528e2a4c9214f5f48a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
-- Node texture tests

local S = minetest.get_translator("testnodes")

minetest.register_node("testnodes:6sides", {
	description = S("Six Textures Test Node"),
	tiles = {
		"testnodes_normal1.png",
		"testnodes_normal2.png",
		"testnodes_normal3.png",
		"testnodes_normal4.png",
		"testnodes_normal5.png",
		"testnodes_normal6.png",
	},

	groups = { dig_immediate = 2 },
})

minetest.register_node("testnodes:anim", {
	description = S("Animated Test Node"),
	tiles = {
		{ name = "testnodes_anim.png",
		animation = {
			type = "vertical_frames",
			aspect_w = 16,
			aspect_h = 16,
			length = 4.0,
		}, },
	},

	groups = { dig_immediate = 2 },
})

-- Node texture transparency test

local alphas = { 64, 128, 191 }

for a=1,#alphas do
	local alpha = alphas[a]

	-- Transparency taken from texture
	minetest.register_node("testnodes:alpha_texture_"..alpha, {
		description = S("Texture Alpha Test Node (@1)", alpha),
		drawtype = "glasslike",
		paramtype = "light",
		tiles = {
			"testnodes_alpha"..alpha..".png",
		},
		use_texture_alpha = "blend",

		groups = { dig_immediate = 3 },
	})

	-- Transparency set via texture modifier
	minetest.register_node("testnodes:alpha_"..alpha, {
		description = S("Alpha Test Node (@1)", alpha),
		drawtype = "glasslike",
		paramtype = "light",
		tiles = {
			"testnodes_alpha.png^[opacity:" .. alpha,
		},
		use_texture_alpha = "blend",

		groups = { dig_immediate = 3 },
	})
end

-- Generate PNG textures

local function mandelbrot(w, h, iterations)
	local r = {}
	for y=0, h-1 do
		for x=0, w-1 do
			local re = (x - w/2) * 4/w
			local im = (y - h/2) * 4/h
			-- zoom in on a nice view
			re = re / 128 - 0.23
			im = im / 128 - 0.82

			local px, py = 0, 0
			local i = 0
			while px*px + py*py <= 4 and i < iterations do
				px, py = px*px - py*py + re, 2 * px * py + im
				i = i + 1
			end
			r[w*y+x+1] = i / iterations
		end
	end
	return r
end

local function gen_checkers(w, h, tile)
	local r = {}
	for y=0, h-1 do
		for x=0, w-1 do
			local hori = math.floor(x / tile) % 2 == 0
			local vert = math.floor(y / tile) % 2 == 0
			r[w*y+x+1] = hori ~= vert and 1 or 0
		end
	end
	return r
end

local fractal = mandelbrot(512, 512, 128)
local frac_emb = mandelbrot(64, 64, 64)
local checker = gen_checkers(512, 512, 32)

local floor = math.floor
local abs = math.abs
local data_emb = {}
local data_mb = {}
local data_ck = {}
for i=1, #frac_emb do
	data_emb[i] = {
		r = floor(abs(frac_emb[i] * 2 - 1) * 255),
		g = floor(abs(1 - frac_emb[i]) * 255),
		b = floor(frac_emb[i] * 255),
		a = frac_emb[i] < 0.95 and 255 or 0,
	}
end
for i=1, #fractal do
	data_mb[i] = {
		r = floor(fractal[i] * 255),
		g = floor(abs(fractal[i] * 2 - 1) * 255),
		b = floor(abs(1 - fractal[i]) * 255),
		a = 255,
	}
	data_ck[i] = checker[i] > 0 and "#F80" or "#000"
end

local textures_path = minetest.get_modpath( minetest.get_current_modname() ) .. "/textures/"
minetest.safe_file_write(
	textures_path .. "testnodes_generated_mb.png",
	minetest.encode_png(512,512,data_mb)
)
minetest.safe_file_write(
	textures_path .. "testnodes_generated_ck.png",
	minetest.encode_png(512,512,data_ck)
)

minetest.register_node("testnodes:generated_png_mb", {
	description = S("Generated Mandelbrot PNG Test Node"),
	tiles = { "testnodes_generated_mb.png" },

	groups = { dig_immediate = 2 },
})
minetest.register_node("testnodes:generated_png_ck", {
	description = S("Generated Checker PNG Test Node"),
	tiles = { "testnodes_generated_ck.png" },

	groups = { dig_immediate = 2 },
})

local png_emb = "[png:" .. minetest.encode_base64(minetest.encode_png(64,64,data_emb))

minetest.register_node("testnodes:generated_png_emb", {
	description = S("Generated In-Band Mandelbrot PNG Test Node"),
	tiles = { png_emb },

	groups = { dig_immediate = 2 },
})
minetest.register_node("testnodes:generated_png_src_emb", {
	description = S("Generated In-Band Source Blit Mandelbrot PNG Test Node"),
	tiles = { png_emb .. "^testnodes_damage_neg.png" },

	groups = { dig_immediate = 2 },
})
minetest.register_node("testnodes:generated_png_dst_emb", {
	description = S("Generated In-Band Dest Blit Mandelbrot PNG Test Node"),
	tiles = { "testnodes_generated_ck.png^" .. png_emb },

	groups = { dig_immediate = 2 },
})

--[[

The following nodes can be used to demonstrate the TGA format support.

Minetest supports TGA types 1, 2, 3 & 10. While adding the support for
TGA type 9 (RLE-compressed, color-mapped) is easy, it is not advisable
to do so, as it is not backwards compatible with any Minetest pre-5.5;
content creators should therefore either use TGA type 1 or 10, or PNG.

TODO: Types 1, 2 & 10 should have two test nodes each (i.e. bottom-top
and top-bottom) for 16bpp (A1R5G5B5), 24bpp (B8G8R8), 32bpp (B8G8R8A8)
colors.

Note: Minetest requires the optional TGA footer for a texture to load.
If a TGA image does not load in Minetest, append eight (8) null bytes,
then the string “TRUEVISION-XFILE.”, then another null byte.

]]--

minetest.register_node("testnodes:tga_type1_24bpp_bt", {
	description = S("TGA Type 1 (color-mapped RGB) 24bpp bottom-top Test Node"),
	drawtype = "glasslike",
	paramtype = "light",
	sunlight_propagates = true,
	tiles = { "testnodes_tga_type1_24bpp_bt.tga" },
	groups = { dig_immediate = 2 },
})

minetest.register_node("testnodes:tga_type1_24bpp_tb", {
	description = S("TGA Type 1 (color-mapped RGB) 24bpp top-bottom Test Node"),
	drawtype = "glasslike",
	paramtype = "light",
	sunlight_propagates = true,
	tiles = { "testnodes_tga_type1_24bpp_tb.tga" },
	groups = { dig_immediate = 2 },
})

minetest.register_node("testnodes:tga_type2_16bpp_bt", {
	description = S("TGA Type 2 (uncompressed RGB) 16bpp bottom-top Test Node"),
	drawtype = "glasslike",
	paramtype = "light",
	sunlight_propagates = true,
	tiles = { "testnodes_tga_type2_16bpp_bt.tga" },
	use_texture_alpha = "clip",
	groups = { dig_immediate = 2 },
})

minetest.register_node("testnodes:tga_type2_16bpp_tb", {
	description = S("TGA Type 2 (uncompressed RGB) 16bpp top-bottom Test Node"),
	drawtype = "glasslike",
	paramtype = "light",
	sunlight_propagates = true,
	tiles = { "testnodes_tga_type2_16bpp_tb.tga" },
	use_texture_alpha = "clip",
	groups = { dig_immediate = 2 },
})

minetest.register_node("testnodes:tga_type2_32bpp_bt", {
	description = S("TGA Type 2 (uncompressed RGB) 32bpp bottom-top Test Node"),
	drawtype = "glasslike",
	paramtype = "light",
	sunlight_propagates = true,
	tiles = { "testnodes_tga_type2_32bpp_bt.tga" },
	use_texture_alpha = "blend",
	groups = { dig_immediate = 2 },
})

minetest.register_node("testnodes:tga_type2_32bpp_tb", {
	description = S("TGA Type 2 (uncompressed RGB) 32bpp top-bottom Test Node"),
	drawtype = "glasslike",
	paramtype = "light",
	sunlight_propagates = true,
	tiles = { "testnodes_tga_type2_32bpp_tb.tga" },
	use_texture_alpha = "blend",
	groups = { dig_immediate = 2 },
})

minetest.register_node("testnodes:tga_type3_16bpp_bt", {
	description = S("TGA Type 3 (uncompressed grayscale) 16bpp bottom-top Test Node"),
	drawtype = "glasslike",
	paramtype = "light",
	sunlight_propagates = true,
	tiles = { "testnodes_tga_type3_16bpp_bt.tga" },
	use_texture_alpha = "blend",
	groups = { dig_immediate = 2 },
})

minetest.register_node("testnodes:tga_type3_16bpp_tb", {
	description = S("TGA Type 3 (uncompressed grayscale) 16bpp top-bottom Test Node"),
	drawtype = "glasslike",
	paramtype = "light",
	sunlight_propagates = true,
	tiles = { "testnodes_tga_type3_16bpp_tb.tga" },
	use_texture_alpha = "blend",
	groups = { dig_immediate = 2 },
})

minetest.register_node("testnodes:tga_type10_32bpp_bt", {
	description = S("TGA Type 10 (RLE-compressed RGB) 32bpp bottom-top Test Node"),
	tiles = { "testnodes_tga_type10_32bpp_bt.tga" },
	drawtype = "glasslike",
	paramtype = "light",
	sunlight_propagates = true,
	use_texture_alpha = "blend",
	groups = { dig_immediate = 2 },
})

minetest.register_node("testnodes:tga_type10_32bpp_tb", {
	description = S("TGA Type 10 (RLE-compressed RGB) 32bpp top-bottom Test Node"),
	drawtype = "glasslike",
	paramtype = "light",
	sunlight_propagates = true,
	tiles = { "testnodes_tga_type10_32bpp_tb.tga" },
	use_texture_alpha = "blend",
	groups = { dig_immediate = 2 },
})