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";
shader = sh_displace;
displace_map_sample = shader_get_sampler_index(shader, "map");
uniform_dim = shader_get_uniform(shader, "dimension");
uniform_map_dim = shader_get_uniform(shader, "map_dimension");
uniform_position = shader_get_uniform(shader, "displace");
uniform_strength = shader_get_uniform(shader, "strength");
uniform_mid = shader_get_uniform(shader, "middle");
uniform_rg = shader_get_uniform(shader, "use_rg");
uniform_it = shader_get_uniform(shader, "iterate");
2022-12-27 04:00:50 +01:00
uniform_sam = shader_get_uniform(shader, "sampleMode");
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
2023-01-25 06:49:00 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("Displace map", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
2023-01-25 06:49:00 +01:00
2023-02-14 05:32:32 +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-02-14 05:32:32 +01:00
inputs[| 3] = nodeValue("Strength", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1);
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'.")
2022-01-13 05:24:03 +01:00
.setDisplay(VALUE_DISPLAY.slider, [ 0, 1, 0.01]);
2023-02-14 05:32:32 +01:00
inputs[| 5] = nodeValue("Color data", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0, @"Use color data set extra information.
2023-01-25 06:49:00 +01:00
- Ignore: Don't use color data.
- Vector: Use red as X displacement, green as Y displacement.
- Angle: Use red as angle, green as distance.")
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.enum_button, [ "Ignore", "Vector", "Angle" ]);
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
2023-02-14 05:32:32 +01:00
inputs[| 7] = nodeValue("Oversample mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0, "How to deal with pixel outside the surface.\n - Empty: Use empty pixel\n - Clamp: Repeat edge pixel\n - Repeat: Repeat texture.")
2022-12-27 04:00:50 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Empty", "Clamp", "Repeat" ]);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 8] = nodeValue("Mask", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
inputs[| 9] = nodeValue("Mix", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
.setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
inputs[| 10] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
active_index = 10;
input_display_list = [ 10,
2023-05-03 21:42:17 +02:00
["Output", true], 0, 8, 9,
2022-01-13 05:24:03 +01:00
["Displace", false], 1, 3, 4,
["Color", false], 5, 2,
2023-02-14 05:32:32 +01:00
["Algorithm", true], 6
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-09-14 16:29:39 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
2022-01-13 05:24:03 +01:00
switch(_data[5]) {
case 0 :
2022-01-19 06:11:17 +01:00
inputs[| 2].setVisible(true);
2022-01-13 05:24:03 +01:00
break;
case 1 :
case 2 :
2022-01-19 06:11:17 +01:00
inputs[| 2].setVisible(false);
2022-01-13 05:24:03 +01:00
break;
}
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-03-21 03:01:53 +01:00
surface_set_shader(_outSurf, shader);
shader_set_interpolation(_data[0]);
2022-01-13 05:24:03 +01:00
texture_set_stage(displace_map_sample, surface_get_texture(_data[1]));
2023-02-14 05:32:32 +01:00
shader_set_uniform_f_array_safe(uniform_dim, [ww, hh]);
shader_set_uniform_f_array_safe(uniform_map_dim, [mw, mh]);
shader_set_uniform_f_array_safe(uniform_position, _data[2]);
2022-01-13 05:24:03 +01:00
shader_set_uniform_f(uniform_strength, _data[3]);
shader_set_uniform_f(uniform_mid, _data[4]);
shader_set_uniform_i(uniform_rg, _data[5]);
shader_set_uniform_i(uniform_it, _data[6]);
2023-06-13 14:42:06 +02:00
shader_set_uniform_i(uniform_sam, struct_try_get(attributes, "oversample"));
2022-01-13 05:24:03 +01:00
draw_surface_safe(_data[0], 0, 0);
2023-03-21 03:01:53 +01:00
surface_reset_shader();
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
_outSurf = mask_apply(_data[0], _outSurf, _data[8], _data[9]);
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
}