Full BSDF

This commit is contained in:
2026-08-07 02:04:01 -07:00
parent 7aeebf2008
commit fe017dd874
55 changed files with 2306 additions and 1215 deletions

View File

@ -192,13 +192,27 @@ def parse(nodes, con: ShaderContext,
import re as _re
def _extract_vec3(s):
m = _re.match(r'vec3\s*\(\s*([^,\s\)]+)\s*\)', s)
if m and ',' not in m.group(1):
v = m.group(1)
return v, v, v
m = _re.match(r'vec3\s*\(\s*([^,\s]+)\s*,\s*([^,\s]+)\s*,\s*([^,\s\)]+)', s)
if m:
return m.group(1), m.group(2), m.group(3)
s = s.strip()
m = _re.match(r'vec3\s*\((.*)\)\s*$', s)
if not m:
return '1.0', '1.0', '1.0'
inner = m.group(1).strip()
parts = []
depth = 0
start = 0
for i, ch in enumerate(inner):
if ch == '(':
depth += 1
elif ch == ')':
depth -= 1
elif ch == ',' and depth == 0:
parts.append(inner[start:i].strip())
start = i + 1
parts.append(inner[start:].strip())
if len(parts) == 1:
return parts[0], parts[0], parts[0]
if len(parts) == 3:
return parts[0], parts[1], parts[2]
return '1.0', '1.0', '1.0'
def _try_float(val_str, default=0.0):
@ -209,14 +223,10 @@ def parse(nodes, con: ShaderContext,
_sss_r, _sss_g, _sss_b = _extract_vec3(state.out_subsurface_radius)
_sss_scale = state.out_subsurface_scale
_sss_scale_f = _try_float(_sss_scale, 0.05)
if _sss_scale_f != 1.0:
_sss_r = str(_try_float(_sss_r, 1.0) * _sss_scale_f)
_sss_g = str(_try_float(_sss_g, 0.2) * _sss_scale_f)
_sss_b = str(_try_float(_sss_b, 0.1) * _sss_scale_f)
_sheen_tint_r, _sheen_tint_g, _sheen_tint_b = _extract_vec3(state.out_sheen_tint)
_coat_tint_r, _coat_tint_g, _coat_tint_b = _extract_vec3(state.out_coat_tint)
_spec_tint_r, _spec_tint_g, _spec_tint_b = _extract_vec3(state.out_specular_tint)
_sss_color_r, _sss_color_g, _sss_color_b = _extract_vec3(state.out_subsurface_color)
mat_state.features = {
@ -233,6 +243,7 @@ def parse(nodes, con: ShaderContext,
'sheenTintB': _sheen_tint_b,
'subsurface': state.out_subsurface,
'subsurfaceAnisotropy': state.out_subsurface_anisotropy,
'subsurfaceScale': _sss_scale,
'subsurfaceRadiusR': _sss_r,
'subsurfaceRadiusG': _sss_g,
'subsurfaceRadiusB': _sss_b,
@ -245,6 +256,9 @@ def parse(nodes, con: ShaderContext,
'transmissionRough': state.out_transmission_rough,
'ior': state.out_ior,
'thinWall': state.out_thin_wall,
'specularTintR': _spec_tint_r,
'specularTintG': _spec_tint_g,
'specularTintB': _spec_tint_b,
}
state = None
@ -751,11 +765,11 @@ def vector_curve(name, fac, points):
# Map vector
return 'mix({0}[{1}], {0}[{1} + 1], ({2} - {3}[{1}]) * (1.0 / ({3}[{1} + 1] - {3}[{1}]) ))'.format(ys_var, index_var, fac_var, facs_var)
def write_normal(inp):
def write_normal(inp, target_var='n'):
if inp.is_linked and inp.links[0].from_node.type != 'GROUP_INPUT':
normal_res = parse_vector_input(inp)
if normal_res != None:
state.curshader.write('n = {0};'.format(normal_res))
state.curshader.write('{0} = {1};'.format(target_var, normal_res))
def is_parsed(node_store_name: str):