Skip to content

Commit

Permalink
blender: Convert 5 more shader node types
Browse files Browse the repository at this point in the history
I need to come up with an approximation for Blender's Principled shader.
It's quite ubiquitous in modern scenes, c-ray doesn't support it
directly, but I cooked up a discrete node group using only c-ray
supported nodes, and it's a fairly close, but not perfect, match.
  • Loading branch information
vkoskiv committed Dec 17, 2023
1 parent 1eaff17 commit fcf763e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bindings/nodes/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def parse_vector(input):

def parse_node(input):
match input.bl_idname:
case 'NodeSocketShader':
if input.is_linked:
return parse_node(input.links[0].from_node)
return None
case 'ShaderNodeBsdfDiffuse':
color = parse_color(input.inputs['Color'])
return NodeShaderDiffuse(color) # note: missing roughness + normal
Expand All @@ -111,6 +115,25 @@ def parse_node(input):
pose = NodeVectorConstant(cr_vector(0.0, 0.0, 0.0))
strength = parse_value(input.inputs['Strength'])
return NodeShaderBackground(color, pose, strength)
case 'ShaderNodeMixShader':
factor = parse_value(input.inputs[0])
a = parse_node(input.inputs[1])
b = parse_node(input.inputs[2])
return NodeShaderMix(a, b, factor)
case 'ShaderNodeBsdfTransparent':
color = parse_color(input.inputs['Color'])
return NodeShaderTransparent(color)
case 'ShaderNodeBsdfTranslucent':
color = parse_color(input.inputs['Color'])
return NodeShaderTranslucent(color)
case 'ShaderNodeEmission':
color = parse_color(input.inputs['Color'])
strength = parse_value(input.inputs['Strength'])
return NodeShaderEmissive(color, strength)
case 'ShaderNodeAddShader':
a = parse_node(input.inputs[0])
b = parse_node(input.inputs[1])
return NodeShaderAdd(a, b)
case _:
print("Unknown shader node of type {}, maybe fix.".format(input.bl_idname))
return warning_shader
Expand Down

0 comments on commit fcf763e

Please sign in to comment.