[Bf-extensions-cvs] [0f84063c] blender2.8: OBJ IO: Change specular IO conversion.

Bastien Montagne noreply at git.blender.org
Tue Oct 16 20:01:18 CEST 2018


Commit: 0f84063c580811e14241bda234508a2622f0fcae
Author: Bastien Montagne
Date:   Tue Oct 16 16:34:37 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBA0f84063c580811e14241bda234508a2622f0fcae

OBJ IO: Change specular IO conversion.

Conversion from phong exponent to Principled BSDF is expected to be
quadratic afaik, not linear.

===================================================================

M	io_scene_obj/__init__.py
M	io_scene_obj/export_obj.py
M	io_scene_obj/import_obj.py

===================================================================

diff --git a/io_scene_obj/__init__.py b/io_scene_obj/__init__.py
index ac396b7e..ab977ca9 100644
--- a/io_scene_obj/__init__.py
+++ b/io_scene_obj/__init__.py
@@ -21,7 +21,7 @@
 bl_info = {
     "name": "Wavefront OBJ format",
     "author": "Campbell Barton, Bastien Montagne",
-    "version": (3, 4, 1),
+    "version": (3, 4, 2),
     "blender": (2, 80, 0),
     "location": "File > Import-Export",
     "description": "Import-Export OBJ, Import OBJ mesh, UV's, materials and textures",
diff --git a/io_scene_obj/export_obj.py b/io_scene_obj/export_obj.py
index f3b92afd..a147a493 100644
--- a/io_scene_obj/export_obj.py
+++ b/io_scene_obj/export_obj.py
@@ -73,9 +73,11 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
                 use_mirror = mat_wrap.metallic != 0.0
                 use_transparency = mat_wrap.transmission != 0.0
 
-                # Convert from principled roughness to 0 - 1000 specular range.
-                # XXX Basic linear conversion, what would be best-matching formula here?
-                fw('Ns %.6f\n' % ((1.0 - mat_wrap.roughness) * 1000))
+                # XXX Totally empirical conversion, trying to adapt it
+                #     (from 1.0 - 0.0 Principled BSDF range to 0.0 - 900.0 OBJ specular exponent range)...
+                spec = (1.0 - mat_wrap.roughness) * 30
+                spec *= spec
+                fw('Ns %.6f\n' % spec)
 
                 # Ambient
                 if use_mirror:
diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py
index 916ff313..cb18f911 100644
--- a/io_scene_obj/import_obj.py
+++ b/io_scene_obj/import_obj.py
@@ -93,6 +93,8 @@ def create_materials(filepath, relpath,
     Create all the used materials in this obj,
     assign colors and images to the materials from all referenced material libs
     """
+    from math import sqrt
+
     DIR = os.path.dirname(filepath)
     context_material_vars = set()
 
@@ -303,8 +305,9 @@ def create_materials(filepath, relpath,
                         emit_colors[:] = [
                             float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3])]
                     elif line_id == b'ns':
-                        # XXX Basic linear conversion, what would be best-matching formula here?
-                        context_mat_wrap.roughness = 1.0 - (float_func(line_split[1]) / 1000)
+                        # XXX Totally empirical conversion, trying to adapt it
+                        #     (from 0.0 - 900.0 OBJ specular exponent range to 1.0 - 0.0 Principled BSDF range)...
+                        context_mat_wrap.roughness = 1.0 - (sqrt(float_func(line_split[1])) / 30)
                         context_material_vars.add("roughness")
                     elif line_id == b'ni':  # Refraction index (between 0.001 and 10).
                         context_mat_wrap.ior = float_func(line_split[1])



More information about the Bf-extensions-cvs mailing list