Pixel-Composer/scripts/node_3d_depth/node_3d_depth.gml

67 lines
2.1 KiB
Plaintext
Raw Normal View History

2023-07-14 20:34:35 +02:00
function Node_3D_Depth(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "3D Depth";
2024-08-08 06:57:51 +02:00
inputs[0] = nodeValue_Surface("Base Texture", self);
2023-07-14 20:34:35 +02:00
2024-08-08 06:57:51 +02:00
inputs[1] = nodeValue_Surface("Depth", self);
2023-07-14 20:34:35 +02:00
2024-08-12 13:42:05 +02:00
inputs[2] = nodeValue_Vec3("Rotation", self, [0, 0, 0] );
2023-07-14 20:34:35 +02:00
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
2023-07-14 20:34:35 +02:00
input_display_list = [
["Texture", false], 0, 1,
["Camera", false], 2,
];
attribute_surface_depth();
attribute_interpolation();
2023-08-17 16:56:54 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
2023-07-14 20:34:35 +02:00
var _tex = _data[0];
var _dep = _data[1];
var _rot = _data[2];
if(!is_surface(_tex)) return _outSurf;
if(!is_surface(_dep)) return _outSurf;
var x_rad = degtorad(_rot[0]);
var y_rad = degtorad(_rot[1]);
var z_rad = degtorad(_rot[2]);
var _cx = cos(y_rad) * cos(z_rad);
var _cy = (sin(x_rad) * sin(y_rad) * cos(z_rad) - cos(x_rad) * sin(z_rad));
var _cz = (cos(x_rad) * sin(y_rad) * cos(z_rad) + sin(x_rad) * sin(z_rad));
var up_x = -sin(x_rad);
var up_y = cos(x_rad);
var up_z = 0;
var right_x = cos(y_rad) * cos(z_rad);
var right_y = sin(x_rad) * sin(y_rad) * cos(z_rad) - cos(x_rad) * sin(z_rad);
var right_z = cos(x_rad) * sin(y_rad) * cos(z_rad) + sin(x_rad) * sin(z_rad);
2023-11-23 02:32:26 +01:00
//print($"POS: {_cx}, {_cy}, {_cz}");
//print($"UP: {up_x}, {up_y}, {up_z}");
//print($"RIGHT: {right_x}, {right_y}, {right_z}");
//print("");
2023-07-14 20:34:35 +02:00
surface_set_shader(_outSurf, sh_3d_depth);
DRAW_CLEAR
shader_set_surface("texMap", _tex);
2023-09-08 21:37:36 +02:00
shader_set_f("dimension", surface_get_width_safe(_tex), surface_get_height_safe(_tex));
2023-07-14 20:34:35 +02:00
shader_set_surface("depthMap", _dep);
2023-09-08 21:37:36 +02:00
shader_set_f("depthDimension", surface_get_width_safe(_dep), surface_get_height_safe(_dep));
2023-07-14 20:34:35 +02:00
shader_set_f("cameraPos", _cx, _cy, _cz);
shader_set_f("cameraUp", up_x, up_y, up_z);
shader_set_f("cameraRight", right_x, right_y, right_z);
2023-09-08 21:37:36 +02:00
draw_sprite_stretched(s_fx_pixel, 0, 0, 0, surface_get_width_safe(_tex), surface_get_height_safe(_tex));
2023-07-14 20:34:35 +02:00
surface_reset_shader();
return _outSurf;
}
}