Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2018-03-10 18:09:22 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2018-03-10 20:05:01 +0300
commit7613ffc944ebc133f1f906ea737ab55718434cc4 (patch)
treee2c54a4b971fe955f4c7538db1fc086a997b8702 /intern/cycles/blender
parent8a76f8dac3475b1d24956e0d384d65295f15c76a (diff)
Cycles: switch to squared roughness convention for all nodes.
This was already done for the Principled BSDF to be compatible with typical baked roughness maps in PBR workflows.
Diffstat (limited to 'intern/cycles/blender')
-rw-r--r--intern/cycles/blender/addon/version_update.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/intern/cycles/blender/addon/version_update.py b/intern/cycles/blender/addon/version_update.py
index 90cecec215d..292f0a1fa90 100644
--- a/intern/cycles/blender/addon/version_update.py
+++ b/intern/cycles/blender/addon/version_update.py
@@ -17,6 +17,7 @@
# <pep8 compliant>
import bpy
+import math
from bpy.app.handlers import persistent
@@ -138,6 +139,56 @@ def displacement_principled_nodes(node):
if node.subsurface_method != 'RANDOM_WALK':
node.subsurface_method = 'BURLEY'
+def square_roughness_node_insert(material, nodetree, traversed):
+ if nodetree in traversed:
+ return
+ traversed.add(nodetree)
+
+ roughness_node_types = {
+ 'ShaderNodeBsdfAnisotropic',
+ 'ShaderNodeBsdfGlass',
+ 'ShaderNodeBsdfGlossy',
+ 'ShaderNodeBsdfRefraction'}
+
+ # Update default values
+ for node in nodetree.nodes:
+ if node.bl_idname == 'ShaderNodeGroup':
+ square_roughness_node_insert(material, node.node_tree, traversed)
+ elif node.bl_idname in roughness_node_types:
+ roughness_input = node.inputs['Roughness']
+ roughness_input.default_value = math.sqrt(max(roughness_input.default_value, 0.0))
+
+ # Gather roughness links to replace
+ roughness_links = []
+ for link in nodetree.links:
+ if link.to_node.bl_idname in roughness_node_types and \
+ link.to_socket.identifier == 'Roughness':
+ roughness_links.append(link)
+
+ # Replace links with sqrt node
+ for link in roughness_links:
+ from_node = link.from_node
+ from_socket = link.from_socket
+ to_node = link.to_node
+ to_socket = link.to_socket
+
+ nodetree.links.remove(link)
+
+ node = nodetree.nodes.new(type='ShaderNodeMath')
+ node.operation = 'POWER'
+ node.location[0] = 0.5 * (from_node.location[0] + to_node.location[0]);
+ node.location[1] = 0.5 * (from_node.location[1] + to_node.location[1]);
+
+ nodetree.links.new(from_socket, node.inputs[0])
+ node.inputs[1].default_value = 0.5
+ nodetree.links.new(node.outputs['Value'], to_socket)
+
+def square_roughness_nodes_insert():
+ traversed = set()
+ for material in bpy.data.materials:
+ if check_is_new_shading_material(material):
+ square_roughness_node_insert(material, material.node_tree, traversed)
+
def mapping_node_order_flip(node):
"""
@@ -376,3 +427,7 @@ def do_versions(self):
cmat.displacement_method = 'BUMP'
foreach_cycles_node(displacement_principled_nodes)
+
+ if bpy.data.version <= (2, 79, 3):
+ # Switch to squared roughness convention
+ square_roughness_nodes_insert()