Skip to content

Commit 5d519c7

Browse files
committed
[hdEmbree] factor out a _CalculateHitPosition utility function
1 parent 31e637a commit 5d519c7

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

pxr/imaging/plugin/hdEmbree/renderer.cpp

+20-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@
2222
#include <chrono>
2323
#include <thread>
2424

25+
namespace {
26+
27+
PXR_NAMESPACE_USING_DIRECTIVE
28+
29+
// -------------------------------------------------------------------------
30+
// General Ray Utilities
31+
// -------------------------------------------------------------------------
32+
33+
inline GfVec3f
34+
_CalculateHitPosition(RTCRayHit const& rayHit)
35+
{
36+
return GfVec3f(rayHit.ray.org_x + rayHit.ray.tfar * rayHit.ray.dir_x,
37+
rayHit.ray.org_y + rayHit.ray.tfar * rayHit.ray.dir_y,
38+
rayHit.ray.org_z + rayHit.ray.tfar * rayHit.ray.dir_z);
39+
}
40+
41+
} // anonymous namespace
42+
2543
PXR_NAMESPACE_OPEN_SCOPE
2644

2745
HdEmbreeRenderer::HdEmbreeRenderer()
@@ -762,9 +780,7 @@ HdEmbreeRenderer::_ComputeDepth(RTCRayHit const& rayHit,
762780
}
763781

764782
if (clip) {
765-
GfVec3f hitPos = GfVec3f(rayHit.ray.org_x + rayHit.ray.tfar * rayHit.ray.dir_x,
766-
rayHit.ray.org_y + rayHit.ray.tfar * rayHit.ray.dir_y,
767-
rayHit.ray.org_z + rayHit.ray.tfar * rayHit.ray.dir_z);
783+
GfVec3f hitPos = _CalculateHitPosition(rayHit);
768784

769785
hitPos = GfVec3f(_viewMatrix.Transform(hitPos));
770786
hitPos = GfVec3f(_projMatrix.Transform(hitPos));
@@ -874,9 +890,7 @@ HdEmbreeRenderer::_ComputeColor(RTCRayHit const& rayHit,
874890
rtcGetGeometryUserData(rtcGetGeometry(instanceContext->rootScene,rayHit.hit.geomID)));
875891

876892
// Compute the worldspace location of the rayHit hit.
877-
GfVec3f hitPos = GfVec3f(rayHit.ray.org_x + rayHit.ray.tfar * rayHit.ray.dir_x,
878-
rayHit.ray.org_y + rayHit.ray.tfar * rayHit.ray.dir_y,
879-
rayHit.ray.org_z + rayHit.ray.tfar * rayHit.ray.dir_z);
893+
GfVec3f hitPos = _CalculateHitPosition(rayHit);
880894

881895
// If a normal primvar is present (e.g. from smooth shading), use that
882896
// for shading; otherwise use the flat face normal.

0 commit comments

Comments
 (0)