Merge pull request #1949 from MoritzBrueckner/clamp-node
Implement cycles clamp node
This commit is contained in:
commit
343d22e47a
|
@ -425,6 +425,7 @@ def parse_value(node, socket):
|
|||
'TEX_WAVE': nodes_texture.parse_tex_wave,
|
||||
'LIGHT_FALLOFF': nodes_color.parse_lightfalloff,
|
||||
'NORMAL': nodes_vector.parse_normal,
|
||||
'CLAMP': nodes_converter.parse_clamp,
|
||||
'VALTORGB': nodes_converter.parse_valtorgb,
|
||||
'MATH': nodes_converter.parse_math,
|
||||
'RGBTOBW': nodes_converter.parse_rgbtobw,
|
||||
|
|
|
@ -2,6 +2,7 @@ from typing import Union
|
|||
|
||||
import bpy
|
||||
|
||||
import arm.log as log
|
||||
import arm.material.cycles as c
|
||||
import arm.material.cycles_functions as c_functions
|
||||
from arm.material.parser_state import ParserState
|
||||
|
@ -75,6 +76,23 @@ def parse_blackbody(node: bpy.types.ShaderNodeBlackbody, out_socket: bpy.types.N
|
|||
return c.to_vec3([rgb[0], rgb[1], rgb[2]])
|
||||
|
||||
|
||||
def parse_clamp(node: bpy.types.ShaderNodeClamp, out_socket: bpy.types.NodeSocket, state: ParserState) -> floatstr:
|
||||
value = c.parse_value_input(node.inputs['Value'])
|
||||
minVal = c.parse_value_input(node.inputs['Min'])
|
||||
maxVal = c.parse_value_input(node.inputs['Max'])
|
||||
|
||||
if node.clamp_type == 'MINMAX':
|
||||
# Condition is minVal < maxVal, otherwise use 'RANGE' type
|
||||
return f'clamp({value}, {minVal}, {maxVal})'
|
||||
|
||||
elif node.clamp_type == 'RANGE':
|
||||
return f'{minVal} < {maxVal} ? clamp({value}, {minVal}, {maxVal}) : clamp({value}, {maxVal}, {minVal})'
|
||||
|
||||
else:
|
||||
log.warn(f'Clamp node: unsupported clamp type {node.clamp_type}.')
|
||||
return value
|
||||
|
||||
|
||||
def parse_valtorgb(node: bpy.types.ShaderNodeValToRGB, out_socket: bpy.types.NodeSocket, state: ParserState) -> Union[floatstr, vec3str]:
|
||||
# Alpha (TODO: make ColorRamp calculation vec4-based and split afterwards)
|
||||
if out_socket == node.outputs[1]:
|
||||
|
|
Loading…
Reference in a new issue