Pixel-Composer/scripts/node_shadow/node_shadow.gml

118 lines
3.4 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Shadow(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
name = "Shadow";
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Surface("Surface in", self));
newInput(1, nodeValue_Color("Color", self, c_black));
2022-01-13 05:24:03 +01:00
2024-08-18 09:13:41 +02:00
newInput(2, nodeValue_Float("Strength", self, .5))
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 2, 0.01] });
2022-01-13 05:24:03 +01:00
2024-08-18 09:13:41 +02:00
newInput(3, nodeValue_Vec2("Shift", self, [ 4, 4 ]))
2022-12-27 13:30:02 +01:00
.setUnitRef(function(index) { return getDimension(index); });
2022-01-13 05:24:03 +01:00
2024-08-18 09:13:41 +02:00
newInput(4, nodeValue_Float("Grow", self, 3))
2024-03-24 04:58:08 +01:00
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 16, 0.1] });
2022-01-13 05:24:03 +01:00
2024-08-18 09:13:41 +02:00
newInput(5, nodeValue_Float("Blur", self, 3))
2024-03-24 04:58:08 +01:00
.setDisplay(VALUE_DISPLAY.slider, { range: [1, 16, 0.1] });
2022-01-13 05:24:03 +01:00
2024-08-18 06:16:20 +02:00
newInput(6, nodeValue_Surface("Mask", self));
2022-01-13 05:24:03 +01:00
2024-08-18 09:13:41 +02:00
newInput(7, nodeValue_Float("Mix", self, 1))
.setDisplay(VALUE_DISPLAY.slider);
2023-02-14 05:32:32 +01:00
2024-08-18 06:16:20 +02:00
newInput(8, nodeValue_Bool("Active", self, true));
2023-02-14 05:32:32 +01:00
active_index = 8;
2023-11-24 10:41:53 +01:00
__init_mask_modifier(6); // inputs 9, 10
2024-08-18 06:16:20 +02:00
newInput(11, nodeValue_Enum_Scroll("Positioning", self, 0, [ "Shift", "Light" ]));
2024-07-11 12:32:40 +02:00
2024-08-18 09:13:41 +02:00
newInput(12, nodeValue_Vec2("Light Position", self, [ 0, 0 ]))
2024-07-11 12:32:40 +02:00
.setUnitRef(function(index) { return getDimension(index); });
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
2023-02-14 05:32:32 +01:00
input_display_list = [ 8,
2023-11-24 10:41:53 +01:00
["Surfaces", true], 0, 6, 7, 9, 10,
2024-07-11 12:32:40 +02:00
["Shadow", false], 1, 2, 11, 3, 12, 4, 5,
2023-01-01 02:06:02 +01:00
];
2023-02-14 05:32:32 +01:00
surface_blur_init();
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
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
var _surf = outputs[0].getValue();
2024-07-02 12:18:32 +02:00
var _hov = false;
2022-01-13 05:24:03 +01:00
if(is_array(_surf)) {
2024-07-02 12:18:32 +02:00
if(array_length(_surf) == 0) return _hov;
_surf = _surf[preview_index];
2022-01-13 05:24:03 +01:00
}
2023-09-08 21:37:36 +02:00
var ww = surface_get_width_safe(_surf) * _s;
var hh = surface_get_height_safe(_surf) * _s;
2022-01-13 05:24:03 +01:00
var _typ = getSingleValue(11);
2024-08-08 06:57:51 +02:00
if(_typ == 0) { var hv = inputs[ 3].drawOverlay(hover, active, _x + ww / 2, _y + hh / 2, _s, _mx, _my, _snx, _sny); _hov |= hv; }
else if(_typ == 1) { var hv = inputs[12].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= hv; }
2024-07-02 12:18:32 +02:00
return _hov;
2022-01-13 05:24:03 +01:00
}
2024-07-11 12:32:40 +02:00
static step = function() {
2023-11-24 10:41:53 +01:00
__step_mask_modifier();
2024-07-11 12:32:40 +02:00
var _typ = getSingleValue(11);
2024-08-08 06:57:51 +02:00
inputs[ 3].setVisible(_typ == 0);
inputs[12].setVisible(_typ == 1);
2024-07-11 12:32:40 +02:00
}
2023-11-24 10:41:53 +01:00
2023-08-17 16:56:54 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
2024-07-11 12:32:40 +02:00
var _surf = _data[0];
2022-01-13 05:24:03 +01:00
var cl = _data[1];
var _stre = _data[2];
var _border = _data[4];
var _size = _data[5];
2024-07-11 12:32:40 +02:00
var _posi = _data[11];
var _shf = _data[ 3];
var _lgh = _data[12];
var _dim = surface_get_dimension(_surf);
var pass1 = surface_create_valid(_dim[0], _dim[1], attrDepth());
var _shax = _shf[0],
var _shay = _shf[1];
if(_posi == 1) {
_shax = _dim[0] / 2 - _lgh[0];
_shay = _dim[1] / 2 - _lgh[1];
2024-07-11 12:32:40 +02:00
}
2022-01-13 05:24:03 +01:00
2024-01-08 08:10:50 +01:00
surface_set_shader(pass1, sh_outline_only);
2024-07-11 12:32:40 +02:00
shader_set_f("dimension", _dim);
2024-01-08 08:10:50 +01:00
shader_set_f("borderSize", _border);
2024-07-11 12:32:40 +02:00
shader_set_f("borderColor", [ 1., 1., 1., 1. ]);
2022-01-13 05:24:03 +01:00
2024-07-11 12:32:40 +02:00
draw_surface_safe(_data[0], _shax, _shay);
2024-01-08 08:10:50 +01:00
surface_reset_shader();
2022-01-13 05:24:03 +01:00
surface_set_target(_outSurf);
2024-07-11 12:32:40 +02:00
DRAW_CLEAR
2024-07-22 10:21:57 +02:00
BLEND_OVERRIDE
2024-07-11 12:32:40 +02:00
draw_surface_ext_safe(surface_apply_gaussian(pass1, _size, false, cl), 0, 0, 1, 1, 0, cl, _stre * _color_get_alpha(cl));
2024-07-22 10:21:57 +02:00
BLEND_ALPHA_MULP
2024-07-11 12:32:40 +02:00
draw_surface_safe(_surf);
2024-07-22 10:21:57 +02:00
BLEND_NORMAL
2022-01-13 05:24:03 +01:00
surface_reset_target();
2024-07-11 12:32:40 +02:00
2022-01-13 05:24:03 +01:00
surface_free(pass1);
2023-11-24 10:41:53 +01:00
__process_mask_modifier(_data);
2023-02-14 05:32:32 +01:00
_outSurf = mask_apply(_data[0], _outSurf, _data[6], _data[7]);
2022-01-13 05:24:03 +01:00
return _outSurf;
}
}