Skip to content

Commit 8cd1296

Browse files
authored
Add additional texture modifiers (#10100)
* Adjust hue, saturation, and lightness * Colorize using hue, saturation, and lightness * Adjust contrast & brightness * Hard light * Overlay * Screen * Create texture of a given size and color
1 parent a8ec609 commit 8cd1296

File tree

2 files changed

+529
-36
lines changed

2 files changed

+529
-36
lines changed

doc/lua_api.md

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,29 @@ Example:
594594
Creates an inventorycube with `grass.png`, `dirt.png^grass_side.png` and
595595
`dirt.png^grass_side.png` textures
596596

597+
#### `[fill:<w>x<h>:<x>,<y>:<color>`
598+
599+
* `<w>`: width
600+
* `<h>`: height
601+
* `<x>`: x position
602+
* `<y>`: y position
603+
* `<color>`: a `ColorString`.
604+
605+
Creates a texture of the given size and color, optionally with an <x>,<y>
606+
position. An alpha value may be specified in the `Colorstring`.
607+
608+
The optional <x>,<y> position is only used if the [fill is being overlaid
609+
onto another texture with '^'.
610+
611+
When [fill is overlaid onto another texture it will not upscale or change
612+
the resolution of the texture, the base texture will determine the output
613+
resolution.
614+
615+
Examples:
616+
617+
[fill:16x16:#20F02080
618+
texture.png^[fill:8x8:4,4:red
619+
597620
#### `[lowpart:<percent>:<file>`
598621

599622
Blit the lower `<percent>`% part of `<file>` on the texture.
@@ -628,14 +651,30 @@ which it assumes to be a tilesheet with dimensions w,h.
628651

629652
Colorize the textures with the given color.
630653
`<color>` is specified as a `ColorString`.
631-
`<ratio>` is an int ranging from 0 to 255 or the word "`alpha`". If
654+
`<ratio>` is an int ranging from 0 to 255 or the word "`alpha`". If
632655
it is an int, then it specifies how far to interpolate between the
633656
colors where 0 is only the texture color and 255 is only `<color>`. If
634657
omitted, the alpha of `<color>` will be used as the ratio. If it is
635658
the word "`alpha`", then each texture pixel will contain the RGB of
636659
`<color>` and the alpha of `<color>` multiplied by the alpha of the
637660
texture pixel.
638661

662+
#### `[colorizehsl:<hue>:<saturation>:<lightness>`
663+
664+
Colorize the texture to the given hue. The texture will be converted into a
665+
greyscale image as seen through a colored glass, like "Colorize" in GIMP.
666+
Saturation and lightness can optionally be adjusted.
667+
668+
`<hue>` should be from -180 to +180. The hue at 0° on an HSL color wheel is
669+
red, 60° is yellow, 120° is green, and 180° is cyan, while -60° is magenta
670+
and -120° is blue.
671+
672+
`<saturation>` and `<lightness>` are optional adjustments.
673+
674+
`<lightness>` is from -100 to +100, with a default of 0
675+
676+
`<saturation>` is from 0 to 100, with a default of 50
677+
639678
#### `[multiply:<color>`
640679

641680
Multiplies texture colors with the given color.
@@ -644,6 +683,76 @@ Result is more like what you'd expect if you put a color on top of another
644683
color, meaning white surfaces get a lot of your new color while black parts
645684
don't change very much.
646685

686+
A Multiply blend can be applied between two textures by using the overlay
687+
modifier with a brightness adjustment:
688+
689+
textureA.png^[contrast:0:-64^[overlay:textureB.png
690+
691+
#### `[screen:<color>`
692+
693+
Apply a Screen blend with the given color. A Screen blend is the inverse of
694+
a Multiply blend, lightening images instead of darkening them.
695+
696+
`<color>` is specified as a `ColorString`.
697+
698+
A Screen blend can be applied between two textures by using the overlay
699+
modifier with a brightness adjustment:
700+
701+
textureA.png^[contrast:0:64^[overlay:textureB.png
702+
703+
#### `[hsl:<hue>:<saturation>:<lightness>`
704+
705+
Adjust the hue, saturation, and lightness of the texture. Like
706+
"Hue-Saturation" in GIMP, but with 0 as the mid-point.
707+
708+
`<hue>` should be from -180 to +180
709+
710+
`<saturation>` and `<lightness>` are optional, and both percentages.
711+
712+
`<lightness>` is from -100 to +100.
713+
714+
`<saturation>` goes down to -100 (fully desaturated) but may go above 100,
715+
allowing for even muted colors to become highly saturated.
716+
717+
#### `[contrast:<contrast>:<brightness>`
718+
719+
Adjust the brightness and contrast of the texture. Conceptually like
720+
GIMP's "Brightness-Contrast" feature but allows brightness to be wound
721+
all the way up to white or down to black.
722+
723+
`<contrast>` is a value from -127 to +127.
724+
725+
`<brightness>` is an optional value, from -127 to +127.
726+
727+
If only a boost in contrast is required, an alternative technique is to
728+
hardlight blend the texture with itself, this increases contrast in the same
729+
way as an S-shaped color-curve, which avoids dark colors clipping to black
730+
and light colors clipping to white:
731+
732+
texture.png^[hardlight:texture.png
733+
734+
#### `[overlay:<file>`
735+
736+
Applies an Overlay blend with the two textures, like the Overlay layer mode
737+
in GIMP. Overlay is the same as Hard light but with the role of the two
738+
textures swapped, see the `[hardlight` modifier description for more detail
739+
about these blend modes.
740+
741+
#### `[hardlight:<file>`
742+
743+
Applies a Hard light blend with the two textures, like the Hard light layer
744+
mode in GIMP.
745+
746+
Hard light combines Multiply and Screen blend modes. Light parts of the
747+
`<file>` texture will lighten (screen) the base texture, and dark parts of the
748+
`<file>` texture will darken (multiply) the base texture. This can be useful
749+
for applying embossing or chiselled effects to textures. A Hard light with the
750+
same texture acts like applying an S-shaped color-curve, and can be used to
751+
increase contrast without clipping.
752+
753+
Hard light is the same as Overlay but with the roles of the two textures
754+
swapped, i.e. `A.png^[hardlight:B.png` is the same as `B.png^[overlay:A.png`
755+
647756
#### `[png:<base64>`
648757

649758
Embed a base64 encoded PNG image in the texture string.

0 commit comments

Comments
 (0)