Pixel-Composer/scripts/node_smoke_turbulence/node_smoke_turbulence.gml

72 lines
2.5 KiB
Text
Raw Normal View History

2024-03-19 09:49:29 +01:00
function Node_Smoke_Turbulence(_x, _y, _group = noone) : Node_Smoke(_x, _y, _group) constructor {
2023-02-14 02:48:33 +01:00
name = "Turbulence";
2024-03-28 14:18:02 +01:00
setDimension(96, 96);
2023-02-14 02:48:33 +01:00
manual_ungroupable = false;
2024-08-20 10:15:53 +02:00
newInput(0, nodeValue("Domain", self, CONNECT_TYPE.input, VALUE_TYPE.sdomain, noone))
2023-02-14 02:48:33 +01:00
.setVisible(true, true);
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Area("Effect area", self, DEF_AREA, { useShape : false }));
2023-02-14 02:48:33 +01:00
2024-08-18 09:13:41 +02:00
newInput(2, nodeValue_Float("Strength", self, 0.10))
.setDisplay(VALUE_DISPLAY.slider, { range: [-1, 1, 0.01] });
2023-02-14 02:48:33 +01:00
2024-08-18 09:13:41 +02:00
newInput(3, nodeValue_Float("Scale", self, 4))
.setDisplay(VALUE_DISPLAY.slider, { range: [1, 16, 0.01] });
2023-02-14 02:48:33 +01:00
2024-08-18 09:13:41 +02:00
newInput(4, nodeValue_Float("Seed", self, seed_random(6)))
2024-08-08 06:57:51 +02:00
.setDisplay(VALUE_DISPLAY._default, { side_button : button(function() { randomize(); inputs[4].setValue(seed_random(6)); }).setIcon(THEME.icon_random, 0, COLORS._main_icon) });
2023-02-14 02:48:33 +01:00
2024-08-18 06:16:20 +02:00
newInput(5, nodeValue_Enum_Button("Mode", self, 0, [ "Override", "Add" ]));
2023-02-14 02:48:33 +01:00
input_display_list = [
["Domain", false], 0,
["Turbulence", false], 5, 1, 2, 4, 3
];
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Domain", self, VALUE_TYPE.sdomain, noone));
2023-02-14 02:48:33 +01:00
2024-03-14 14:35:19 +01:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
2024-08-08 06:57:51 +02:00
inputs[1].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
2023-02-14 02:48:33 +01:00
}
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) {
2024-08-06 14:04:41 +02:00
var _dom = getInputData(0);
var _are = getInputData(1);
var _str = getInputData(2);
var _sca = getInputData(3);
var _sed = getInputData(4);
var _mod = getInputData(5);
2023-02-14 02:48:33 +01:00
2023-10-07 09:09:18 +02:00
FLUID_DOMAIN_CHECK
2024-08-08 06:57:51 +02:00
outputs[0].setValue(_dom);
2023-02-14 02:48:33 +01:00
var vSurface = surface_create_size(_dom.sf_velocity);
surface_set_target(vSurface)
draw_clear_alpha(0., 0.);
shader_set(sh_fd_turbulence);
BLEND_OVERRIDE;
2024-06-24 13:49:54 +02:00
shader_set_uniform_f(shader_get_uniform(sh_fd_turbulence, "scale"), _sca);
shader_set_uniform_f(shader_get_uniform(sh_fd_turbulence, "seed"), _sed);
2023-02-14 02:48:33 +01:00
shader_set_uniform_f(shader_get_uniform(sh_fd_turbulence, "strength"), _str);
draw_sprite_stretched(s_fx_pixel, 0, _are[0] - _are[2], _are[1] - _are[3], _are[2] * 2, _are[3] * 2);
BLEND_NORMAL;
shader_reset();
surface_reset_target();
2023-10-09 16:07:33 +02:00
fd_rectangle_set_target(_dom, _mod? FD_TARGET_TYPE.ADD_VELOCITY : FD_TARGET_TYPE.REPLACE_VELOCITY);
draw_surface_safe(vSurface);
2023-10-09 16:07:33 +02:00
fd_rectangle_reset_target(_dom);
2023-02-14 02:48:33 +01:00
surface_free(vSurface);
}
2023-03-05 07:16:44 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
2023-02-14 02:48:33 +01:00
var bbox = drawGetBbox(xx, yy, _s);
2023-11-10 11:32:46 +01:00
draw_sprite_fit(s_node_smokeSim_turbulence, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
2023-02-14 02:48:33 +01:00
}
}