Skip to content

Commit cf4f1d3

Browse files
committed
[hdEmbree] add lighting support for IES files
1 parent fd70f4c commit cf4f1d3

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

pxr/imaging/plugin/hdEmbree/light.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,42 @@ HdEmbree_Light::Sync(HdSceneDelegate *sceneDelegate,
233233
_lightData.shaping.coneSoftness = value.UncheckedGet<float>();
234234
}
235235

236+
if (const auto value = sceneDelegate->GetLightParamValue(
237+
id, HdLightTokens->shapingIesFile);
238+
value.IsHolding<SdfAssetPath>()) {
239+
SdfAssetPath iesAssetPath = value.UncheckedGet<SdfAssetPath>();
240+
std::string iesPath = iesAssetPath.GetResolvedPath();
241+
if (iesPath.empty()) {
242+
iesPath = iesAssetPath.GetAssetPath();
243+
}
244+
245+
if (!iesPath.empty()) {
246+
std::ifstream in(iesPath);
247+
if (!in.is_open()) {
248+
TF_WARN("could not open ies file %s", iesPath.c_str());
249+
} else {
250+
std::stringstream buffer;
251+
buffer << in.rdbuf();
252+
253+
if (!_lightData.shaping.ies.iesFile.load(buffer.str())) {
254+
TF_WARN("could not load ies file %s", iesPath.c_str());
255+
}
256+
}
257+
}
258+
}
259+
260+
if (const auto value = sceneDelegate->GetLightParamValue(
261+
id, HdLightTokens->shapingIesNormalize);
262+
value.IsHolding<bool>()) {
263+
_lightData.shaping.ies.normalize = value.UncheckedGet<bool>();
264+
}
265+
266+
if (const auto value = sceneDelegate->GetLightParamValue(
267+
id, HdLightTokens->shapingIesAngleScale);
268+
value.IsHolding<float>()) {
269+
_lightData.shaping.ies.angleScale = value.UncheckedGet<float>();
270+
}
271+
236272
_PopulateRtcLight(device, scene);
237273

238274
HdEmbreeRenderer *renderer = embreeRenderParam->GetRenderer();

pxr/imaging/plugin/hdEmbree/light.h

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef PXR_IMAGING_PLUGIN_HD_EMBREE_LIGHT_H
88
#define PXR_IMAGING_PLUGIN_HD_EMBREE_LIGHT_H
99

10+
#include "pxr/imaging/plugin/hdEmbree/pxrIES/pxrIES.h"
11+
1012
#include "pxr/base/gf/vec3f.h"
1113
#include "pxr/base/gf/matrix3f.h"
1214
#include "pxr/base/gf/matrix4f.h"
@@ -71,12 +73,20 @@ struct HdEmbree_LightTexture
7173
int height = 0;
7274
};
7375

76+
struct HdEmbree_IES
77+
{
78+
PxrIESFile iesFile;
79+
bool normalize = false;
80+
float angleScale = 0.0f;
81+
};
82+
7483
struct HdEmbree_Shaping
7584
{
7685
GfVec3f focusTint;
7786
float focus = 0.0f;
7887
float coneAngle = 180.0f;
7988
float coneSoftness = 0.0f;
89+
HdEmbree_IES ies;
8090
};
8191

8292
struct HdEmbree_LightData

pxr/imaging/plugin/hdEmbree/renderer.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,27 @@ _IntersectAreaLight(HdEmbree_LightData const& light, RTCRayHit const& rayHit)
437437
};
438438
}
439439

440+
float
441+
_EvalIES(HdEmbree_LightData const& light, GfVec3f const& wI)
442+
{
443+
HdEmbree_IES const& ies = light.shaping.ies;
444+
445+
if (!ies.iesFile.valid()) {
446+
// Either none specified or there was an error loading. In either case,
447+
// just ignore
448+
return 1.0f;
449+
}
450+
451+
// emission direction in light space
452+
GfVec3f wE = light.xformWorldToLight.TransformDir(wI).GetNormalized();
453+
454+
float theta = _Theta(wE);
455+
float phi = _Phi(wE);
456+
float norm = ies.normalize ? ies.iesFile.power() : 1.0f;
457+
458+
return ies.iesFile.eval(theta, phi, ies.angleScale) / norm;
459+
}
460+
440461
GfVec3f
441462
_EvalLightBasic(HdEmbree_LightData const& light)
442463
{
@@ -543,6 +564,9 @@ _EvalAreaLight(HdEmbree_LightData const& light, _ShapeSample const& ss,
543564
const float thetaOffZ = acosf(cosThetaOffZ);
544565
Le *= 1.0f - _Smoothstep(thetaOffZ, GfRange1f(thetaSoft, thetaCone));
545566

567+
// Apply IES
568+
Le *= _EvalIES(light, wI);
569+
546570
return _LightSample {
547571
Le,
548572
wI,

0 commit comments

Comments
 (0)