Pixel-Composer/scripts/node_3d_material/node_3d_material.gml

94 lines
2.4 KiB
Text
Raw Normal View History

2023-08-24 11:59:05 +02:00
function Node_3D_Material(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constructor {
name = "3D Material";
solid_surf = noone;
2024-08-18 09:13:41 +02:00
newInput(0, nodeValue_Surface("Texture", self))
2023-08-24 11:59:05 +02:00
.setVisible(true, true);
2024-08-18 09:13:41 +02:00
newInput(1, nodeValue_Float("Diffuse", self, 1 ))
.setDisplay(VALUE_DISPLAY.slider);
2023-08-24 11:59:05 +02:00
2024-08-18 09:13:41 +02:00
newInput(2, nodeValue_Float("Specular", self, 0 ))
.setDisplay(VALUE_DISPLAY.slider);
2023-08-24 11:59:05 +02:00
2024-08-18 06:16:20 +02:00
newInput(3, nodeValue_Float("Shininess", self, 1 ));
2023-08-24 11:59:05 +02:00
2024-08-18 06:16:20 +02:00
newInput(4, nodeValue_Bool("Metalic", self, false ));
2023-08-24 19:44:12 +02:00
2024-08-18 06:16:20 +02:00
newInput(5, nodeValue_Surface("Normal Map", self));
2023-08-24 19:44:12 +02:00
2024-08-18 09:13:41 +02:00
newInput(6, nodeValue_Float("Normal Strength", self, 1 ))
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 2, 0.01 ] });
2023-08-24 19:44:12 +02:00
2024-08-18 09:13:41 +02:00
newInput(7, nodeValue_Float("Roughness", self, 1 ))
.setDisplay(VALUE_DISPLAY.slider);
2023-08-24 11:59:05 +02:00
2024-08-18 06:16:20 +02:00
newInput(8, nodeValue_Bool("Anti aliasing", self, false ));
2023-11-28 09:42:22 +01:00
2024-10-05 02:49:33 +02:00
newInput(9, nodeValue_Vec2("Scale", self, [ 1, 1 ] ));
newInput(10, nodeValue_Vec2("Shift", self, [ 0, 0 ] ));
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Material", self, VALUE_TYPE.d3Material, noone));
2023-08-24 11:59:05 +02:00
2024-10-05 02:49:33 +02:00
input_display_list = [
["Texture", false], 0, 8, 9, 10,
2023-11-28 09:42:22 +01:00
["Properties", false], 1, 2, 3, 4, 7,
2024-10-05 02:49:33 +02:00
["Normal", false], 5, 6,
2023-08-24 19:44:12 +02:00
];
2023-08-24 11:59:05 +02:00
static processData = function(_output, _data, _output_index, _array_index = 0) {
var _surf = _data[0];
var _diff = _data[1];
var _spec = _data[2];
var _shin = _data[3];
var _metl = _data[4];
2023-08-24 19:44:12 +02:00
var _nor = _data[5];
var _norS = _data[6];
var _roug = _data[7];
2023-11-28 09:42:22 +01:00
var _aa = _data[8];
2024-10-05 02:49:33 +02:00
var _scal = _data[9];
var _shft = _data[10];
2023-08-24 11:59:05 +02:00
if(!is_surface(_surf)) {
solid_surf = surface_verify(solid_surf, 1, 1);
_surf = solid_surf;
}
var _mat = new __d3dMaterial(_surf);
_mat.diffuse = _diff;
_mat.specular = _spec;
_mat.shine = _shin;
_mat.metalic = _metl;
2023-11-28 09:42:22 +01:00
_mat.texFilter = _aa;
2024-10-05 02:49:33 +02:00
_mat.texScale = _scal;
_mat.texShift = _shft;
2023-08-24 11:59:05 +02:00
2023-08-24 19:44:12 +02:00
_mat.normal = _nor;
_mat.normalStr = _norS;
_mat.reflective = clamp(1 - _roug, 0, 1);
2023-08-24 11:59:05 +02:00
return _mat;
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
2023-11-27 11:40:28 +01:00
if(!previewable) return;
2023-08-24 11:59:05 +02:00
var bbox = drawGetBbox(xx, yy, _s);
2024-08-08 06:57:51 +02:00
var _mat = outputs[0].getValue();
2023-08-24 11:59:05 +02:00
if(_mat == noone) return;
2023-08-24 11:59:05 +02:00
if(is_array(_mat)) {
if(array_empty(_mat)) return;
_mat = _mat[0];
}
2023-11-27 11:40:28 +01:00
if(is_instanceof(_mat, __d3dMaterial) && is_surface(_mat.surface)) {
var aa = 0.5 + 0.5 * renderActive;
if(!isHighlightingInGraph()) aa *= 0.25;
draw_surface_bbox(_mat.surface, bbox,, aa);
}
2023-08-24 11:59:05 +02:00
}
}