Support vertical layering of opaque BSDFs - #3022
Conversation
This changelist extends vertical layering to opaque BSDFs, adopting the convention that every BSDF in the PBS library defines a vertical-layering transmittance: the fraction of incident light that passes through the BSDF to the layers beneath it. Interface BSDFs such as `dielectric_bsdf` and `sheen_bsdf` transmit all of the energy they do not reflect, while opaque BSDFs such as `oren_nayar_diffuse_bsdf` and `conductor_bsdf` treat their weight input as a statistical coverage of the surface, transmitting light only through the uncovered fraction. Previously, an opaque BSDF used as the top input of a `layer` node fully occluded its base regardless of weight, so even a zero-weight lobe occluded the layers beneath it. With this change, layering an opaque BSDF over a base is equivalent to mixing the two BSDFs by the coverage, making a zero-weight lobe transparent to its base and preserving energy conservation throughout. Specific changes: - Update the throughput of the opaque BSDF closures in hardware shading languages from full occlusion to the uncovered fraction `1 - weight`. - Extend MDL shader generation to support vertical layering of opaque BSDFs, passing the layer base into their existing `weighted_layer` composition. - Add a Vertical-Layering Transmittance section to the PBR specification, defining the transmittance of each BSDF in the PBS library, its composition by the `mix`, `layer`, `add`, and `multiply` nodes, and the energy conservation invariant relating transmittance to directional albedo. - Add test graphs validating that layering an opaque BSDF over a base matches the equivalent mix (pixel-identical in GLSL), and that a zero-weight opaque top leaves its base unoccluded. Notes for reviewers: - No shading models in the standard libraries change appearance: all `layer` tops in `libraries/bxdf` are interface BSDFs or unit-weight opaque BSDFs. User materials that layer a partial-weight opaque BSDF will brighten, as the base now correctly receives the uncovered fraction of light. - Shader-semantic `multiply` nodes intentionally preserve transmittance (attenuating only the scattered response), so `multiply`-scaled opaque top layers (e.g. the `topMix` of `LamaLayer`) still fully occlude their base, while `mix`-scaled top layers interpolate transmittance instead. - OSL `layer` closure semantics are implemented by host renderers; the new specification section defines the expected behavior for those implementations.
|
In addition to the list of reviewers above, I'm CC'ing @krohmerNV and @jreichel-nvidia for their thoughts from the MDL perspective. |
This changelist integrates the layer pass-through semantics proposed by @tdavidovicNV in AcademySoftwareFoundation#3017 into the vertical-layering transmittance framework, preserving the distinctions drawn there between reflection, absorption, and pass-through. The following specific changes are included: - Evaluate the transmittance of an interface BSDF with its physical Fresnel reflectance alone, classifying the energy removed by non-physical color inputs such as the `tint` of `dielectric_bsdf` as absorption within the interface, matching the behavior of existing implementations. - Present the bidirectional pass-through factor of Weidlich and Wilkie as the ideal quantity underlying vertical layering, with the fixed-exitant-direction transmittance serving as its reference approximation. - Restructure the `layer` node section into parallel "Layering over a BSDF" and "Layering over a VDF" subsections, clarifying that a VDF base represents a surface boundary bound to an interior medium, with medium entry governed by the Fresnel transmittance of the surface interface.
tdavidovicNV
left a comment
There was a problem hiding this comment.
I really like this, definitely good direction.
I have two concerns about the MDL, which just reinforce the call for my more MDL capable colleagues to take a look. I tried to point out the code that looks worrying, but I don't know enough about MDL to propose actually working fixes.
| tint: mxp_color, | ||
| roughness: mxp_roughness | ||
| ), | ||
| base: mxp_base.surface.scattering, |
There was a problem hiding this comment.
The new SSS layering path forwards mxp_base.surface.scattering, but the returned volume is still constructed exclusively from the top SSS node.
Shouldn’t this be something along the lines of:
coverage = saturate(mxp_weight * mxp_top_weight)
result.surface =
weighted_layer(coverage, top.surface, base.surface)
result.volume =
volume_mix(coverage, top.volume,
1 - coverage, base.volume)
result.ior = base.ior
In particular, layer(subsurface(weight=0), baseSubsurface) should preserve the base volume exactly. I will leave the exact code to more MDL-capable people.
There was a problem hiding this comment.
Good catch, and agreed: the volume should follow the coverage rather than the top alone. This is now addressed in a1a760a, which blends the scattering VDF, scattering coefficient, and absorption coefficient of the subsurface node with those of its base by weight * top_weight, following the volume_mix composition that mx_mix_bsdf already uses. Your case of layer(subsurface(weight=0), baseSubsurface) now reduces to the base volume exactly, and the unlayered case reproduces the previous coefficients. The material additionally forwards the IOR of its base, matching the other layerable materials in the module.
| ), | ||
| ior: mxp_ior, | ||
| // we need to carry volume properties along for SSS | ||
| volume: mxp_base.volume |
There was a problem hiding this comment.
The conductor now forwards mxp_base.volume, but the returned material still uses the conductor’s IOR unconditionally no matter the top weight:
ior: mxp_ior
The important point is that layer(conductor(weight=0), base) should preserve the base IOR, I think.
I don't think the conductor's IOR should affect the volume's IOR (at least that's my reading of this code), unless we go full IOR accumulation route.
There was a problem hiding this comment.
Also a good point, and agreed. That ior: mxp_ior predates this PR (it entered the 1.9 module in #2102 and was carried into 1.11), but making the conductor layerable is what makes it matter, and assigning a conductor's complex IOR to the material IOR was never meaningful for a non-transmissive lobe. With the update in a7d18f8, all three conductor definitions forward ior: mxp_base.ior, matching mx_dielectric_bsdf and mx_sheen_bsdf. Since material IOR is uniform in MDL, as the note in mx_mix_bsdf observes, forwarding the base is the consistent choice rather than any form of accumulation.
|
After looking into this more, I need to walk back my earlier agreement with this PR. I agree with most of the change, but not with the proposed behavior of The proposed spec currently says two things:
This gives these two graphs different meanings: The first one covers half of the surface and lets half of the base show through. The second one still covers the whole surface. It only makes the Oren–Nayar response darker, with the removed light treated as absorption. At zero, the difference is even clearer: means no top layer, while: means a completely black layer which still hides the base. I don’t think these should be different. This is also not what I intended in #2971, where There is also a practical cross-target problem. Current OSL could probably be extended to support the distinction proposed here, but this would require a change to the closure contract and corresponding changes in OSL renderers. It is not just a MaterialX codegen change. MDL can represent the distinction because it has separate operations for layer weight and BSDF tinting. However, MaterialX’s MDL layer codegen does not currently handle a I would prefer that For an opaque BSDF, this means reducing its coverage. Multiplying by 0.5 leaves half the surface uncovered, while multiplying by zero removes the layer completely. Since the spec defines throughput as (T=1-w) for opaque BSDFs, scaling the effective weight by (s) gives: Given GLSL and OSL are our reference renders, and this proposal introduces something OSL currently cannot easily express, I am worried. |
|
(I am gonna walk back the recommendation, because LamaLayer and LamaConductor utilize the |
|
After looking into this much more, I need to walk back both my earlier agreement with the The underlying problem is that scaling a BSDF response and scaling its coverage are different operations. At zero, this is the difference between an absent BSDF, which reveals the layer below, and a black absorbing BSDF, which still hides it. #3022 currently makes that distinction by saying that an elemental BSDF's own I tested the same material with a neutral, reflection-only dielectric top in several backends: The results are not consistent (the base is green, the top is dielectric):
This behavior is not inferred from the renders alone. GLSL includes the dielectric OSL has no way to scale only the response of an arbitrary closure while leaving its layering weight unchanged. Closure multiplication changes the closure weight, which is also used for coverage. Pushing the multiplier into the BSDF's color or tint parameters is not an option either: the input may be an arbitrary composition, and the language has no operation that can inspect that composition and modify its parameters. Mixing with opaque black does not solve this. Consider: Response-only scaling would produce a half-covered grey BSDF. OSL closure multiplication produces a quarter-covered white BSDF. Mixing the half-covered white BSDF with opaque black produces half black, one quarter white, and one quarter uncovered: 75% coverage. All three look the same over black, but behave differently when layered. So the proposed response-only meaning of a generic BSDF MDL can represent response scaling with My #3017 proposal did not settle There are also two separate questions involving An ordinary mixed top: needs a pass-through value of its own. glTF and OpenPBR already use this form, and the linear rule proposed in #3022 is the natural one: I think this should remain part of the 1.39.6 definition. The separate question is how to reduce the coverage of an arbitrary compound top. Under the proposed rules this can be written as: Here GLSL and OSL give the expected coverage behavior for this graph. In my tests Karma produces black at Lama also shows why this is not merely theoretical. Other material systems generally give these operations separate names. MDL has So, for 1.39.6, I would suggest the following scope:
The effect of I think those questions should become focused follow-up issues. One should cover the relationship between response, coverage, That would still give #3022 a useful result for 1.39.6: opaque BSDFs become usable as top layers, while the unresolved |
|
Does it make sense to try and shoehorn these semantics into nodes that aren't really designed for that? Should we not have dedicated nodes for this, e.g. by actually defining the lama nodes as nodedefs to do proper physical layering rather than the broken graphs they currently are? |
|
...especially as I don't see any discussion of |
Following up on review notes from @tdavidovicNV, this changelist blends the volume of the MDL `mx_subsurface_bsdf` material with that of its vertically layered base by the coverage of the subsurface lobe. Previously, the surface scattering of the material forwarded its base, but its returned volume was constructed exclusively from the subsurface node, so that layering a zero-weight `subsurface_bsdf` over a subsurface base discarded the volume of the base.
Following up on review notes from @tdavidovicNV, this changelist forwards the IOR of the vertically layered base from the MDL `mx_conductor_bsdf` material, matching the convention of the other layerable BSDF materials in the module. Previously, the 1.9 and 1.11 definitions of the material assigned the complex refraction index of the conductor to the material IOR regardless of its weight, so that layering a zero-weight `conductor_bsdf` over a base discarded the IOR of the base.
Following up on review notes from @tdavidovicNV, this changelist removes the vertical-layering transmittance rules for the `add` and `multiply` nodes from the PBR specification, reserving their definition for a future revision. The removed rules described the existing behavior of the hardware shading languages, in which `multiply` attenuates only the scattered response of a BSDF, but this behavior is not shared across shader generators, and the response-only meaning of `multiply` cannot be expressed through closure multiplication in OSL. The composition of transmittance by the `mix` and `layer` nodes, on which the standard shading models depend, remains as defined.
Following up on review notes from @tdavidovicNV, this changelist extends the vertical layering test suite with graphs covering the remaining cases of the transmittance rules defined in this pull request. A unit-coverage opaque top completes the set of opaque weights at 0, 0.5, and 1, while a two-sided mix of an opaque and an interface BSDF, as used by the glTF and OpenPBR shading models, is paired with its horizontal re-expression to validate the linear transmittance of the mix node. A final graph scales an opaque top through a mix with an empty background, exercising the coverage path through which MDL shader generation layers a mix-scaled top.
Following up on review notes from @anderslanglands, this changelist makes the vertical-layering semantics of the `layer` node over a VDF explicit in the PBR specification. The medium transmittance of a VDF is named as the quantity already defined by its extinction equations, and the composite is given by a reflection lobe unaffected by the medium, a transmission lobe attenuated along its path, and a transmittance equal to the product of those of the surface and the medium, matching the reference implementation in hardware shading languages.
|
Thanks for the renderer matrix and test materials, @tdavidovicNV. That's very helpful additional context, and I agree with the scope you've proposed for 1.39.6. With the update in 05affd7, the transmittance rules for On improvements to testing, 3e1b033 extends Since the renderer matrix and test materials are yours, would you be willing to open the two issues you outlined -- one on the relationship between response, coverage, |
|
Thanks @anderslanglands -- I think we agree on the overall direction, though I'd frame it slightly differently. The dedicated operation you're describing could be a coverage weight on the This PR is the node-level piece that any such operator would build on. Today an opaque top silently occludes its base in full regardless of weight, and the coverage reading adopted here is what MDL's On |
|
The VDF question was more about what happens when I e.g. layer or add two dielectrics which themselves have VDF children? And what happens with multiply? Similarly, the important part of lama that is currently omitted in materialx is layering a thick dielectric over something else, and without the concept of layer thickness we can't really properly represent OpenPBR or any other slab-based model. |
|
Ah, thanks for clarifying, @anderslanglands. My take is that a BSDF bound to a medium is a BSDF like any other, with the response and transmittance defined in the "Layering over a VDF" subsection, so the cases you describe follow from the existing rules. For On thickness, I agree this is an important missing piece, and it's a pre-existing one: Notably, LamaLayer's two remaining inputs are |
|
I agree with this scope. Notably, there is now a bug in OSL (AcademySoftwareFoundation/OpenShadingLanguage#2151) that: That will probably affect a lot of tests for this proposal, so should be known about. |
The trouble is this is not defined unless you also define the thickness of the top layer (as in lama). In the absence of that, the only sensible option imo is to say the thickness of the top layer is 0, in which case its medium will be ignored. |
Following up on review notes from @anderslanglands, this changelist scopes the geometric path length of the layer-over-VDF composition to a composite bounding a closed object, and reserves the medium transmittance of a medium-bound BSDF nested as a top layer for a future revision of the PBR specification. A medium-bound BSDF in this nested position describes a thin slab, whose transmittance depends upon an explicit slab thickness that no node in the library yet expresses.
|
Thanks @tdavidovicNV, and for going beyond the report to fix the issue upstream in AcademySoftwareFoundation/OpenShadingLanguage#2152. Since no tagged OSL release yet contains that fix, the mix-as-top graphs in |
|
That's a fair point, @anderslanglands, and you've changed my view on this. My earlier note that the nested case follows from the existing rules assumed a path length that nothing in the graph defines: when a medium-bound BSDF is nested as the top of another On your proposed default, I agree that zero thickness is the natural choice, and it matches the default of |
|
@jstone-lucasfilm all my concerns are resolved for this PR. The thickness debate is definitely interesting, but probably longer and maybe should be split away, but I will leave that up to you and @anderslanglands, no strong opinions from me. |
|
Since we've resolved a number of issues brought up earlier in this PR, I wanted to bump the discussion, to see whether any reviewers are aware of issues that still need to be addressed. I'm specifically CC'ing @tdavidovicNV and @anderslanglands, who have provided great review so far, as well as @niklasharrysson, @krohmerNV, and @jreichel-nvidia, who may have additional perspectives that would be valuable to include. |

This changelist extends vertical layering to opaque BSDFs, adopting the convention that every BSDF in the PBS library defines a vertical-layering transmittance: the fraction of incident light that passes through the BSDF to the layers beneath it. Interface BSDFs such as
dielectric_bsdfandsheen_bsdftransmit all of the energy they do not reflect, while opaque BSDFs such asoren_nayar_diffuse_bsdfandconductor_bsdftreat their weight input as a statistical coverage of the surface, transmitting light only through the uncovered fraction.Previously, an opaque BSDF used as the top input of a
layernode fully occluded its base regardless of weight, so even a zero-weight lobe occluded the layers beneath it. With this change, layering an opaque BSDF over a base is equivalent to mixing the two BSDFs by the coverage, making a zero-weight lobe transparent to its base and preserving energy conservation throughout.Specific changes:
1 - weight.mixandlayernodes, the transmittance of a BSDF layered over a VDF, and the energy conservation invariant relating transmittance to directional albedo.mixwith an empty background reduces the coverage of an opaque top.Notes for reviewers:
layertops inlibraries/bxdfare interface BSDFs or unit-weight opaque BSDFs. User materials that layer a partial-weight opaque BSDF will brighten, as the base now correctly receives the uncovered fraction of light.addandmultiplynodes, and the medium transmittance of a medium-bound BSDF nested as a top layer, which depends upon a slab thickness that no node in the library yet expresses. Each target retains its current behavior, somultiply-scaled tops such as thetopMixofLamaLayerrender as before. Follow-up issues on these topics are proposed in the discussion below.layerclosure semantics are implemented by host renderers, with the new specification section defining the expected behavior for those implementations. Note that tagged OSL releases render the mix-as-top test graphs with reduced coverage, due to atestrenderbug in layer-opacity evaluation ([BUG] testrender drops earlier ADD branches in layer-opacity and background evaluation OpenShadingLanguage#2151) that has since been fixed on the OSL main branch.mdlc, will be run on this branch viaworkflow_dispatchbefore merge.Thanks to @tdavidovicNV for the renderer comparisons and OSL fixes that shaped the scope of this changelist, and to @anderslanglands for the layering discussions reflected in its treatment of media.