2023-02-28 09:43:01 +01:00
|
|
|
function Node_Shadow_Cast(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2023-01-25 06:49:00 +01:00
|
|
|
name = "Cast Shadow";
|
2024-06-28 08:40:21 +02:00
|
|
|
batch_output = false;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(0, nodeValue_Surface("Background", self));
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(1, nodeValue_Surface("Solid", self));
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(2, nodeValue_Vec2("Light Position", self, [ 0, 0 ]))
|
2023-01-17 08:11:55 +01:00
|
|
|
.setUnitRef(function(index) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _surf = getInputData(0);
|
2023-01-17 08:11:55 +01:00
|
|
|
if(is_array(_surf) && array_length(_surf) == 0)
|
|
|
|
return [1, 1];
|
|
|
|
|
|
|
|
if(is_array(_surf))
|
|
|
|
_surf = _surf[0];
|
|
|
|
|
|
|
|
if(!is_surface(_surf))
|
|
|
|
return [1, 1];
|
|
|
|
|
2024-03-02 10:08:44 +01:00
|
|
|
return [ surface_get_width_safe(_surf), surface_get_height_safe(_surf) ];
|
2023-01-17 08:11:55 +01:00
|
|
|
}, VALUE_UNIT.reference);
|
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(3, nodeValue_Float("Soft light radius", self, 1))
|
2023-10-02 08:57:44 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 2, 0.01] });
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(4, nodeValue_Int("Light density", self, 1))
|
2024-03-24 04:58:08 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [1, 16, 0.1] });
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-20 10:15:53 +02:00
|
|
|
newInput(5, nodeValue_Enum_Scroll("Light type", self, 0, [ new scrollItem("Point", s_node_shadow_type, 0),
|
|
|
|
new scrollItem("Sun", s_node_shadow_type, 1) ]));
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(6, nodeValue_Color("Ambient color", self, c_grey));
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(7, nodeValue_Color("Light color", self, c_white));
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(8, nodeValue_Float("Light radius", self, 16));
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(9, nodeValue_Bool("Render solid", self, true));
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(10, nodeValue_Bool("Use BG color", self, false, "If checked, background color will be used as shadow caster."));
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(11, nodeValue_Float("BG threshold", self, 0.1))
|
2023-10-02 08:57:44 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(12, nodeValue_Float("Light intensity", self, 1))
|
2023-10-02 08:57:44 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 2, 0.01] });
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(13, nodeValue_Int("Banding", self, 0))
|
2024-03-24 04:58:08 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 16, 0.1] });
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-08-20 10:15:53 +02:00
|
|
|
newInput(14, nodeValue_Enum_Scroll("Attenuation", self, 0, [ new scrollItem("Quadratic", s_node_curve, 0),
|
|
|
|
new scrollItem("Invert quadratic", s_node_curve, 1),
|
|
|
|
new scrollItem("Linear", s_node_curve, 2), ]))
|
2024-08-07 11:48:39 +02:00
|
|
|
.setTooltip("Control how light fade out over distance.");
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(15, nodeValue_Int("Ambient occlusion", self, 0))
|
2024-03-24 04:58:08 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 16, 0.1] });
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(16, nodeValue_Float("Ambient occlusion strength", self, 0.1))
|
2024-05-01 14:28:15 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 0.5, 0.001] });
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(17, nodeValue_Bool("Active", self, true));
|
2023-02-14 05:32:32 +01:00
|
|
|
active_index = 17;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[1] = nodeValue_Output("Light mask", self, VALUE_TYPE.surface, noone);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
|
|
|
input_display_list = [ 17,
|
2024-01-09 03:39:40 +01:00
|
|
|
["Surfaces", true], 0, 1,
|
|
|
|
["BG Shadow Caster", true, 10], 11,
|
2024-03-17 14:24:24 +01:00
|
|
|
["Light", false], 5, 12, 8, 2,
|
|
|
|
["Soft Light", false], 4, 3,
|
2024-01-09 03:39:40 +01:00
|
|
|
["Render", false], 13, 14, 7, 6, 9,
|
|
|
|
["Ambient Occlusion", false], 15, 16,
|
2023-01-17 08:11:55 +01:00
|
|
|
];
|
|
|
|
|
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-05-10 04:01:14 +02:00
|
|
|
PROCESSOR_OVERLAY_CHECK
|
|
|
|
|
2024-07-02 12:18:32 +02:00
|
|
|
var _hov = false;
|
2024-08-08 06:57:51 +02:00
|
|
|
var hv = inputs[2].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= hv;
|
|
|
|
if(array_length(current_data) != array_length(inputs)) return _hov;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
var _type = current_data[5];
|
|
|
|
if(_type == 0) {
|
|
|
|
var pos = current_data[2];
|
|
|
|
var px = _x + pos[0] * _s;
|
|
|
|
var py = _y + pos[1] * _s;
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var hv = inputs[8].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny, 0, 1 / 4); _hov |= hv;
|
2023-01-17 08:11:55 +01:00
|
|
|
}
|
2024-07-02 12:18:32 +02:00
|
|
|
|
|
|
|
return _hov;
|
2023-01-17 08:11:55 +01:00
|
|
|
}
|
|
|
|
|
2023-08-17 16:56:54 +02:00
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) {
|
2023-01-17 08:11:55 +01:00
|
|
|
var _bg = _data[0];
|
|
|
|
var _solid = _data[1];
|
|
|
|
var _pos = _data[2];
|
|
|
|
var _rad = _data[3];
|
|
|
|
var _den = _data[4];
|
|
|
|
var _type = _data[5];
|
|
|
|
var _lamb = _data[6];
|
|
|
|
var _lclr = _data[7];
|
|
|
|
var _lrad = _data[8];
|
|
|
|
var _sol = _data[9];
|
2023-01-25 06:49:00 +01:00
|
|
|
var _int = _data[12];
|
|
|
|
var _band = _data[13];
|
|
|
|
var _attn = _data[14];
|
|
|
|
var _ao = _data[15];
|
|
|
|
var _ao_str= _data[16];
|
|
|
|
|
|
|
|
var _bg_use = _data[10];
|
|
|
|
var _bg_thr = _data[11];
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[8].setVisible(_type == 0);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
if(!is_surface(_bg)) return _outSurf;
|
2024-06-24 13:49:54 +02:00
|
|
|
|
2024-01-09 03:39:40 +01:00
|
|
|
surface_set_shader(_outSurf, sh_shadow_cast);
|
|
|
|
shader_set_f("dimension", surface_get_width_safe(_bg), surface_get_height_safe(_bg));
|
2024-06-24 13:49:54 +02:00
|
|
|
shader_set_2("lightPos", _pos);
|
2024-01-09 03:39:40 +01:00
|
|
|
shader_set_color("lightAmb", _lamb);
|
|
|
|
shader_set_color("lightClr", _lclr);
|
|
|
|
shader_set_f("lightRadius", _rad);
|
|
|
|
shader_set_f("pointLightRadius", _lrad);
|
|
|
|
shader_set_f("lightDensity", _den);
|
|
|
|
shader_set_i("lightType", _type);
|
|
|
|
shader_set_i("renderSolid", _sol);
|
|
|
|
shader_set_f("lightInt", _int);
|
|
|
|
shader_set_f("lightBand", _band);
|
|
|
|
shader_set_f("lightAttn", _attn);
|
|
|
|
shader_set_f("ao", _ao);
|
|
|
|
shader_set_f("aoStr", _ao_str);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-01-09 03:39:40 +01:00
|
|
|
shader_set_i("mask", _output_index);
|
|
|
|
shader_set_i("bgUse", _bg_use);
|
|
|
|
shader_set_f("bgThres", _bg_thr);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-01-09 03:39:40 +01:00
|
|
|
shader_set_i("useSolid", is_surface(_solid));
|
|
|
|
shader_set_surface("solid", _solid);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-01-09 03:39:40 +01:00
|
|
|
draw_surface_safe(_bg);
|
|
|
|
surface_reset_shader();
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
return _outSurf;
|
|
|
|
}
|
|
|
|
}
|