Skip to content

Commit

Permalink
[hdEmbree] add support for lighting double-sided meshes
Browse files Browse the repository at this point in the history
  • Loading branch information
pmolodo committed Oct 22, 2024
1 parent 05ff0ad commit 65f44f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pxr/imaging/plugin/hdEmbree/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ class HdEmbreeMesh final : public HdMesh {
/// embree state.
virtual void Finalize(HdRenderParam *renderParam) override;

bool EmbreeMeshIsDoubleSided() const
{
return _doubleSided;
}

protected:
// Initialize the given representation of this Rprim.
// This is called prior to syncing the prim, the first time the repr
Expand Down
17 changes: 16 additions & 1 deletion pxr/imaging/plugin/hdEmbree/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1660,8 +1660,23 @@ HdEmbreeRenderer::_ComputeLighting(
float vis = _Visibility(position, ls.wI, ls.dist * 0.99f);

// Add exitant luminance
float cosOffNormal = GfDot(ls.wI, normal);
if (cosOffNormal < 0.0f) {
bool doubleSided = false;
HdEmbreeMesh *mesh =
dynamic_cast<HdEmbreeMesh*>(prototypeContext->rprim);
if (mesh) {
doubleSided = mesh->EmbreeMeshIsDoubleSided();
}

if (doubleSided) {
cosOffNormal *= -1.0f;
} else {
cosOffNormal = 0.0f;
}
}
finalColor += ls.Li
* _DotZeroClip(ls.wI, normal)
* cosOffNormal
* brdf
* vis
* ls.invPdfW;
Expand Down

0 comments on commit 65f44f3

Please sign in to comment.