Blender 2.8 - 4.5 Support
This commit is contained in:
@ -76,7 +76,7 @@ def parse_addshader(node: bpy.types.ShaderNodeAddShader, out_socket: NodeSocket,
|
||||
state.out_ior = '({0} * 0.5 + {1} * 0.5)'.format(ior1, ior2)
|
||||
|
||||
|
||||
if bpy.app.version < (3, 0, 0):
|
||||
if bpy.app.version < (2, 92, 0):
|
||||
def parse_bsdfprincipled(node: bpy.types.ShaderNodeBsdfPrincipled, out_socket: NodeSocket, state: ParserState) -> None:
|
||||
if state.parse_surface:
|
||||
c.write_normal(node.inputs[20])
|
||||
@ -84,18 +84,20 @@ if bpy.app.version < (3, 0, 0):
|
||||
state.out_metallic = c.parse_value_input(node.inputs[4])
|
||||
state.out_specular = c.parse_value_input(node.inputs[5])
|
||||
state.out_roughness = c.parse_value_input(node.inputs[7])
|
||||
if (node.inputs['Emission Strength'].is_linked or node.inputs['Emission Strength'].default_value != 0.0)\
|
||||
and (node.inputs['Emission'].is_linked or not mat_utils.equals_color_socket(node.inputs['Emission'], (0.0, 0.0, 0.0), comp_alpha=False)):
|
||||
if node.inputs['Emission'].is_linked or not mat_utils.equals_color_socket(node.inputs['Emission'], (0.0, 0.0, 0.0), comp_alpha=False):
|
||||
emission_col = c.parse_vector_input(node.inputs[17])
|
||||
emission_strength = c.parse_value_input(node.inputs[18])
|
||||
state.out_emission_col = '({0} * {1})'.format(emission_col, emission_strength)
|
||||
state.out_emission_col = emission_col
|
||||
mat_state.emission_type = mat_state.EmissionType.SHADED
|
||||
else:
|
||||
mat_state.emission_type = mat_state.EmissionType.NO_EMISSION
|
||||
if state.parse_opacity:
|
||||
state.out_ior = c.parse_value_input(node.inputs[14])
|
||||
state.out_opacity = c.parse_value_input(node.inputs[19])
|
||||
if bpy.app.version >= (3, 0, 0) and bpy.app.version <= (4, 1, 0):
|
||||
# In Blender 2.83, Alpha socket is at index 18, not 19
|
||||
if 'Alpha' in node.inputs:
|
||||
state.out_opacity = c.parse_value_input(node.inputs['Alpha'])
|
||||
else:
|
||||
state.out_opacity = '1.0'
|
||||
if bpy.app.version >= (2, 92, 0) and bpy.app.version <= (4, 1, 0):
|
||||
def parse_bsdfprincipled(node: bpy.types.ShaderNodeBsdfPrincipled, out_socket: NodeSocket, state: ParserState) -> None:
|
||||
if state.parse_surface:
|
||||
c.write_normal(node.inputs[22])
|
||||
|
@ -1,4 +1,4 @@
|
||||
from typing import Any, Callable, Optional
|
||||
from typing import Any, Callable, Dict, List, Optional, TypeVar, Union
|
||||
|
||||
import bpy
|
||||
|
||||
@ -32,8 +32,8 @@ else:
|
||||
is_displacement = False
|
||||
|
||||
# User callbacks
|
||||
write_material_attribs: Optional[Callable[[dict[str, Any], shader.Shader], bool]] = None
|
||||
write_material_attribs_post: Optional[Callable[[dict[str, Any], shader.Shader], None]] = None
|
||||
write_material_attribs: Optional[Callable[[Dict[str, Any], shader.Shader], bool]] = None
|
||||
write_material_attribs_post: Optional[Callable[[Dict[str, Any], shader.Shader], None]] = None
|
||||
write_vertex_attribs: Optional[Callable[[shader.Shader], bool]] = None
|
||||
|
||||
|
||||
|
@ -169,58 +169,57 @@ def write(vert, particle_info=None, shadowmap=False):
|
||||
vert.write('float s = sin(p_angle);')
|
||||
vert.write('vec3 center = spos.xyz - p_location;')
|
||||
|
||||
match rotation_mode:
|
||||
case 'OB_X':
|
||||
vert.write('vec3 rz = vec3(center.y, -center.x, center.z);')
|
||||
vert.write('vec2 rotation = vec2(rz.y * c - rz.z * s, rz.y * s + rz.z * c);')
|
||||
vert.write('spos.xyz = vec3(rz.x, rotation.x, rotation.y) + p_location;')
|
||||
if rotation_mode == 'OB_X':
|
||||
vert.write('vec3 rz = vec3(center.y, -center.x, center.z);')
|
||||
vert.write('vec2 rotation = vec2(rz.y * c - rz.z * s, rz.y * s + rz.z * c);')
|
||||
vert.write('spos.xyz = vec3(rz.x, rotation.x, rotation.y) + p_location;')
|
||||
|
||||
if (not shadowmap):
|
||||
vert.write('wnormal = vec3(wnormal.y, -wnormal.x, wnormal.z);')
|
||||
vert.write('vec2 n_rot = vec2(wnormal.y * c - wnormal.z * s, wnormal.y * s + wnormal.z * c);')
|
||||
vert.write('wnormal = normalize(vec3(wnormal.x, n_rot.x, n_rot.y));')
|
||||
case 'OB_Y':
|
||||
vert.write('vec2 rotation = vec2(center.x * c + center.z * s, -center.x * s + center.z * c);')
|
||||
vert.write('spos.xyz = vec3(rotation.x, center.y, rotation.y) + p_location;')
|
||||
if (not shadowmap):
|
||||
vert.write('wnormal = vec3(wnormal.y, -wnormal.x, wnormal.z);')
|
||||
vert.write('vec2 n_rot = vec2(wnormal.y * c - wnormal.z * s, wnormal.y * s + wnormal.z * c);')
|
||||
vert.write('wnormal = normalize(vec3(wnormal.x, n_rot.x, n_rot.y));')
|
||||
elif rotation_mode == 'OB_Y':
|
||||
vert.write('vec2 rotation = vec2(center.x * c + center.z * s, -center.x * s + center.z * c);')
|
||||
vert.write('spos.xyz = vec3(rotation.x, center.y, rotation.y) + p_location;')
|
||||
|
||||
if (not shadowmap):
|
||||
vert.write('wnormal = normalize(vec3(wnormal.x * c + wnormal.z * s, wnormal.y, -wnormal.x * s + wnormal.z * c));')
|
||||
case 'OB_Z':
|
||||
vert.write('vec3 rz = vec3(center.y, -center.x, center.z);')
|
||||
vert.write('vec3 ry = vec3(-rz.z, rz.y, rz.x);')
|
||||
vert.write('vec2 rotation = vec2(ry.x * c - ry.y * s, ry.x * s + ry.y * c);')
|
||||
vert.write('spos.xyz = vec3(rotation.x, rotation.y, ry.z) + p_location;')
|
||||
if (not shadowmap):
|
||||
vert.write('wnormal = normalize(vec3(wnormal.x * c + wnormal.z * s, wnormal.y, -wnormal.x * s + wnormal.z * c));')
|
||||
elif rotation_mode == 'OB_Z':
|
||||
vert.write('vec3 rz = vec3(center.y, -center.x, center.z);')
|
||||
vert.write('vec3 ry = vec3(-rz.z, rz.y, rz.x);')
|
||||
vert.write('vec2 rotation = vec2(ry.x * c - ry.y * s, ry.x * s + ry.y * c);')
|
||||
vert.write('spos.xyz = vec3(rotation.x, rotation.y, ry.z) + p_location;')
|
||||
|
||||
if (not shadowmap):
|
||||
vert.write('wnormal = vec3(wnormal.y, -wnormal.x, wnormal.z);')
|
||||
vert.write('wnormal = vec3(-wnormal.z, wnormal.y, wnormal.x);')
|
||||
vert.write('vec2 n_rot = vec2(wnormal.x * c - wnormal.y * s, wnormal.x * s + wnormal.y * c);')
|
||||
vert.write('wnormal = normalize(vec3(n_rot.x, n_rot.y, wnormal.z));')
|
||||
case 'VEL':
|
||||
vert.write('vec3 forward = -normalize(p_velocity);')
|
||||
vert.write('if (length(forward) > 1e-5) {')
|
||||
vert.write('vec3 world_up = vec3(0.0, 0.0, 1.0);')
|
||||
if (not shadowmap):
|
||||
vert.write('wnormal = vec3(wnormal.y, -wnormal.x, wnormal.z);')
|
||||
vert.write('wnormal = vec3(-wnormal.z, wnormal.y, wnormal.x);')
|
||||
vert.write('vec2 n_rot = vec2(wnormal.x * c - wnormal.y * s, wnormal.x * s + wnormal.y * c);')
|
||||
vert.write('wnormal = normalize(vec3(n_rot.x, n_rot.y, wnormal.z));')
|
||||
elif rotation_mode == 'VEL':
|
||||
vert.write('vec3 forward = -normalize(p_velocity);')
|
||||
vert.write('if (length(forward) > 1e-5) {')
|
||||
vert.write('vec3 world_up = vec3(0.0, 0.0, 1.0);')
|
||||
|
||||
vert.write('if (abs(dot(forward, world_up)) > 0.999) {')
|
||||
vert.write('world_up = vec3(-1.0, 0.0, 0.0);')
|
||||
vert.write('}')
|
||||
vert.write('if (abs(dot(forward, world_up)) > 0.999) {')
|
||||
vert.write('world_up = vec3(-1.0, 0.0, 0.0);')
|
||||
vert.write('}')
|
||||
|
||||
vert.write('vec3 right = cross(world_up, forward);')
|
||||
vert.write('if (length(right) < 1e-5) {')
|
||||
vert.write('forward = -forward;')
|
||||
vert.write('right = cross(world_up, forward);')
|
||||
vert.write('}')
|
||||
vert.write('right = normalize(right);')
|
||||
vert.write('vec3 up = normalize(cross(forward, right));')
|
||||
vert.write('vec3 right = cross(world_up, forward);')
|
||||
vert.write('if (length(right) < 1e-5) {')
|
||||
vert.write('forward = -forward;')
|
||||
vert.write('right = cross(world_up, forward);')
|
||||
vert.write('}')
|
||||
vert.write('right = normalize(right);')
|
||||
vert.write('vec3 up = normalize(cross(forward, right));')
|
||||
|
||||
vert.write('mat3 rot = mat3(right, -forward, up);')
|
||||
vert.write('mat3 phase = mat3(vec3(c, 0.0, -s), vec3(0.0, 1.0, 0.0), vec3(s, 0.0, c));')
|
||||
vert.write('mat3 final_rot = rot * phase;')
|
||||
vert.write('spos.xyz = final_rot * center + p_location;')
|
||||
vert.write('mat3 rot = mat3(right, -forward, up);')
|
||||
vert.write('mat3 phase = mat3(vec3(c, 0.0, -s), vec3(0.0, 1.0, 0.0), vec3(s, 0.0, c));')
|
||||
vert.write('mat3 final_rot = rot * phase;')
|
||||
vert.write('spos.xyz = final_rot * center + p_location;')
|
||||
|
||||
if (not shadowmap):
|
||||
vert.write('wnormal = normalize(final_rot * wnormal);')
|
||||
vert.write('}')
|
||||
if (not shadowmap):
|
||||
vert.write('wnormal = normalize(final_rot * wnormal);')
|
||||
vert.write('}')
|
||||
|
||||
if rotation_factor_random != 0:
|
||||
str_rotate_around = '''vec3 rotate_around(vec3 v, vec3 angle) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
from typing import Generator
|
||||
from typing import Generator, Tuple
|
||||
|
||||
import bpy
|
||||
|
||||
@ -101,7 +101,7 @@ def iter_nodes_leenkxpbr(node_group: bpy.types.NodeTree) -> Generator[bpy.types.
|
||||
yield node
|
||||
|
||||
|
||||
def equals_color_socket(socket: bpy.types.NodeSocketColor, value: tuple[float, ...], *, comp_alpha=True) -> bool:
|
||||
def equals_color_socket(socket: bpy.types.NodeSocketColor, value: Tuple[float, ...], *, comp_alpha=True) -> bool:
|
||||
# NodeSocketColor.default_value is of bpy_prop_array type that doesn't
|
||||
# support direct comparison
|
||||
return (
|
||||
|
@ -4,7 +4,7 @@ This module contains a list of all material nodes that Leenkx supports
|
||||
"""
|
||||
from enum import IntEnum, unique
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Callable, Optional
|
||||
from typing import Any, Callable, Optional, Dict, List, Tuple, TypeVar, Union
|
||||
|
||||
import bpy
|
||||
|
||||
@ -62,7 +62,7 @@ class MaterialNodeMeta:
|
||||
"""
|
||||
|
||||
|
||||
ALL_NODES: dict[str, MaterialNodeMeta] = {
|
||||
ALL_NODES: Dict[str, MaterialNodeMeta] = {
|
||||
# --- nodes_color
|
||||
'BRIGHTCONTRAST': MaterialNodeMeta(parse_func=nodes_color.parse_brightcontrast),
|
||||
'CURVE_RGB': MaterialNodeMeta(parse_func=nodes_color.parse_curvergb),
|
||||
|
Reference in New Issue
Block a user