Skip to content

Commit 30c51a1

Browse files
juhdanadnerzhul
authored andcommittedJun 2, 2017
Document hardware coloring and soft node overlays (#5876)
1 parent 001de6f commit 30c51a1

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed
 

Diff for: ‎doc/lua_api.txt

+161
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,167 @@ Result is more like what you'd expect if you put a color on top of another
426426
color. Meaning white surfaces get a lot of your new color while black parts don't
427427
change very much.
428428

429+
Hardware coloring
430+
-----------------
431+
The goal of hardware coloring is to simplify the creation of
432+
colorful nodes. If your textures use the same pattern, and they only
433+
differ in their color (like colored wool blocks), you can use hardware
434+
coloring instead of creating and managing many texture files.
435+
All of these methods use color multiplication (so a white-black texture
436+
with red coloring will result in red-black color).
437+
438+
### Static coloring
439+
This method is useful if you wish to create nodes/items with
440+
the same texture, in different colors, each in a new node/item definition.
441+
442+
#### Global color
443+
When you register an item or node, set its `color` field (which accepts a
444+
`ColorSpec`) to the desired color.
445+
446+
An `ItemStack`s static color can be overwritten by the `color` metadata
447+
field. If you set that field to a `ColorString`, that color will be used.
448+
449+
#### Tile color
450+
Each tile may have an individual static color, which overwrites every
451+
other coloring methods. To disable the coloring of a face,
452+
set its color to white (because multiplying with white does nothing).
453+
You can set the `color` property of the tiles in the node's definition
454+
if the tile is in table format.
455+
456+
### Palettes
457+
For nodes and items which can have many colors, a palette is more
458+
suitable. A palette is a texture, which can contain up to 256 pixels.
459+
Each pixel is one possible color for the node/item.
460+
You can register one node/item, which can have up to 256 colors.
461+
462+
#### Palette indexing
463+
When using palettes, you always provide a pixel index for the given
464+
node or `ItemStack`. The palette is read from left to right and from
465+
top to bottom. If the palette has less than 256 pixels, then it is
466+
stretched to contain exactly 256 pixels (after arranging the pixels
467+
to one line). The indexing starts from 0.
468+
469+
Examples:
470+
* 16x16 palette, index = 0: the top left corner
471+
* 16x16 palette, index = 4: the fifth pixel in the first row
472+
* 16x16 palette, index = 16: the pixel below the top left corner
473+
* 16x16 palette, index = 255: the bottom right corner
474+
* 2 (width)x4 (height) palette, index=31: the top left corner.
475+
The palette has 8 pixels, so each pixel is stretched to 32 pixels,
476+
to ensure the total 256 pixels.
477+
* 2x4 palette, index=32: the top right corner
478+
* 2x4 palette, index=63: the top right corner
479+
* 2x4 palette, index=64: the pixel below the top left corner
480+
481+
#### Using palettes with items
482+
When registering an item, set the item definition's `palette` field to
483+
a texture. You can also use texture modifiers.
484+
485+
The `ItemStack`'s color depends on the `palette_index` field of the
486+
stack's metadata. `palette_index` is an integer, which specifies the
487+
index of the pixel to use.
488+
489+
#### Linking palettes with nodes
490+
When registering a node, set the item definition's `palette` field to
491+
a texture. You can also use texture modifiers.
492+
The node's color depends on its `param2`, so you also must set an
493+
appropriate `drawtype`:
494+
* `drawtype = "color"` for nodes which use their full `param2` for
495+
palette indexing. These nodes can have 256 different colors.
496+
The palette should contain 256 pixels.
497+
* `drawtype = "colorwallmounted"` for nodes which use the first
498+
five bits (most significant) of `param2` for palette indexing.
499+
The remaining three bits are describing rotation, as in `wallmounted`
500+
draw type. Division by 8 yields the palette index (without stretching the
501+
palette). These nodes can have 32 different colors, and the palette
502+
should contain 32 pixels.
503+
Examples:
504+
* `param2 = 17` is 2 * 8 + 1, so the rotation is 1 and the third (= 2 + 1)
505+
pixel will be picked from the palette.
506+
* `param2 = 35` is 4 * 8 + 3, so the rotation is 3 and the fifth (= 4 + 1)
507+
pixel will be picked from the palette.
508+
* `drawtype = "colorfacedir"` for nodes which use the first
509+
three bits of `param2` for palette indexing. The remaining
510+
five bits are describing rotation, as in `facedir` draw type.
511+
Division by 32 yields the palette index (without stretching the
512+
palette). These nodes can have 8 different colors, and the
513+
palette should contain 8 pixels.
514+
Examples:
515+
* `param2 = 17` is 0 * 32 + 17, so the rotation is 17 and the
516+
first (= 0 + 1) pixel will be picked from the palette.
517+
* `param2 = 35` is 1 * 32 + 3, so the rotation is 3 and the
518+
second (= 1 + 1) pixel will be picked from the palette.
519+
520+
To colorize a node on the map, set its `param2` value (according
521+
to the node's draw type).
522+
523+
### Conversion between nodes in the inventory and the on the map
524+
Static coloring is the same for both cases, there is no need
525+
for conversion.
526+
527+
If the `ItemStack`'s metadata contains the `color` field, it will be
528+
lost on placement, because nodes on the map can only use palettes.
529+
530+
If the `ItemStack`'s metadata contains the `palette_index` field, you
531+
currently must manually convert between it and the node's `param2` with
532+
custom `on_place` and `on_dig` callbacks.
533+
534+
### Colored items in craft recipes
535+
Craft recipes only support item strings, but fortunately item strings
536+
can also contain metadata. Example craft recipe registration:
537+
538+
local stack = ItemStack("wool:block")
539+
dyed:get_meta():set_int("palette_index", 3) -- add index
540+
minetest.register_craft({
541+
output = dyed:to_string(), -- convert to string
542+
type = "shapeless",
543+
recipe = {
544+
"wool:block",
545+
"dye:red",
546+
},
547+
})
548+
549+
Metadata field filtering in the `recipe` field are not supported yet,
550+
so the craft output is independent of the color of the ingredients.
551+
552+
Soft texture overlay
553+
--------------------
554+
Sometimes hardware coloring is not enough, because it affects the
555+
whole tile. Soft texture overlays were added to Minetest to allow
556+
the dynamic coloring of only specific parts of the node's texture.
557+
For example a grass block may have colored grass, while keeping the
558+
dirt brown.
559+
560+
These overlays are 'soft', because unlike texture modifiers, the layers
561+
are not merged in the memory, but they are simply drawn on top of each
562+
other. This allows different hardware coloring, but also means that
563+
tiles with overlays are drawn slower. Using too much overlays might
564+
cause FPS loss.
565+
566+
To define an overlay, simply set the `overlay_tiles` field of the node
567+
definition. These tiles are defined in the same way as plain tiles:
568+
they can have a texture name, color etc.
569+
To skip one face, set that overlay tile to an empty string.
570+
571+
Example (colored grass block):
572+
573+
minetest.register_node("default:dirt_with_grass", {
574+
description = "Dirt with Grass",
575+
-- Regular tiles, as usual
576+
-- The dirt tile disables palette coloring
577+
tiles = {{name = "default_grass.png"},
578+
{name = "default_dirt.png", color = "white"}},
579+
-- Overlay tiles: define them in the same style
580+
-- The top and bottom tile does not have overlay
581+
overlay_tiles = {"", "",
582+
{name = "default_grass_side.png", tileable_vertical = false}},
583+
-- Global color, used in inventory
584+
color = "green",
585+
-- Palette in the world
586+
paramtype2 = "color",
587+
palette = "default_foilage.png",
588+
})
589+
429590
Sounds
430591
------
431592
Only Ogg Vorbis files are supported.

0 commit comments

Comments
 (0)
Please sign in to comment.