0
$\begingroup$

I'm making models in Blender in order to export them to Wavefront format. I'm using an image texture connected to the base color of a principled BSDF, and that principled BSDF is connected to the material output. From what I understand, that's the only way to get Blender 2.8 to properly export the material with the texture to Wavefront format.

I'm having a problem though with the specular exponent (Ns) - for some reason Blender exports it as 225.000000, which is too high and messes up the lighting.

I tried changing each and every one of the principled BSDF's numeric values and export to .obj, but the specular exponent remained at 255. Do I need more nodes than Principled to do it?

EDIT: Almost forgot - I use this Python script when exporting to .obj:

import bpy
import sys
from os.path import splitext

target_file_name, _ext = splitext(bpy.data.filepath)
target_file_name += '.obj'
bpy.ops.export_scene.obj(
    filepath=target_file_name,
    use_materials=True,
    path_mode='STRIP',
    axis_forward='-Z',
    axis_up='Y',
)
$\endgroup$

1 Answer 1

1
$\begingroup$

The roughness of the Principled BSDF controls the specular exponent that is written into the .mtl file.

From the export_obj.py source code:

# 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)

Output for Roughness set to 1.0:

# Blender MTL File: 'None'
# Material Count: 1

newmtl Material
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.0 0.0 0.0
Ni 1.450000
d 1.000000
illum 2

Output for Roughness set to 0.0:

# Blender MTL File: 'None'
# Material Count: 1

newmtl Material
Ns 900.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.0 0.0 0.0
Ni 1.450000
d 1.000000
illum 2
$\endgroup$
3
  • $\begingroup$ Thanks! Don't know how I missed it when I tried every slider... maybe because I tried with too big numbers, when the roughness needs to be between 0 and 1... $\endgroup$
    – Idan Arye
    Commented Aug 26, 2019 at 9:59
  • $\begingroup$ Why is a roughness of 0.0 900? That seems like kind of a weird number to use.. $\endgroup$
    – coulomb
    Commented Sep 2, 2022 at 21:46
  • $\begingroup$ @coulomb I can't tell you why 900 has been used as the upper limit, but according to the MTL specification: "A high exponent results in a tight, concentrated highlight. Ns values normally range from 0 to 1000." $\endgroup$ Commented Sep 2, 2022 at 22:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .