Some times we need to make a render of the scene with the single material, for example, for clay or wireframe renders. Blender has the global materials override option for the Cycles render engine in the “View Layer Properties” – “Override” but not for the EEVEE render engine.
Quick materials override for the EEVEE rendering engine can be made with a small script, as shown in the following video:
Script and video by Vitaly Sokol.
The following script is used to make a quick global materials overriding system:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import bpy group_name = "GlobalMixer" mixer_name = "Overrider" MixerGlobalGroup = bpy.data.node_groups.get(group_name) # create a group if MixerGlobalGroup == None : test_group = bpy.data.node_groups.new(group_name, 'ShaderNodeTree') # create group inputs group_inputs = test_group.nodes.new('NodeGroupInput') group_inputs.location = (-200,0) test_group.inputs.new('NodeSocketShader','MainShader') # create group outputs group_outputs = test_group.nodes.new('NodeGroupOutput') group_outputs.location = (400,0) test_group.outputs.new('NodeSocketShader','MixedShader') # create three math nodes in a group node = test_group.nodes.new('ShaderNodeMixShader') node.location = (-200,-200) node.inputs[0].default_value = 1 node2 = test_group.nodes.new('ShaderNodeBsdfDiffuse') node.location = (200,100) # link inputs test_group.links.new(group_inputs.outputs['MainShader'], node.inputs[1]) #link output test_group.links.new(node.outputs[0], group_outputs.inputs['MixedShader']) test_group.links.new(node2.outputs[0], node.inputs[2]) MixerGlobalGroup = test_group print('Global MIxer Created:', MixerGlobalGroup) else: test_group = bpy.data.node_groups[group_name] print('Global MIxer Exists: ', test_group) ##################################################################################### # ADD A MIXER GROUP ##################################################################################### for mat in bpy.data.materials: nodes = mat.node_tree.nodes if nodes.get(mixer_name) == None: mixer = nodes.new(type="ShaderNodeGroup") mixer.node_tree = MixerGlobalGroup mixer.name = mixer_name mixer.location = (200,200) print(mixer_name," [created] ", mixer) else: print("....overrider already exists") mylinks = mat.node_tree.links matOut = nodes.get("Material Output") matInput = matOut.inputs mixerOut = nodes.get(mixer_name).outputs mixerIn = nodes.get(mixer_name).inputs old_link = matInput['Surface'].links[0].from_node if old_link.name != mixer_name: print("conected to: ",old_link.name) mylinks.new(mixerOut[0], matInput[0]) old_link = mylinks.new(mixerIn[0], old_link.outputs[0]) else: print("already connected to ", mixer_name) |
When executed, this script creates a node group and inserts it into each material before the “Material Output” node.
Any material before script execution:
The same material after script execution:
There is the “Diffuse” node linked to the “Mix” node and the external input linked to the same “Mix” node which translates the main object material into the node group. The “Diffuse” node is the shader that will override the main object material. Instead, you can create your own node combination to make the proper material for the override. But it should be located only inside this node group.
To start this working – replace the main object material with the material from the group, we just need to change the “Factor” value of the “Mix Shader” node from 0 to 1. The “Mix Shader” node works as a switcher: Factor = 0 – we render objects with their own materials, Factor = 1 – the single material of the group is used for all objects in the scene.
Switching the “Factor” value to 1, we will see that absolutely all objects in the scene change their materials from their own to the material of the group (Diffuse). This works because the node group works as an “instance” or “pointer” – its contents remain the same all the time, regardless of the material in which the node group is placed.
Since the script placed this node group in each material, we get the opportunity to easily replace all scene materials with the single material and back just changing the “Factor” value of the “Mix Shader” node inside the group.