From d69d899f60e4d15f1005a5c8fcddb24e2f3793aa Mon Sep 17 00:00:00 2001 From: Lubos Lenco Date: Wed, 3 Jun 2020 18:35:49 +0200 Subject: [PATCH] Implement material node --- .../nodelib/Sources/arm/node/Material.hx | 52 +++++++++++++++---- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/Libraries/nodelib/Sources/arm/node/Material.hx b/Libraries/nodelib/Sources/arm/node/Material.hx index 7d4a0565..2a6ee53f 100644 --- a/Libraries/nodelib/Sources/arm/node/Material.hx +++ b/Libraries/nodelib/Sources/arm/node/Material.hx @@ -708,19 +708,33 @@ class Material { return "vVecCam"; } else if (node.type == "LAYER") { + var l = node.buttons[0].default_value; if (socket == node.outputs[0]) { // Base - var l = node.buttons[0].default_value; curshader.add_uniform("sampler2D texpaint", "_texpaint" + l); return "texture(texpaint, texCoord).rgb"; } else if (socket == node.outputs[5]) { // Normal - var l = node.buttons[0].default_value; curshader.add_uniform("sampler2D texpaint_nor", "_texpaint_nor" + l); return "texture(texpaint_nor, texCoord).rgb"; } } else if (node.type == "MATERIAL") { - return "vec3(0.0, 0.0, 0.0)"; + var m = Project.materials[node.buttons[0].default_value]; + var _nodes = nodes; + var _links = links; + nodes = m.canvas.nodes; + links = m.canvas.links; + var output_node = node_by_type(nodes, "OUTPUT_MATERIAL_PBR"); + var result = "vec3(0.0, 0.0, 0.0)"; + if (socket == node.outputs[0]) { // Base + result = parse_vector_input(output_node.inputs[0]); + } + else if (socket == node.outputs[5]) { // Normal + result = parse_vector_input(output_node.inputs[5]); + } + nodes = _nodes; + links = _links; + return result; } else if (node.type == "NEW_GEOMETRY") { if (socket == node.outputs[0]) { // Position @@ -994,28 +1008,24 @@ class Material { } } else if (node.type == "LAYER") { + var l = node.buttons[0].default_value; if (socket == node.outputs[1]) { // Opac - var l = node.buttons[0].default_value; curshader.add_uniform("sampler2D texpaint", "_texpaint" + l); return "texture(texpaint, texCoord).a"; } else if (socket == node.outputs[2]) { // Occ - var l = node.buttons[0].default_value; curshader.add_uniform("sampler2D texpaint_pack", "_texpaint_pack" + l); return "texture(texpaint_pack, texCoord).r"; } else if (socket == node.outputs[3]) { // Rough - var l = node.buttons[0].default_value; curshader.add_uniform("sampler2D texpaint_pack", "_texpaint_pack" + l); return "texture(texpaint_pack, texCoord).g"; } else if (socket == node.outputs[4]) { // Metal - var l = node.buttons[0].default_value; curshader.add_uniform("sampler2D texpaint_pack", "_texpaint_pack" + l); return "texture(texpaint_pack, texCoord).b"; } else if (socket == node.outputs[7]) { // Height - var l = node.buttons[0].default_value; curshader.add_uniform("sampler2D texpaint_pack", "_texpaint_pack" + l); return "texture(texpaint_pack, texCoord).a"; } @@ -1028,7 +1038,31 @@ class Material { } } else if (node.type == "MATERIAL") { - return "0.0"; + var m = Project.materials[node.buttons[0].default_value]; + var _nodes = nodes; + var _links = links; + nodes = m.canvas.nodes; + links = m.canvas.links; + var output_node = node_by_type(nodes, "OUTPUT_MATERIAL_PBR"); + var result = "0.0"; + if (socket == node.outputs[1]) { // Opac + result = parse_value_input(output_node.inputs[1]); + } + else if (socket == node.outputs[2]) { // Occ + result = parse_value_input(output_node.inputs[2]); + } + else if (socket == node.outputs[3]) { // Rough + result = parse_value_input(output_node.inputs[3]); + } + else if (socket == node.outputs[4]) { // Metal + result = parse_value_input(output_node.inputs[4]); + } + else if (socket == node.outputs[7]) { // Height + result = parse_value_input(output_node.inputs[7]); + } + nodes = _nodes; + links = _links; + return result; } else if (node.type == "FRESNEL") { var ior = parse_value_input(node.inputs[0]);