AcademySoftwareFoundation / OpenPBR

Specification and reference implementation for the OpenPBR Surface shading model
Apache License 2.0
401 stars 17 forks source link

Layer inconsistencies between the whitepaper and the reference implementation #202

Closed dian-nikolov-chaos closed 1 month ago

dian-nikolov-chaos commented 1 month ago

There seem to be some inconsistencies in the layer structure of the model between the whitepaper and the reference implementation.

In the whitepaper all diagrams and calculations point to the lower reflection layer coating only the opaque diffuse layer, while in the reference implementation it seems to coat all of the dielectric layers.

In the reference implementation we have:

<layer name="dielectric_base" type="BSDF">
    <input name="top" type="BSDF" nodename="dielectric_reflection_tf_mix" />
    <input name="base" type="BSDF" nodename="dielectric_substrate" />
</layer>

where dielectric_reflection_tf_mix is the mix of the thin film and the lower reflection layer (not the coat) and dielectric_substrate is:

<mix name="dielectric_substrate" type="BSDF">
    <input name="fg" type="BSDF" nodename="dielectric_volume_transmission" />
    <input name="bg" type="BSDF" nodename="opaque_base" />
    <input name="mix" type="float" interfacename="transmission_weight" />
</mix>

Here dielectric_volume_transmission is the volume and transmission layered BSDF and opaque_base is the SSS and diffuse BSDF mix.

So according to this implementation, the dielectric reflection layer coats all of those layers, which differs from the descriptions in the whitepaper.

Which version is the correct one?

portsmouth commented 1 month ago

Hi there!

The physical picture is that there is a dielectric base (mixed with a metallic base). The dielectric base contains the internal medium corresponding to the Translucent base, Subsurface and Glossy-diffuse slabs.

In all three cases, there is a dielectric boundary at which light is reflected or transmitted. That reflection is represented in the MaterialX code by the dielectric_reflection BRDF.

In the case of the Glossy-Diffuse slab, we model the situation as an explicit layer of clear dielectric on top of an (index-matched) diffuse base. We do that because the standard "specular+diffuse" models physically all correspond to that, i.e. a thin coat on top of a diffuse base. Though conceptually it is the same dielectric interface, as indicated in the model diagrams below and text:

image

It is a bit confusing perhaps, but this corresponds to how it works for example in the formulation of the Standard Surface model.

We attempted to describe the specifics (of how the described model maps to a lobe representation such as MaterialX) in this section, which is excerpted below.

I've outlined in red the dielectric reflection lobe, which appears as noted in all three base dielectric components, essentially unchanged. Then in the lobe representation (and "albedo-scaling" approximation), you can factor that out and describe the whole thing (as in Equation 90) as the dielectric BRDF "layered" on top of the dielectric_substrate lobe (containing a mix of the lobes for the volume/subsurface/diffuse). That corresponds e.g. to what was done in Standard Surface, in that case without an explicit derivation or physical justification though.

Feel free to ask for further clarification if it's not clear or confusing. Also if you found it confusing, no doubt others did too, suggesting perhaps we need to add some more details or guidance.

image

portsmouth commented 1 month ago

My self-contained alternative GLSL implementation (of the almost-complete -- apart from fuzz) OpenPBR logic here , though not following exactly the same approach as in the excerpt above, might also be of interest, as a non-official example.

(Note that in this implementation, I opted to do a physically correct implementation of the dielectric BRDF and BTDF. So the albedo-scaling combination of BRDF+BTDF is not used for the translucent-base/subsurface case, while for the diffuse lobe I still do albedo scaling of the dielectric BRDF and the diffuse BRDF).

dian-nikolov-chaos commented 1 month ago

Thank you for the detailed response!

I was looking mainly at the diagrams and the M_PBR formulas and didn't realise the dielectric boundary is modeled explicitly in the Glossy-Diffuse base but modeled implicitly for the subsurface and translucent bases.

That's all I needed to know, so no further clarification needed :)