mitsuba-renderer / mitsuba-blender

Mitsuba integration add-on for Blender
BSD 3-Clause "New" or "Revised" License
270 stars 35 forks source link

Specular component is exported wrong for pure metallic objects #28

Closed TZZZZ closed 1 year ago

TZZZZ commented 2 years ago

Hi! Could you please help with the following?

I have a simple scene in Blender with one camera, one cube, and one rectangular emitter (see attached). The cube has metallicity = 1 and specular = 0, i.e., it is pure metallic. We see a perfect reflection of the light source in Blender:

Screenshot 2022-08-24 at 17 48 03

However, after exporting the scene to xml using this add-on and rendering the obtained xml in Mitsuba3 I obtain a black screen.

I think that the reason is as follows. The specular value in xml is exported as zero. It seems for me that in Mitsuba3 the specular parameter has another meaning and it should be exported as 0.5 in this case. If I change it manually to 0.5, I obtain the correct images in Mitsuba.

addon_test_metal.blend.zip

TZZZZ commented 2 years ago

Hi! Just in case I would like to ask for confirmation that I clearly explained that happens in this example and that you don't need other information.

ros-dorian commented 2 years ago

Hello,

After a bit of investigation, it seems that the specular parameter is simply another way of expressing the eta value in a way that is more easily understandable by artists. Both Mitsuba and Blender convert the specular value into an eta IOR using the formula $\text{specular} = \frac{1}{0.08}(\frac{\text{eta}-1}{\text{eta}+1})^2$. You can find this information in Blender's manual and in Mitsuba's code.

The primary difference between Blender and Mitsuba is that Blender, on one hand, has both an IOR and a specular value. In this case, the IOR value affects the transmittance only whereas the specular value handles the fresnel coefficient for dielectric and metallic materials. On the other hand, Mitsuba only has one value for both effects which can either be defined as eta directly or using the converted specular value.

All of that to say that, in my opinion, the bug is not about the specular value itself but rather an incorrect behavior in Mitsuba with $\text{specular} = 0$ (or $\text{eta} = 1$).

A simple fix for now can be to avoid the problematic values by adding some epsilon, which seems to produce correct images. However, it would be interesting on top of that to export either Blender's IOR or specular value depending on whether the material has a transmission component.

Let me know if all of this makes sense or if I am missing something. I will let this issue open until we have some more opinion from people that know Mitsuba in details :) @dvicini

ros-dorian commented 2 years ago

One more thing to note is that any transmission value that is not completely 0 or 1 will lead to inconsistent results between Mitsuba and Blender unless the specular and eta values are matched in Blender. You can find a very interesting video here that explains how to do this in the shader editor (and achieve better realism).

Basically, it comes down to two different implementation philosophies. Blender wants to give artists control over the appearance of the material and Mitsuba aims at physical realism.

TZZZZ commented 2 years ago

Yes, thank you, it works with specular=epsilon.

ros-dorian commented 2 years ago

Great, I've merged the temporary fix but I'll leave this issue open until further investigation.

ros-dorian commented 1 year ago

Closing this issue as it is mostly solved.