2023-02-28 09:43:01 +01:00
function Node_Displace(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
name = "Displace";
2024-08-07 11:48:39 +02:00
inputs[| 0] = nodeValue_Surface("Surface in", self);
2023-01-25 06:49:00 +01:00
2024-08-07 11:48:39 +02:00
inputs[| 1] = nodeValue_Surface("Displace map", self);
2023-01-25 06:49:00 +01:00
2024-02-10 07:03:50 +01:00
inputs[| 2] = nodeValue("Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 0 ], "Vector to displace pixel by." )
2022-12-27 04:00:50 +01:00
.setDisplay(VALUE_DISPLAY.vector)
2022-12-27 13:30:02 +01:00
.setUnitRef(function(index) { return getDimension(index); });
2022-01-13 05:24:03 +01:00
2023-12-22 08:42:02 +01:00
inputs[| 3] = nodeValue("Strength", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
2023-12-22 14:46:54 +01:00
.setMappable(15);
2023-01-25 06:49:00 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 4] = nodeValue("Mid value", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0., "Brightness value to be use as a basis for 'no displacement'.")
2023-10-02 08:57:44 +02:00
.setDisplay(VALUE_DISPLAY.slider);
2022-01-13 05:24:03 +01:00
2024-08-07 11:48:39 +02:00
inputs[| 5] = nodeValue_Enum_Button("Mode", self, 0, [ "Linear", "Vector", "Angle", "Gradient" ])
.setTooltip(@"Use color data for extra information.
2024-07-05 12:58:46 +02:00
- Linear: Displace along a single line (defined by the position value).
2023-01-25 06:49:00 +01:00
- Vector: Use red as X displacement, green as Y displacement.
2024-07-05 12:58:46 +02:00
- Angle: Use red as angle, green as distance.
2024-08-07 11:48:39 +02:00
- Gradient: Displace down the brightness value defined by the Displace map.");
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 6] = nodeValue("Iterate", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false, @"If not set, then strength value is multiplied directly to the displacement.
2023-01-25 06:49:00 +01:00
If set, then strength value control how many times the effect applies on itself.");
2022-01-13 05:24:03 +01:00
2024-08-07 11:48:39 +02:00
inputs[| 7] = nodeValue_Enum_Scroll("Oversample mode", self, 0, [ "Empty", "Clamp", "Repeat" ])
.setTooltip("How to deal with pixel outside the surface.\n - Empty: Use empty pixel\n - Clamp: Repeat edge pixel\n - Repeat: Repeat texture.");
2022-01-13 05:24:03 +01:00
2024-08-07 11:48:39 +02:00
inputs[| 8] = nodeValue_Surface("Mask", self);
2023-02-14 05:32:32 +01:00
inputs[| 9] = nodeValue("Mix", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
2023-10-02 08:57:44 +02:00
.setDisplay(VALUE_DISPLAY.slider);
2023-02-14 05:32:32 +01:00
inputs[| 10] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
active_index = 10;
2024-08-07 11:48:39 +02:00
inputs[| 11] = nodeValue_Enum_Scroll("Blend mode", self, 0, [ "Overwrite", "Min", "Max" ]);
2023-11-08 13:05:24 +01:00
2023-11-09 04:02:41 +01:00
inputs[| 12] = nodeValue("Channel", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0b1111)
.setDisplay(VALUE_DISPLAY.toggle, { data: array_create(4, THEME.inspector_channel) });
2023-11-24 10:41:53 +01:00
__init_mask_modifier(8); // inputs 13, 14
2023-12-23 09:39:55 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2024-08-07 11:48:39 +02:00
inputs[| 15] = nodeValue_Surface("Strength map", self)
2023-12-22 08:42:02 +01:00
.setVisible(false, false);
2023-12-23 09:39:55 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2024-02-10 07:03:50 +01:00
inputs[| 16] = nodeValue("Separate axis", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
2024-08-07 11:48:39 +02:00
inputs[| 17] = nodeValue_Surface("Displace map 2", self);
2024-02-10 07:03:50 +01:00
2023-11-09 04:02:41 +01:00
input_display_list = [ 10, 12,
2024-02-10 07:03:50 +01:00
["Surfaces", true], 0, 8, 9, 13, 14,
["Strength", false], 1, 17, 3, 15, 4,
["Displacement", false], 5, 16, 2,
["Algorithm", true], 6, 11,
2022-01-13 05:24:03 +01:00
];
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2022-01-13 05:24:03 +01:00
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
2023-03-21 03:01:53 +01:00
attribute_oversample();
attribute_interpolation();
2023-03-19 09:17:39 +01:00
2023-11-24 10:41:53 +01:00
static step = function() { #region
__step_mask_modifier();
2023-12-22 14:46:54 +01:00
inputs[| 3].mappableStep();
2024-02-10 07:03:50 +01:00
var _mode = getInputData(5);
var _sep = getInputData(16);
2024-02-15 14:23:26 +01:00
var _dsp2 = (_mode == 1 || _mode == 2) && _sep;
2024-02-10 07:03:50 +01:00
inputs[| 2].setVisible(_mode == 0);
2024-02-15 14:23:26 +01:00
inputs[| 16].setVisible(_mode == 1 || _mode == 2);
inputs[| 17].setVisible(_dsp2, _dsp2);
2024-02-10 07:03:50 +01:00
if(_mode == 1 && _sep) {
inputs[| 1].setName("Displace X");
inputs[| 17].setName("Displace Y");
} else if(_mode == 2 && _sep) {
inputs[| 1].setName("Displace angle");
inputs[| 17].setName("Displace amount");
} else {
inputs[| 1].setName("Displace map");
}
2023-11-24 10:41:53 +01:00
} #endregion
2023-09-14 16:29:39 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
2023-09-08 21:37:36 +02:00
var ww = surface_get_width_safe(_data[0]);
var hh = surface_get_height_safe(_data[0]);
var mw = surface_get_width_safe(_data[1]);
var mh = surface_get_height_safe(_data[1]);
2022-01-13 05:24:03 +01:00
2023-11-08 13:05:24 +01:00
surface_set_shader(_outSurf, sh_displace);
2023-03-21 03:01:53 +01:00
shader_set_interpolation(_data[0]);
2024-02-10 07:03:50 +01:00
shader_set_surface("map", _data[1]);
shader_set_surface("map2", _data[17]);
2023-11-08 13:05:24 +01:00
shader_set_f("dimension", [ww, hh]);
shader_set_f("map_dimension", [mw, mh]);
2023-12-22 08:42:02 +01:00
shader_set_f("displace", _data[ 2]);
2023-12-25 12:51:12 +01:00
shader_set_f_map("strength", _data[ 3], _data[15], inputs[| 3]);
2023-12-22 08:42:02 +01:00
shader_set_f("middle", _data[ 4]);
2024-02-10 07:03:50 +01:00
shader_set_i("mode", _data[ 5]);
2023-12-22 08:42:02 +01:00
shader_set_i("iterate", _data[ 6]);
2023-11-08 13:05:24 +01:00
shader_set_i("blendMode", _data[11]);
2024-02-10 07:03:50 +01:00
shader_set_i("sepAxis", _data[16]);
2023-11-08 13:05:24 +01:00
draw_surface_safe(_data[0]);
2023-03-21 03:01:53 +01:00
surface_reset_shader();
2022-01-13 05:24:03 +01:00
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[8], _data[9]);
2023-11-09 04:02:41 +01:00
_outSurf = channel_apply(_data[0], _outSurf, _data[12]);
2023-02-14 05:32:32 +01:00
2022-01-13 05:24:03 +01:00
return _outSurf;
2023-09-14 16:29:39 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
}