Skip to content

Commit

Permalink
Merge pull request #121 from OpenSAGE/shaderFallback
Browse files Browse the repository at this point in the history
upgrade to NormalMapped.fx if material has a normal map
  • Loading branch information
Tarcontar authored Mar 11, 2020
2 parents 63047b2 + 7a4dd0c commit eebf452
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Binary file modified .coverage
Binary file not shown.
5 changes: 4 additions & 1 deletion io_mesh_w3d/common/utils/material_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ def retrieve_shader_material(context, material, principled, w3x=False):
append_property(shader_mat, 1, 'DiffuseTexture', principled.base_color_texture)

append_property(shader_mat, 1, 'NormalMap', principled.normalmap_texture)
if principled.normalmap_texture is not None:
if principled.normalmap_texture is not None and principled.normalmap_texture.image is not None:
if shader_mat.header.type_name == 'DefaultW3D.fx':
shader_mat.header.type_name = 'NormalMapped.fx'
append_property(shader_mat, 2, 'BumpScale', principled.normalmap_strength, 1.0)

append_property(shader_mat, 1, 'SpecMap', principled.specular_texture)
append_property(shader_mat, 7, 'CullingEnable', material.use_backface_culling)
append_property(shader_mat, 2, 'Opacity', material.opacity)
Expand Down
13 changes: 13 additions & 0 deletions tests/common/cases/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,26 @@ def test_shader_material_type_name_fallback(self):

for source in mesh.shader_materials:
source.header.type_name = 'LoremIpsum'
source.properties = []

(material, principled) = create_material_from_shader_material(
self, mesh.name(), source)
actual = retrieve_shader_material(self, material, principled)
source.header.type_name = 'DefaultW3D.fx'
compare_shader_materials(self, source, actual)

def test_shader_material_type_name_upgrade_to_normal_mapped(self):
mesh = get_mesh(shader_mats=True)

for source in mesh.shader_materials:
source.header.type_name = 'LoremIpsum'

(material, principled) = create_material_from_shader_material(
self, mesh.name(), source)
actual = retrieve_shader_material(self, material, principled)
source.header.type_name = 'NormalMapped.fx'
compare_shader_materials(self, source, actual)

def test_shader_roundtrip(self):
mesh = get_mesh()

Expand Down

0 comments on commit eebf452

Please sign in to comment.