def __get_edge_preview_shader(self): group_name = 'MMDEdgePreview' shader = bpy.data.node_groups.get(group_name, None) or bpy.data.node_groups.new(name=group_name, type='ShaderNodeTree') if len(shader.nodes): return shader ng = _NodeGroupUtils(shader) node_input = ng.new_node('NodeGroupInput', (-5, 0)) node_output = ng.new_node('NodeGroupOutput', (3, 0)) ############################################################################ node_color = ng.new_node('ShaderNodeMixRGB', (-1, -1.5)) node_color.mute = True ng.new_input_socket('Color', node_color.inputs['Color1']) if bpy.app.version < (2, 80, 0): node_geo = ng.new_node('ShaderNodeGeometry', (-2, -2.5)) node_cull = ng.new_math_node('MULTIPLY', (-1, -2.5)) ng.links.new(node_geo.outputs['Front/Back'], node_cull.inputs[1]) ng.new_input_socket('Alpha', node_cull.inputs[0]) ng.new_output_socket('Color', node_color.outputs['Color']) ng.new_output_socket('Alpha', node_cull.outputs['Value']) ############################################################################ node_ray = ng.new_node('ShaderNodeLightPath', (-3, 1.5)) node_geo = ng.new_node('ShaderNodeNewGeometry', (-3, 0)) node_max = ng.new_math_node('MAXIMUM', (-2, 1.5)) node_max.mute = True node_gt = ng.new_math_node('GREATER_THAN', (-1, 1)) node_alpha = ng.new_math_node('MULTIPLY', (0, 1)) node_trans = ng.new_node('ShaderNodeBsdfTransparent', (0, 0)) EDGE_NODE_NAME = 'ShaderNodeEmission' if bpy.app.version < (2, 80, 0) else 'ShaderNodeBackground' node_rgb = ng.new_node(EDGE_NODE_NAME, (0, -0.5)) # BsdfDiffuse/Background/Emission node_mix = ng.new_node('ShaderNodeMixShader', (1, 0.5)) links = ng.links links.new(node_ray.outputs['Is Camera Ray'], node_max.inputs[0]) links.new(node_ray.outputs['Is Glossy Ray'], node_max.inputs[1]) links.new(node_max.outputs['Value'], node_gt.inputs[0]) links.new(node_geo.outputs['Backfacing'], node_gt.inputs[1]) links.new(node_gt.outputs['Value'], node_alpha.inputs[0]) links.new(node_alpha.outputs['Value'], node_mix.inputs['Fac']) links.new(node_trans.outputs['BSDF'], node_mix.inputs[1]) links.new(node_rgb.outputs[0], node_mix.inputs[2]) links.new(node_color.outputs['Color'], node_rgb.inputs['Color']) ng.new_input_socket('Alpha', node_alpha.inputs[1]) ng.new_output_socket('Shader', node_mix.outputs['Shader']) return shader
def __get_shader_uv(self): group_name = 'MMDTexUV' shader = bpy.data.node_groups.get( group_name, None) or bpy.data.node_groups.new( name=group_name, type='ShaderNodeTree') if len(shader.nodes): return shader ng = _NodeGroupUtils(shader) ############################################################################ node_output = ng.new_node('NodeGroupOutput', (6, 0)) tex_coord = ng.new_node('ShaderNodeTexCoord', (0, 0)) if hasattr(bpy.types, 'ShaderNodeUVMap'): tex_coord1 = ng.new_node('ShaderNodeUVMap', (4, -2)) tex_coord1.uv_map, socketUV1 = 'UV1', 'UV' else: tex_coord1 = ng.new_node('ShaderNodeAttribute', (4, -2)) tex_coord1.attribute_name, socketUV1 = 'UV1', 'Vector' vec_trans = ng.new_node('ShaderNodeVectorTransform', (1, -1)) vec_trans.vector_type = 'NORMAL' vec_trans.convert_from = 'OBJECT' vec_trans.convert_to = 'CAMERA' node_vector = ng.new_node('ShaderNodeMapping', (2, -1)) node_vector.vector_type = 'POINT' if bpy.app.version < (2, 81, 0): node_vector.translation = (0.5, 0.5, 0.0) node_vector.scale = (0.5, 0.5, 1.0) else: node_vector.inputs['Location'].default_value = (0.5, 0.5, 0.0) node_vector.inputs['Scale'].default_value = (0.5, 0.5, 1.0) links = ng.links links.new(tex_coord.outputs['Normal'], vec_trans.inputs['Vector']) links.new(vec_trans.outputs['Vector'], node_vector.inputs['Vector']) ng.new_output_socket('Base UV', tex_coord.outputs['UV']) ng.new_output_socket('Toon UV', node_vector.outputs['Vector']) ng.new_output_socket('Sphere UV', node_vector.outputs['Vector']) ng.new_output_socket('SubTex UV', tex_coord1.outputs[socketUV1]) return shader
def __get_shader(self): group_name = 'MMDShaderDev' shader = bpy.data.node_groups.get(group_name, None) or bpy.data.node_groups.new(name=group_name, type='ShaderNodeTree') if len(shader.nodes): return shader ng = _NodeGroupUtils(shader) ############################################################################ node_input = ng.new_node('NodeGroupInput', (-5, -1)) node_output = ng.new_node('NodeGroupOutput', (11, 1)) node_diffuse = ng.new_mix_node('ADD', (-3, 4), fac=0.6) node_diffuse.use_clamp = True node_tex = ng.new_mix_node('MULTIPLY', (-2, 3.5)) node_toon = ng.new_mix_node('MULTIPLY', (-1, 3)) node_sph = ng.new_mix_node('MULTIPLY', (0, 2.5)) node_spa = ng.new_mix_node('ADD', (0, 1.5)) node_sphere = ng.new_mix_node('MIX', (1, 1)) node_geo = ng.new_node('ShaderNodeNewGeometry', (6, 3.5)) node_invert = ng.new_math_node('LESS_THAN', (7, 3)) node_cull = ng.new_math_node('MAXIMUM', (8, 2.5)) node_alpha = ng.new_math_node('MINIMUM', (9, 2)) node_alpha.use_clamp = True node_alpha_tex = ng.new_math_node('MULTIPLY', (-1, -2)) node_alpha_toon = ng.new_math_node('MULTIPLY', (0, -2.5)) node_alpha_sph = ng.new_math_node('MULTIPLY', (1, -3)) node_reflect = ng.new_math_node('DIVIDE', (7, -1.5), value1=1) node_reflect.use_clamp = True shader_diffuse = ng.new_node('ShaderNodeBsdfDiffuse', (8, 0)) shader_glossy = ng.new_node('ShaderNodeBsdfGlossy', (8, -1)) shader_base_mix = ng.new_node('ShaderNodeMixShader', (9, 0)) shader_base_mix.inputs['Fac'].default_value = 0.02 shader_trans = ng.new_node('ShaderNodeBsdfTransparent', (9, 1)) shader_alpha_mix = ng.new_node('ShaderNodeMixShader', (10, 1)) links = ng.links links.new(node_reflect.outputs['Value'], shader_glossy.inputs['Roughness']) links.new(shader_diffuse.outputs['BSDF'], shader_base_mix.inputs[1]) links.new(shader_glossy.outputs['BSDF'], shader_base_mix.inputs[2]) links.new(node_diffuse.outputs['Color'], node_tex.inputs['Color1']) links.new(node_tex.outputs['Color'], node_toon.inputs['Color1']) links.new(node_toon.outputs['Color'], node_sph.inputs['Color1']) links.new(node_toon.outputs['Color'], node_spa.inputs['Color1']) links.new(node_sph.outputs['Color'], node_sphere.inputs['Color1']) links.new(node_spa.outputs['Color'], node_sphere.inputs['Color2']) links.new(node_sphere.outputs['Color'], shader_diffuse.inputs['Color']) links.new(node_geo.outputs['Backfacing'], node_invert.inputs[0]) links.new(node_invert.outputs['Value'], node_cull.inputs[0]) links.new(node_cull.outputs['Value'], node_alpha.inputs[0]) links.new(node_alpha_tex.outputs['Value'], node_alpha_toon.inputs[0]) links.new(node_alpha_toon.outputs['Value'], node_alpha_sph.inputs[0]) links.new(node_alpha_sph.outputs['Value'], node_alpha.inputs[1]) links.new(node_alpha.outputs['Value'], shader_alpha_mix.inputs['Fac']) links.new(shader_trans.outputs['BSDF'], shader_alpha_mix.inputs[1]) links.new(shader_base_mix.outputs['Shader'], shader_alpha_mix.inputs[2]) ############################################################################ ng.new_input_socket('Ambient Color', node_diffuse.inputs['Color1'], (0.4, 0.4, 0.4, 1)) ng.new_input_socket('Diffuse Color', node_diffuse.inputs['Color2'], (0.8, 0.8, 0.8, 1)) ng.new_input_socket('Specular Color', shader_glossy.inputs['Color'], (0.8, 0.8, 0.8, 1)) ng.new_input_socket('Reflect', node_reflect.inputs[1], 50, min_max=(1, 512)) ng.new_input_socket('Base Tex Fac', node_tex.inputs['Fac'], 1) ng.new_input_socket('Base Tex', node_tex.inputs['Color2'], (1, 1, 1, 1)) ng.new_input_socket('Toon Tex Fac', node_toon.inputs['Fac'], 1) ng.new_input_socket('Toon Tex', node_toon.inputs['Color2'], (1, 1, 1, 1)) ng.new_input_socket('Sphere Tex Fac', node_sph.inputs['Fac'], 1) ng.new_input_socket('Sphere Tex', node_sph.inputs['Color2'], (1, 1, 1, 1)) ng.new_input_socket('Sphere Mul/Add', node_sphere.inputs['Fac'], 0) ng.new_input_socket('Double Sided', node_cull.inputs[1], 0, min_max=(0, 1)) ng.new_input_socket('Alpha', node_alpha_tex.inputs[0], 1, min_max=(0, 1)) ng.new_input_socket('Base Alpha', node_alpha_tex.inputs[1], 1, min_max=(0, 1)) ng.new_input_socket('Toon Alpha', node_alpha_toon.inputs[1], 1, min_max=(0, 1)) ng.new_input_socket('Sphere Alpha', node_alpha_sph.inputs[1], 1, min_max=(0, 1)) links.new(node_input.outputs['Sphere Tex Fac'], node_spa.inputs['Fac']) links.new(node_input.outputs['Sphere Tex'], node_spa.inputs['Color2']) ng.new_output_socket('Shader', shader_alpha_mix.outputs['Shader']) return shader
def __exposeNodeTreeOutput(out_socket, name, node_output, shader): _NodeGroupUtils(shader).new_output_socket(name, out_socket)
def __exposeNodeTreeInput(in_socket, name, default_value, node_input, shader): _NodeGroupUtils(shader).new_input_socket(name, in_socket, default_value)