Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python-envs.defaultEnvManager": "ms-python.python:system"
}
Comment on lines +1 to +3

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exclude this please

1 change: 0 additions & 1 deletion blender_bindings/material_loader/material_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def _initial_setup(cls, material: bpy.types.Material):
if material.get('source_loaded', False):
return False

material.use_nodes = True
material['source_loaded'] = True
material.use_nodes = True
cls._clean_nodes(material)
Expand Down
3 changes: 2 additions & 1 deletion blender_bindings/material_loader/shader_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class Nodes:
ShaderNodeRGBToBW = 'ShaderNodeRGBToBW'
ShaderNodeScript = 'ShaderNodeScript'
ShaderNodeSeparateHSV = 'ShaderNodeSeparateHSV'
ShaderNodeSeparateRGB = 'ShaderNodeSeparateRGB'
ShaderNodeSeparateColor = 'ShaderNodeSeparateColor'
ShaderNodeSeparateRGB = 'ShaderNodeSeparateColor'
ShaderNodeSeparateXYZ = 'ShaderNodeSeparateXYZ'
ShaderNodeShaderToRGB = 'ShaderNodeShaderToRGB'
ShaderNodeSqueeze = 'ShaderNodeSqueeze'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def create_nodes(self, material: bpy.types.Material, extra_parameters: dict[Extr
elif self.phongexponenttexture is not None:
phongexponenttexture_node = self.create_node(Nodes.ShaderNodeTexImage, '$phongexponenttexture')
phongexponenttexture_node.image = phongexponenttexture
phongexponenttexture_split_node = self.create_node(Nodes.ShaderNodeSeparateRGB)
phongexponenttexture_split_node = self.create_node(Nodes.ShaderNodeSeparateColor)
self.connect_nodes(phongexponenttexture_node.outputs['Color'],
phongexponenttexture_split_node.inputs['Image'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[Extra
elif self.phongexponenttexture is not None:
phongexponenttexture_node = self.create_node(Nodes.ShaderNodeTexImage, '$phongexponenttexture')
phongexponenttexture_node.image = phongexponenttexture
phongexponenttexture_split_node = self.create_node(Nodes.ShaderNodeSeparateRGB)
phongexponenttexture_split_node = self.create_node(Nodes.ShaderNodeSeparateColor)
self.connect_nodes(phongexponenttexture_node.outputs['Color'],
phongexponenttexture_split_node.inputs['Image'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[Extra
elif self.phongexponenttexture is not None:
phongexponenttexture_node = self.create_node(Nodes.ShaderNodeTexImage, '$phongexponenttexture')
phongexponenttexture_node.image = phongexponenttexture
phongexponenttexture_split_node = self.create_node(Nodes.ShaderNodeSeparateRGB)
phongexponenttexture_split_node = self.create_node(Nodes.ShaderNodeSeparateColor)
self.connect_nodes(phongexponenttexture_node.outputs['Color'],
phongexponenttexture_split_node.inputs['Image'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[Extra
elif self.phongexponenttexture is not None:
phongexponenttexture_node = self.create_node(Nodes.ShaderNodeTexImage, '$phongexponenttexture')
phongexponenttexture_node.image = phongexponenttexture
phongexponenttexture_split_node = self.create_node(Nodes.ShaderNodeSeparateRGB)
phongexponenttexture_split_node = self.create_node(Nodes.ShaderNodeSeparateColor)
self.connect_nodes(phongexponenttexture_node.outputs['Color'],
phongexponenttexture_split_node.inputs['Image'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[Extra
elif self.phongexponenttexture is not None:
phongexponenttexture_node = self.create_node(Nodes.ShaderNodeTexImage, '$phongexponenttexture')
phongexponenttexture_node.image = phongexponenttexture
phongexponenttexture_split_node = self.create_node(Nodes.ShaderNodeSeparateRGB)
phongexponenttexture_split_node = self.create_node(Nodes.ShaderNodeSeparateColor)
self.connect_nodes(phongexponenttexture_node.outputs['Color'],
phongexponenttexture_split_node.inputs['Image'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,46 @@ def basetexture(self):
return self.load_texture_or_default(texture_path, (0.3, 0, 0.3, 1.0))
return None

@property
def compress(self):
texture_path = self._vmt.get_string('$compress', None)
if texture_path is not None:
return self.load_texture_or_default(texture_path, (0.3, 0.0, 0.3, 1.0))
return None

@property
def stretch(self):
texture_path = self._vmt.get_string('$stretch', None)
if texture_path is not None:
return self.load_texture_or_default(texture_path, (0.3, 0.0, 0.3, 1.0))
return None

@property
def bumpcompress(self):
texture_path = self._vmt.get_string('$bumpcompress', None)
if texture_path is not None:
image = self.load_texture_or_default(texture_path, (0.5, 0.5, 1.0, 1.0))
if image == self.basetexture:
return image
image = self.convert_normalmap(image)
image.colorspace_settings.is_data = True
image.colorspace_settings.name = 'Non-Color'
return image
return None

@property
def bumpstretch(self):
texture_path = self._vmt.get_string('$bumpstretch', None)
if texture_path is not None:
image = self.load_texture_or_default(texture_path, (0.5, 0.5, 1.0, 1.0))
if image == self.basetexture:
return image
image = self.convert_normalmap(image)
image.colorspace_settings.is_data = True
image.colorspace_settings.name = 'Non-Color'
return image
return None

@property
def lightwarptexture(self):
texture_path = self._vmt.get_string('$lightwarptexture', None)
Expand Down Expand Up @@ -245,7 +285,7 @@ def phongtint(self):

def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[ExtraMaterialParameters, Any]):
sio_diffuse = None
selfillum = False
tension = None

# print(f"BVLG: {self.use_bvlg_status}")

Expand Down Expand Up @@ -322,6 +362,24 @@ def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[Extra

if self.detail:
albedo, detail = self.handle_detail(group_node.inputs['$basetexture [texture]'], albedo, uv_node=uv)
if self.compress and self.stretch:
attr = self.create_node(Nodes.ShaderNodeAttribute)
attr.attribute_name = 'tension'
tension = self.create_node(Nodes.ShaderNodeSeparateXYZ)
self.connect_nodes(attr.outputs[1], tension.inputs[0])
compress = self.create_texture_node(self.compress)
stretch = self.create_texture_node(self.stretch)
mix_default_compress = self.create_node(Nodes.ShaderNodeMixRGB)
mix_compress_stretch = self.create_node(Nodes.ShaderNodeMixRGB)

self.connect_nodes(tension.outputs[0], mix_default_compress.inputs[0])
self.connect_nodes(tension.outputs[1], mix_compress_stretch.inputs[0])
self.connect_nodes(albedo, mix_default_compress.inputs[1])
self.connect_nodes(compress.outputs[0], mix_default_compress.inputs[2])
self.connect_nodes(mix_default_compress.outputs[0], mix_compress_stretch.inputs[1])
self.connect_nodes(stretch.outputs[0], mix_compress_stretch.inputs[2])
self.connect_nodes(mix_compress_stretch.outputs[0], group_node.inputs['$basetexture [texture]'])

elif self.color:
group_node.inputs['$basetexture [texture]'].default_value = self.color

Expand All @@ -344,6 +402,24 @@ def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[Extra
elif self.normalmapalphaphongmask and not self.basemapalphaphongmask:
self.connect_nodes(bumpmap_node.outputs['Alpha'],
group_node.inputs['phongmask [bumpmap texture alpha]'])

if self.bumpcompress and self.bumpstretch:
if not tension:
attr = self.create_node(Nodes.ShaderNodeAttribute)
tension = self.create_node(Nodes.ShaderNodeSeparateXYZ)
self.connect_nodes(attr.outputs[1], tension.inputs[0])
compress = self.create_texture_node(self.bumpcompress)
stretch = self.create_texture_node(self.bumpstretch)
mix_default_compress = self.create_node(Nodes.ShaderNodeMixRGB)
mix_compress_stretch = self.create_node(Nodes.ShaderNodeMixRGB)

self.connect_nodes(tension.outputs[0], mix_default_compress.inputs[0])
self.connect_nodes(tension.outputs[1], mix_compress_stretch.inputs[0])
self.connect_nodes(bumpmap_node.outputs[0], mix_default_compress.inputs[1])
self.connect_nodes(compress.outputs[0], mix_default_compress.inputs[2])
self.connect_nodes(mix_default_compress.outputs[0], mix_compress_stretch.inputs[1])
self.connect_nodes(stretch.outputs[0], mix_compress_stretch.inputs[2])
self.connect_nodes(mix_compress_stretch.outputs[0], group_node.inputs['$bumpmap [texture]'])

if self.rimlight:
group_node.inputs['$rimlight [bool]'].default_value = self.rimlight
Expand Down Expand Up @@ -568,7 +644,7 @@ def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[Extra
elif self.phongexponenttexture is not None:
phongexponenttexture_node = self.create_node(Nodes.ShaderNodeTexImage, '$phongexponenttexture')
phongexponenttexture_node.image = phongexponenttexture
phongexponenttexture_split_node = self.create_node(Nodes.ShaderNodeSeparateRGB)
phongexponenttexture_split_node = self.create_node(Nodes.ShaderNodeSeparateColor)
self.connect_nodes(phongexponenttexture_node.outputs['Color'],
phongexponenttexture_split_node.inputs['Image'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[Extra
bs_socket2 = bs_node2.outputs[0]

if self.blendmodulatetexture != None:
SEPrgb = self.create_node(Nodes.ShaderNodeSeparateRGB)
SEPrgb = self.create_node(Nodes.ShaderNodeSeparateColor)
sub = self.create_node(Nodes.ShaderNodeMath)
sub.operation = 'SUBTRACT'
add = self.create_node(Nodes.ShaderNodeMath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[Extra
self.connect_nodes(transform_node.outputs[0], normal2_node.inputs[0])
self.connect_nodes(transform_node.outputs[0], mask_node.inputs[0])

split_mask = self.create_node(Nodes.ShaderNodeSeparateRGB)
split_mask = self.create_node(Nodes.ShaderNodeSeparateColor)
self.connect_nodes(mask_node.outputs[0], split_mask.inputs[0])
mask_output = split_mask.outputs[0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def create_nodes(self, material: bpy.types.Material, extra_parameters: dict[Extr

if self._have_texture("g_tHeight1"):
color_texture = self._get_texture("g_tHeight1", (1, 1, 1, 1), True)
split = self.create_node(Nodes.ShaderNodeSeparateRGB)
split = self.create_node(Nodes.ShaderNodeSeparateColor)
self.connect_nodes(color_texture.outputs[0], split.inputs[0])
self.connect_nodes(split.outputs[0], shader.inputs["V0"])

if self._have_texture("g_tHeight2"):
color_texture = self._get_texture("g_tHeight2", (1, 1, 1, 1), True)
split = self.create_node(Nodes.ShaderNodeSeparateRGB)
split = self.create_node(Nodes.ShaderNodeSeparateColor)
self.connect_nodes(color_texture.outputs[0], split.inputs[0])
self.connect_nodes(split.outputs[0], shader.inputs["V1"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[Extra
self.connect_nodes(normal_texture.outputs[1], shader.inputs["Roughness"])

# metalness_texture = self._get_texture("g_tMetalness", (1, 1, 1, 1), True)
# metalness_conv = self.create_node(Nodes.ShaderNodeSeparateRGB)
# metalness_conv = self.create_node(Nodes.ShaderNodeSeparateColor)
# self.connect_nodes(metalness_texture.outputs[0], metalness_conv.inputs[0])
# roughness_override = self._material_resource.get_vector_property("TextureNormal", None)
# if roughness_override is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[Extra
self.connect_nodes(normal_texture.outputs[1], shader.inputs["Specular"])

metalness_texture = self._get_texture("g_tMetalness", (1, 1, 1, 1), True)
metalness_conv = self.create_node(Nodes.ShaderNodeSeparateRGB)
metalness_conv = self.create_node(Nodes.ShaderNodeSeparateColor)
self.connect_nodes(metalness_texture.outputs[0], metalness_conv.inputs[0])
self.connect_nodes(metalness_conv.outputs[0], shader.inputs["Roughness"])
self.connect_nodes(metalness_conv.outputs[1], shader.inputs["Metallic"])
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[Extra
uv_mapping = self.setup_uv_transform(self.selfillum_texcoord_offset1, self.selfillum_texcoord_scale1)
if uv_mapping:
self.connect_nodes(uv_mapping.outputs[0], selfillum_mask_node.inputs[0])
split_node = self.create_node(Nodes.ShaderNodeSeparateRGB)
split_node = self.create_node(Nodes.ShaderNodeSeparateColor)
self.connect_nodes(selfillum_mask_node.outputs[0], split_node.inputs[0])
if self.selfillum_scale == 1.0:
self.connect_nodes(split_node.outputs[0], shader.inputs["Emission Strength"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def create_nodes(self, material: bpy.types.Material, extra_parameters: dict[Extr
tint_mask_output = None
if self._check_flag("F_TINT_MASK"):
tint_mask_node = self._get_texture("g_tTintMask", (1.0, 1.0, 1.0, 1.0), True)
split_rgb_node = self.create_node(Nodes.ShaderNodeSeparateRGB)
split_rgb_node = self.create_node(Nodes.ShaderNodeSeparateColor)
self.connect_nodes(tint_mask_node.outputs['Color'], split_rgb_node.inputs[0])
tint_mask_output = split_rgb_node.outputs[0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def create_nodes(self, material:bpy.types.Material, extra_parameters: dict[Extra
tint_mask_output = None
if self._check_flag("F_TINT_MASK"):
tint_mask_node = self._get_texture("g_tTintMask", (1.0, 1.0, 1.0, 1.0), True)
split_rgb_node = self.create_node(Nodes.ShaderNodeSeparateRGB)
split_rgb_node = self.create_node(Nodes.ShaderNodeSeparateColor)
self.connect_nodes(tint_mask_node.outputs['Color'], split_rgb_node.inputs[0])
tint_mask_output = split_rgb_node.outputs[0]

Expand Down
Loading