2020-05-24 15:46:26 +02:00
|
|
|
-- Node texture tests
|
|
|
|
|
|
|
|
local S = minetest.get_translator("testnodes")
|
|
|
|
|
|
|
|
minetest.register_node("testnodes:6sides", {
|
2022-10-09 14:05:22 +02:00
|
|
|
description = S("Six Textures Test Node").."\n"..
|
|
|
|
S("Has 1 texture per face"),
|
2020-05-24 15:46:26 +02:00
|
|
|
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", {
|
2022-10-09 14:05:22 +02:00
|
|
|
description = S("Animated Test Node").."\n"..
|
|
|
|
S("Tiles animate from A to D in 4s cycle"),
|
2020-05-24 15:46:26 +02:00
|
|
|
tiles = {
|
|
|
|
{ name = "testnodes_anim.png",
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 16,
|
|
|
|
aspect_h = 16,
|
|
|
|
length = 4.0,
|
|
|
|
}, },
|
|
|
|
},
|
|
|
|
|
|
|
|
groups = { dig_immediate = 2 },
|
|
|
|
})
|
|
|
|
|
2024-03-19 19:56:47 +01:00
|
|
|
minetest.register_node("testnodes:fill_positioning", {
|
|
|
|
description = S("Fill Modifier Test Node") .. "\n" ..
|
|
|
|
S("The node should have the same look as " ..
|
|
|
|
"testnodes:fill_positioning_reference."),
|
|
|
|
drawtype = "glasslike",
|
|
|
|
paramtype = "light",
|
|
|
|
tiles = {"[fill:16x16:#ffffff^[fill:6x6:1,1:#00ffdc" ..
|
|
|
|
"^[fill:6x6:1,9:#00ffdc^[fill:6x6:9,1:#00ffdc^[fill:6x6:9,9:#00ffdc"},
|
|
|
|
groups = {dig_immediate = 3},
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("testnodes:fill_positioning_reference", {
|
|
|
|
description = S("Fill Modifier Test Node Reference"),
|
|
|
|
drawtype = "glasslike",
|
|
|
|
paramtype = "light",
|
|
|
|
tiles = {"testnodes_fill_positioning_reference.png"},
|
|
|
|
groups = {dig_immediate = 3},
|
|
|
|
})
|
|
|
|
|
2020-05-24 15:46:26 +02:00
|
|
|
-- 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, {
|
2022-10-09 14:05:22 +02:00
|
|
|
description = S("Texture Alpha Test Node (@1)", alpha).."\n"..
|
|
|
|
S("Semi-transparent"),
|
2020-05-24 15:46:26 +02:00
|
|
|
drawtype = "glasslike",
|
|
|
|
paramtype = "light",
|
|
|
|
tiles = {
|
|
|
|
"testnodes_alpha"..alpha..".png",
|
|
|
|
},
|
2021-01-17 02:25:33 +01:00
|
|
|
use_texture_alpha = "blend",
|
2020-05-24 15:46:26 +02:00
|
|
|
|
|
|
|
groups = { dig_immediate = 3 },
|
|
|
|
})
|
|
|
|
|
2021-01-16 22:16:04 +01:00
|
|
|
-- Transparency set via texture modifier
|
2020-05-24 15:46:26 +02:00
|
|
|
minetest.register_node("testnodes:alpha_"..alpha, {
|
2022-10-09 14:05:22 +02:00
|
|
|
description = S("Alpha Test Node (@1)", alpha).."\n"..
|
|
|
|
S("Semi-transparent"),
|
2021-01-16 22:16:04 +01:00
|
|
|
drawtype = "glasslike",
|
2020-05-24 15:46:26 +02:00
|
|
|
paramtype = "light",
|
|
|
|
tiles = {
|
2021-01-16 22:16:04 +01:00
|
|
|
"testnodes_alpha.png^[opacity:" .. alpha,
|
2020-05-24 15:46:26 +02:00
|
|
|
},
|
2021-01-17 02:25:33 +01:00
|
|
|
use_texture_alpha = "blend",
|
2020-05-30 01:46:57 +02:00
|
|
|
|
2020-05-24 15:46:26 +02:00
|
|
|
groups = { dig_immediate = 3 },
|
|
|
|
})
|
|
|
|
end
|
2020-10-09 20:13:42 +02:00
|
|
|
|
2024-03-19 19:56:47 +01:00
|
|
|
minetest.register_node("testnodes:alpha_compositing", {
|
|
|
|
description = S("Alpha Compositing Test Node") .. "\n" ..
|
|
|
|
S("A regular grid should be visible where each cell contains two " ..
|
|
|
|
"texels with the same colour.") .. "\n" ..
|
|
|
|
S("Alpha compositing is gamma-incorrect for backwards compatibility."),
|
|
|
|
drawtype = "glasslike",
|
|
|
|
paramtype = "light",
|
|
|
|
tiles = {"testnodes_alpha_compositing_bottom.png^" ..
|
|
|
|
"testnodes_alpha_compositing_top.png"},
|
|
|
|
use_texture_alpha = "blend",
|
|
|
|
groups = {dig_immediate = 3},
|
|
|
|
})
|
|
|
|
|
2021-07-29 05:10:10 +02:00
|
|
|
-- 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
|
|
|
|
|
2023-12-27 11:56:48 +01:00
|
|
|
-- The engine should perform color reduction of the generated PNG in certain
|
|
|
|
-- cases, so we have this helper to check the result
|
|
|
|
local function encode_and_check(w, h, ctype, data)
|
|
|
|
local ret = core.encode_png(w, h, data)
|
|
|
|
assert(ret:sub(1, 8) == "\137PNG\r\n\026\n", "missing png signature")
|
|
|
|
assert(ret:sub(9, 16) == "\000\000\000\rIHDR", "didn't find ihdr chunk")
|
|
|
|
local ctype_actual = ret:byte(26) -- Color Type (1 byte)
|
|
|
|
ctype = ({rgba=6, rgb=2, gray=0})[ctype]
|
|
|
|
assert(ctype_actual == ctype, "png should have color type " .. ctype ..
|
|
|
|
" but actually has " .. ctype_actual)
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2021-07-29 05:10:10 +02:00
|
|
|
local fractal = mandelbrot(512, 512, 128)
|
2021-10-13 17:51:37 +02:00
|
|
|
local frac_emb = mandelbrot(64, 64, 64)
|
2021-07-29 05:10:10 +02:00
|
|
|
local checker = gen_checkers(512, 512, 32)
|
|
|
|
|
|
|
|
local floor = math.floor
|
|
|
|
local abs = math.abs
|
2021-10-13 17:51:37 +02:00
|
|
|
local data_emb = {}
|
2021-07-29 05:10:10 +02:00
|
|
|
local data_mb = {}
|
|
|
|
local data_ck = {}
|
2021-10-13 17:51:37 +02:00
|
|
|
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
|
2021-07-29 05:10:10 +02:00
|
|
|
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,
|
|
|
|
}
|
2023-12-27 11:56:48 +01:00
|
|
|
data_ck[i] = checker[i] > 0 and "#888" or "#000"
|
2021-07-29 05:10:10 +02:00
|
|
|
end
|
|
|
|
|
2023-12-27 11:56:48 +01:00
|
|
|
fractal = nil
|
|
|
|
frac_emb = nil
|
|
|
|
checker = nil
|
|
|
|
|
2024-01-22 20:37:26 +01:00
|
|
|
do
|
|
|
|
-- we used to write the textures to our mod folder. in order to avoid
|
2024-01-23 21:15:09 +01:00
|
|
|
-- duplication errors delete them if they still exist.
|
2024-01-22 20:37:26 +01:00
|
|
|
local path = core.get_modpath(core.get_current_modname()) .. "/textures/"
|
|
|
|
os.remove(path .. "testnodes_generated_mb.png")
|
|
|
|
os.remove(path .. "testnodes_generated_ck.png")
|
|
|
|
end
|
|
|
|
|
|
|
|
local textures_path = core.get_worldpath() .. "/"
|
|
|
|
core.safe_file_write(
|
2024-01-22 21:24:42 +01:00
|
|
|
textures_path .. "testnodes1.png",
|
2023-12-27 11:56:48 +01:00
|
|
|
encode_and_check(512, 512, "rgb", data_mb)
|
2021-07-29 05:10:10 +02:00
|
|
|
)
|
2024-01-23 21:15:09 +01:00
|
|
|
local png_ck = encode_and_check(512, 512, "gray", data_ck)
|
2024-01-22 21:24:42 +01:00
|
|
|
core.dynamic_add_media({
|
|
|
|
filename = "testnodes_generated_mb.png",
|
|
|
|
filepath = textures_path .. "testnodes1.png"
|
|
|
|
})
|
2024-01-23 21:15:09 +01:00
|
|
|
core.dynamic_add_media({
|
|
|
|
filename = "testnodes_generated_ck.png",
|
|
|
|
filedata = png_ck,
|
|
|
|
})
|
2021-07-29 05:10:10 +02:00
|
|
|
|
|
|
|
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 },
|
|
|
|
})
|
2021-10-13 17:51:37 +02:00
|
|
|
|
2023-12-27 11:56:48 +01:00
|
|
|
local png_emb = "[png:" .. minetest.encode_base64(
|
|
|
|
encode_and_check(64, 64, "rgba", data_emb))
|
2021-10-13 17:51:37 +02:00
|
|
|
|
|
|
|
minetest.register_node("testnodes:generated_png_emb", {
|
|
|
|
description = S("Generated In-Band Mandelbrot PNG Test Node"),
|
|
|
|
tiles = { png_emb },
|
|
|
|
|
2022-10-09 16:26:16 +02:00
|
|
|
drawtype = "allfaces", -- required because of transparent pixels
|
|
|
|
use_texture_alpha = "clip",
|
|
|
|
paramtype = "light",
|
2021-10-13 17:51:37 +02:00
|
|
|
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" },
|
|
|
|
|
2022-10-09 16:26:16 +02:00
|
|
|
drawtype = "allfaces", -- required because of transparent pixels
|
|
|
|
use_texture_alpha = "clip",
|
|
|
|
paramtype = "light",
|
2021-10-13 17:51:37 +02:00
|
|
|
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 },
|
|
|
|
})
|
2022-02-22 19:17:40 +01:00
|
|
|
|
2024-01-23 21:15:09 +01:00
|
|
|
png_ck = nil
|
|
|
|
png_emb = nil
|
2023-12-27 11:56:48 +01:00
|
|
|
data_emb = nil
|
|
|
|
data_mb = nil
|
|
|
|
data_ck = nil
|
|
|
|
|
2022-02-22 19:17:40 +01:00
|
|
|
--[[
|
|
|
|
|
|
|
|
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 },
|
|
|
|
})
|