-- Create a mix material diffuse/glossy for organic materials liche leaves and grass. -- -- @description Create a mix-organic material from an RGBA Image -- @author Beppe Gullotta -- @version 0.6 -- This script create a node-group with a mix, a diffuse and a glossy material -- with various imput nodes derived from a single RGBA textures. -- table with params for the "macro" node graph params = {} params.type = octane.GT_STANDARD params.name = "tex-name" params.position = {200, 200} -- creates the "macro" node graph, ie. root for all other nodes root = octane.nodegraph.create(params) -- creates some texture input modes and assign some names inColor1 = octane.node.create{type=octane.NT_IN_TEXTURE,name="Color", graphOwner=root, position={200, 100}} inColor2 = octane.node.create{type=octane.NT_IN_TEXTURE, name="Bump", graphOwner=root, position={450, 150}} inColor3 = octane.node.create{type=octane.NT_IN_TEXTURE, name="Trans-Color", graphOwner=root, position={300, 100}} inColor4 = octane.node.create{type=octane.NT_IN_TEXTURE, name="Specular", graphOwner=root, position={500, 100}} inColor5 = octane.node.create{type=octane.NT_IN_TEXTURE, name="Opacity", graphOwner=root, position={450, 200}} inColor6 = octane.node.create{type=octane.NT_IN_TEXTURE, name="Amount", graphOwner=root, position={350, 300}} inColor7 = octane.node.create{type=octane.NT_IN_TEXTURE, name="Roughness", graphOwner=root, position={550, 150}} -- choose an input RGBA file local result = octane.gui.showDialog { type = octane.gui.dialogType.FILE_DIALOG, title = "Choose the color texture with alpha channel", wildcards = "*.png; *.psd; *.tif; *.tga", save = false } -- creates an image texture node for diffuse channel inColor1Node = octane.node.create{type= octane.NT_TEX_IMAGE, pinOwnerNode=inColor1, pinOwnerId=octane.P_INPUT} print("Loading texture: ", result.result) inColor1Node:setAttribute(octane.A_FILENAME, result.result) -- creates an image texture node for bump channel inColor2Node = octane.node.create{type= octane.NT_TEX_FLOATIMAGE, pinOwnerNode=inColor2, pinOwnerId=octane.P_INPUT} inColor2Node:setAttribute(octane.A_FILENAME, result.result) -- creates an image texture node for transmission channel inColor3Node = octane.node.create{type= octane.NT_TEX_IMAGE, pinOwnerNode=inColor3, pinOwnerId=octane.P_INPUT} inColor3Node:setAttribute(octane.A_FILENAME, result.result) -- creates an image texture node for specular channel inColor4Node = octane.node.create{type= octane.NT_TEX_FLOATIMAGE, pinOwnerNode=inColor4, pinOwnerId=octane.P_INPUT} inColor4Node:setAttribute(octane.A_FILENAME, result.result) -- creates an image texture node for opacity channel inColor5Node = octane.node.create{type= octane.NT_TEX_ALPHAIMAGE, pinOwnerNode=inColor5, pinOwnerId=octane.P_INPUT} inColor5Node:setAttribute(octane.A_FILENAME, result.result) -- creates an image texture node for roughness channel inColor7Node = octane.node.create{type= octane.NT_TEX_FLOATIMAGE, pinOwnerNode=inColor7, pinOwnerId=octane.P_INPUT} inColor7Node:setAttribute(octane.A_FILENAME, result.result) --set the name of the material as the name of the texture fileName = octane.file.getFileNameWithoutExtension(result.result) print (fileName) root : updateProperties{name=fileName} --crate the float node for the ammount channel inColor6Node = octane.node.create{type=octane.NT_TEX_FLOAT, pinOwnerNode=inColor6, pinOwnerId=octane.P_INPUT} -- change some attributes for the nodes inColor1Node:setPinValue(octane.P_POWER, {0.9, 0.9, 0.9}) inColor2Node:setPinValue(octane.P_POWER, {0.3, 0.3, 0.3}) inColor3Node:setPinValue(octane.P_GAMMA, 1.6) inColor4Node:setPinValue(octane.P_GAMMA, 1.6) inColor6Node:setAttribute(octane.A_VALUE, {0.5, 0.5, 0.5}) inColor7Node:setPinValue(octane.P_GAMMA, 3.2) -- creates the output pin, material type outMat = octane.node.create{type=octane.NT_OUT_MATERIAL, name=fileName, graphOwner=root, position={450, 350}} -- creates two materials and a material mix node diffuse = octane.node.create{type=octane.NT_MAT_DIFFUSE, name="Diffuse", graphOwner=root, position={300, 250}} glossy = octane.node.create{type=octane.NT_MAT_GLOSSY, name="Glossy", graphOwner=root, position={600, 250}} matMix = octane.node.create{type=octane.NT_MAT_MIX, name="MatMix", graphOwner=root, position={450, 300}} -- connects everything diffuse:connectTo(octane.P_DIFFUSE, inColor1) diffuse:connectTo(octane.P_TRANSMISSION, inColor3) diffuse:connectTo(octane.P_BUMP, inColor2) diffuse:connectTo(octane.P_OPACITY, inColor5) glossy:connectTo(octane.P_DIFFUSE, inColor1) glossy:connectTo(octane.P_BUMP, inColor2) glossy:connectTo(octane.P_SPECULAR, inColor4) glossy:connectTo(octane.P_ROUGHNESS, inColor7) glossy:connectTo(octane.P_OPACITY, inColor5) matMix:connectTo(octane.P_MATERIAL1, diffuse) matMix:connectTo(octane.P_MATERIAL2, glossy) matMix:connectTo(octane.P_AMOUNT, inColor6) outMat:connectTo(octane.P_INPUT, matMix) --reorganize all the nodes in the graph octane.nodegraph.unfold(root, false)