Skip to content

Commit 93e3555

Browse files
Foghrye4Zeno-
authored andcommittedNov 14, 2016
Adding particle blend, glow and animation (#4705)
1 parent 649448a commit 93e3555

15 files changed

+800
-81
lines changed
 

‎builtin/common/misc_helpers.lua

+37
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,43 @@ function math.sign(x, tolerance)
237237
return 0
238238
end
239239

240+
--------------------------------------------------------------------------------
241+
-- Video enums and pack function
242+
243+
-- E_BLEND_FACTOR
244+
minetest.ebf = {
245+
zero = 0, -- src & dest (0, 0, 0, 0)
246+
one = 1, -- src & dest (1, 1, 1, 1)
247+
dst_color = 2, -- src (destR, destG, destB, destA)
248+
one_minus_dst_color = 3, -- src (1-destR, 1-destG, 1-destB, 1-destA)
249+
src_color = 4, -- dest (srcR, srcG, srcB, srcA)
250+
one_minus_src_color = 5, -- dest (1-srcR, 1-srcG, 1-srcB, 1-srcA)
251+
src_alpha = 6, -- src & dest (srcA, srcA, srcA, srcA)
252+
one_minus_src_alpha = 7, -- src & dest (1-srcA, 1-srcA, 1-srcA, 1-srcA)
253+
dst_alpha = 8, -- src & dest (destA, destA, destA, destA)
254+
one_minus_dst_alpha = 9, -- src & dest (1-destA, 1-destA, 1-destA, 1-destA)
255+
src_alpha_saturate = 10,-- src (min(srcA, 1-destA), idem, ...)
256+
}
257+
258+
-- E_MODULATE_FUNC
259+
minetest.emfn = {
260+
modulate_1x = 1,
261+
modulate_2x = 2,
262+
modulate_4x = 4,
263+
}
264+
265+
-- E_ALPHA_SOURCE
266+
minetest.eas = {
267+
none = 0,
268+
vertex_color = 1,
269+
texture = 2,
270+
}
271+
272+
-- BlendFunc = source * sourceFactor + dest * destFactor
273+
function minetest.pack_texture_blend_func(srcFact, dstFact, modulate, alphaSource)
274+
return alphaSource * 4096 + modulate * 256 + srcFact * 16 + dstFact
275+
end
276+
240277
--------------------------------------------------------------------------------
241278
function get_last_folder(text,count)
242279
local parts = text:split(DIR_DELIM)

‎doc/lua_api.txt

+186-3
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,119 @@ the word "`alpha`", then each texture pixel will contain the RGB of
414414
`<color>` and the alpha of `<color>` multiplied by the alpha of the
415415
texture pixel.
416416

417+
Particle blend
418+
--------------
419+
Blend function is defined by integer number.
420+
There is a huge number of acceptable blend modificators.
421+
Colour of a resulting pixel calculated using formulae:
422+
423+
red = source_red * source_factor + destination_red * destination_factor
424+
425+
and so on for every channel.
426+
427+
Here is a some examples:
428+
429+
Default value:
430+
431+
material_type_param = 0,
432+
433+
Use this value to disable blending. Texture will be applied to existing pixels
434+
using alpha channel of it. Its recomended to use 1-bit alpha
435+
in that case. This value will leave z-buffer writeable.
436+
437+
Additive blend:
438+
439+
material_type_param = 12641,
440+
441+
Source = src_alpha, destination = one, alpha source is a texture and
442+
vertex_color, modulate_1x.
443+
Black color is completely transparent, white color is completely opaque.
444+
Alpha channel still used to calculate result color, but not nessesary.
445+
'destination = one' means that resulting color will be calculated using
446+
overwritten pixels values.
447+
For example with color of source (our texture) RGBA = (0,192,255,63)
448+
"blue-cyan", 1/4 opaque.
449+
and already rendered pixel color (40,192,0) "dark lime green" we will get color:
450+
451+
R = source_red(0) * source_factor(src_alpha=63/255) +
452+
destination_red(40) * destination_factor(one) =
453+
0 * 63/255 + 40 * 1 = 40
454+
455+
G = 192 * 63/255 + 192 * 1 = 239
456+
B = 255 * 63/255 + 0 * 1 = 63
457+
458+
Result: (40,239,63), "green" (a kind of).
459+
Note, if you made a texture with some kind of shape with colour 662211h
460+
it will appear dark red with a single particle, then yellow with a
461+
several of them and white if player looking thru a lot of them. With
462+
this you could made a nice-looking fire.
463+
464+
Substractive blend:
465+
466+
material_type_param = 12548,
467+
468+
Source = zero, destination = src_color, alpha source is a texture and
469+
vertex_color, modulate_1x.
470+
Texture darkness act like an alpha channel.
471+
Black color is completely opaque, white color is completely transparent.
472+
'destination = src_color' means that destination in multiplied by
473+
a source values. 'source = zero' means that source values ignored
474+
(multiplied by 0).
475+
476+
Invert blend:
477+
478+
material_type_param = 12597,
479+
480+
Source = one_minus_dst_color, destination = one_minus_src_alpha, alpha source
481+
is a texture and vertex_color, modulate_1x.
482+
Pixels invert color if source color value is big enough. If not, they just
483+
black.
484+
'destination = one_minus_src_alpha' means, that effect is masked by a
485+
source alpha channel.
486+
487+
You can design and use your own blend using those enum values and function
488+
'minetest.pack_texture_blend_func'. Returned value of a function is
489+
your 'material_type_param'.
490+
491+
A values in a brackets is a multiplicators of a red, green, blue
492+
and alpha channels respectively.
493+
494+
* 'minetest.ebf': global table, containing blend factor enum values. Such as:
495+
* zero = 0 -- src & dest (0, 0, 0, 0)
496+
* one = 1 -- src & dest (1, 1, 1, 1)
497+
* dst_color = 2 -- src (destR, destG, destB, destA)
498+
* one_minus_dst_color = 3 -- src (1-destR, 1-destG, 1-destB, 1-destA)
499+
* src_color = 4 -- dest (srcR, srcG, srcB, srcA)
500+
* one_minus_src_color = 5 -- dest (1-srcR, 1-srcG, 1-srcB, 1-srcA)
501+
* src_alpha = 6 -- src & dest (srcA, srcA, srcA, srcA)
502+
* one_minus_src_alpha = 7 -- src & dest (1-srcA, 1-srcA, 1-srcA, 1-srcA)
503+
* dst_alpha = 8 -- src & dest (destA, destA, destA, destA)
504+
* one_minus_dst_alpha = 9 -- src & dest (1-destA, 1-destA, 1-destA, 1-destA)
505+
* src_alpha_saturate = 10 -- src (min(srcA, 1-destA), idem, ...)
506+
507+
* 'minetest.emfn': global table, containing modulate enum values.
508+
* Multiply the components of the arguments, and shift the products to the
509+
* left by x bits for brightening. Contain:
510+
* modulate_1x = 1 -- no bit shift
511+
* modulate_2x = 2 -- 1 bits shift
512+
* modulate_4x = 4 -- 2 bits shift
513+
514+
'modulate_4x' is quite useful when you want to make additive blend stronger
515+
with a lower amount of particles.
516+
517+
* 'minetest.eas': global table, containing alpha source enum values. Such as:
518+
* none = 0 -- do not use alpha.
519+
* vertex_color = 1 -- use vertex color alpha.
520+
* texture = 2 -- use texture alpha.
521+
522+
You can use both 'vertex_color' and 'texture' source by using value 3.
523+
524+
* 'minetest.pack_texture_blend_func(srcFact, dstFact, modulate, alphaSource)': return integer
525+
* Pack texture blend funcion variable. Depending from that variable blend
526+
* function will be applied in time of a render poligons with selected material.
527+
* Therefore resulting pixel will be 'source * srcFact + destination * dstFact'
528+
* Use result of this function as 'material_type_param'.
529+
417530
Sounds
418531
------
419532
Only Ogg Vorbis files are supported.
@@ -3650,7 +3763,7 @@ Definition tables
36503763

36513764
### Tile definition
36523765
* `"image.png"`
3653-
* `{name="image.png", animation={Tile Animation definition}}`
3766+
* `{name="image.png", animation={Animation definition}}`
36543767
* `{name="image.png", backface_culling=bool, tileable_vertical=bool,
36553768
tileable_horizontal=bool}`
36563769
* backface culling enabled by default for most nodes
@@ -3661,8 +3774,50 @@ Definition tables
36613774
* deprecated, yet still supported field names:
36623775
* `image` (name)
36633776

3664-
### Tile animation definition
3665-
* `{type="vertical_frames", aspect_w=16, aspect_h=16, length=3.0}`
3777+
### Animation definition
3778+
3779+
#### Node animation, particle and particle spawners
3780+
* `{ type="vertical_frames",
3781+
aspect_w=16,
3782+
-- ^ specify width of a picture in pixels.
3783+
aspect_h=16,
3784+
-- ^ specify height of a frame in pixels.
3785+
length=3.0
3786+
-- ^ specify full loop length.
3787+
first_frame = 0, -- <- only for particles, use
3788+
min_first_frame = 0, -- <- for particle spawners
3789+
max_first_frame = 0,
3790+
loop_animation = true, -- <- only for particles and particle spawners
3791+
-- specify if animation should start from beginning after last frame.
3792+
}`
3793+
3794+
#### Particle and particle spawners only
3795+
* `{
3796+
type="2d_animation_sheet", -- <- only for particles and particle spawners
3797+
vertical_frame_num = 1,
3798+
horizontal_frame_num = 1,
3799+
-- ^ specify amount of frames in texture.
3800+
-- Can be used both for animation or for texture transform
3801+
-- together with first_frame variable.
3802+
-- A animation texture separated on equal parts of frames,
3803+
-- by horizontal and vertical numbers. For example with
3804+
-- vertical_frame_num = 4 and horizontal_frame_num = 3 we got
3805+
-- 4*3 = 12 frames in total. Animation sequence start from
3806+
-- left top frame and go on to the right until reach end of
3807+
-- row. Next row also start from left frame.
3808+
first_frame = 0, -- <- only for particles, use
3809+
min_first_frame = 0, -- <- for particle spawners
3810+
max_first_frame = 0,
3811+
-- ^ specify first frame to start animation.
3812+
frame_length = -1,
3813+
-- ^ specify length of a frame in seconds. Negative and zero values
3814+
-- disable animation. A sequence with vertical_frame_num = 4 and
3815+
-- horizontal_frame_num = 3, first_frame = 4 and frame_length = 0.1
3816+
-- will end in (4*3-4)*0.1 = 0.8 seconds.
3817+
loop_animation = true,
3818+
-- specify if animation should start from beginning after last frame.
3819+
}`
3820+
* All settings are optional. Default values is located in this example.
36663821

36673822
### Node definition (`register_node`)
36683823

@@ -4117,6 +4272,20 @@ The Biome API is still in an experimental phase and subject to change.
41174272
-- ^ Uses texture (string)
41184273
playername = "singleplayer"
41194274
-- ^ optional, if specified spawns particle only on the player's client
4275+
material_type_param = 12641,
4276+
-- ^ optional, if specified spawns particle with
4277+
-- specified material type param and disable z-buffer.
4278+
-- Some examples:
4279+
-- Default value: 0,
4280+
-- Additive blend: 12641,
4281+
-- Substractive blend: 12548,
4282+
-- Invert blend: 12597,
4283+
-- See also "Particle blend".
4284+
animation = {Animation definition},
4285+
-- ^ see above. Note, that particle and particle spawners have differences.
4286+
glow = 15,
4287+
-- ^ optional, specify particle self-luminescence in darkness.
4288+
values may vary from 0 (no glow) to 15 (bright glow).
41204289
}
41214290

41224291
### `ParticleSpawner` definition (`add_particlespawner`)
@@ -4151,6 +4320,20 @@ The Biome API is still in an experimental phase and subject to change.
41514320
-- ^ Uses texture (string)
41524321
playername = "singleplayer"
41534322
-- ^ Playername is optional, if specified spawns particle only on the player's client
4323+
material_type_param = 12641,
4324+
-- ^ optional, if specified spawns particle with specified material type
4325+
-- param and disable z-buffer.
4326+
-- Some examples:
4327+
-- Default value: 0,
4328+
-- Additive blend: 12641,
4329+
-- Substractive blend: 12548,
4330+
-- Invert blend: 12597,
4331+
-- See also "Particle blend".
4332+
animation = {Animation definition},
4333+
-- ^ see above. Note, that particle and particle spawners have differences.
4334+
glow = 15,
4335+
-- ^ optional, specify particle self-luminescence in darkness.
4336+
values may vary from 0 (no glow) to 15 (bright glow).
41544337
}
41554338

41564339
### `HTTPRequest` definition (`HTTPApiTable.fetch_async`, `HTTPApiTable.fetch_async`)

‎src/client.h

+18
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3535
#include "hud.h"
3636
#include "particles.h"
3737
#include "network/networkpacket.h"
38+
#include "nodedef.h" // AnimationType
3839

3940
struct MeshMakeData;
4041
class MapBlockMesh;
@@ -185,6 +186,14 @@ struct ClientEvent
185186
bool collision_removal;
186187
bool vertical;
187188
std::string *texture;
189+
u32 material_type_param;
190+
AnimationType animation_type;
191+
u16 vertical_frame_num;
192+
u16 horizontal_frame_num;
193+
u16 first_frame;
194+
float frame_length;
195+
bool loop_animation;
196+
u8 glow;
188197
} spawn_particle;
189198
struct{
190199
u16 amount;
@@ -205,6 +214,15 @@ struct ClientEvent
205214
bool vertical;
206215
std::string *texture;
207216
u32 id;
217+
u32 material_type_param;
218+
AnimationType animation_type;
219+
u16 vertical_frame_num;
220+
u16 horizontal_frame_num;
221+
u16 min_first_frame;
222+
u16 max_first_frame;
223+
float frame_length;
224+
bool loop_animation;
225+
u8 glow;
208226
} add_particlespawner;
209227
struct{
210228
u32 id;

0 commit comments

Comments
 (0)
Please sign in to comment.