MCPcopy Create free account
hub / github.com/DiligentGraphics/DiligentFX / GetLightArea

Function GetLightArea

Hydrogent/src/HnLight.cpp:241–291  ·  view source on GitHub ↗

Returns the area of the maximum possible facing profile.

Source from the content-addressed store, hash-verified

239
240// Returns the area of the maximum possible facing profile.
241static float GetLightArea(pxr::HdSceneDelegate& SceneDelegate, const pxr::SdfPath& Id, const pxr::TfToken LightType, float MetersPerUnit)
242{
243 if (LightType == pxr::HdPrimTypeTokens->diskLight ||
244 LightType == pxr::HdPrimTypeTokens->sphereLight)
245 {
246 pxr::VtValue RadiusVal = SceneDelegate.GetLightParamValue(Id, pxr::HdLightTokens->radius);
247 if (RadiusVal.IsHolding<float>())
248 {
249 float radius = RadiusVal.Get<float>() * MetersPerUnit;
250 // Return area of the facing disk, not the sphere surface area
251 return radius * radius * PI_F;
252 }
253 }
254 else if (LightType == pxr::HdPrimTypeTokens->rectLight)
255 {
256 pxr::VtValue WidthVal = SceneDelegate.GetLightParamValue(Id, pxr::HdLightTokens->width);
257 pxr::VtValue HeightVal = SceneDelegate.GetLightParamValue(Id, pxr::HdLightTokens->height);
258 if (WidthVal.IsHolding<float>() && HeightVal.IsHolding<float>())
259 {
260 float Width = WidthVal.Get<float>() * MetersPerUnit;
261 float Height = HeightVal.Get<float>() * MetersPerUnit;
262 return Width * Height;
263 }
264 }
265 else if (LightType == pxr::HdPrimTypeTokens->cylinderLight)
266 {
267 pxr::VtValue LengthVal = SceneDelegate.GetLightParamValue(Id, pxr::HdLightTokens->length);
268 pxr::VtValue RadiusVal = SceneDelegate.GetLightParamValue(Id, pxr::HdLightTokens->radius);
269 if (LengthVal.IsHolding<float>() && RadiusVal.IsHolding<float>())
270 {
271 float length = LengthVal.Get<float>() * MetersPerUnit;
272 float radius = RadiusVal.Get<float>() * MetersPerUnit;
273 // Return area of the facing rectangle, not the cylinder surface area
274 return length * radius;
275 }
276 }
277 else if (LightType == pxr::HdPrimTypeTokens->distantLight)
278 {
279 pxr::VtValue AngleDegVal = SceneDelegate.GetLightParamValue(Id, pxr::HdLightTokens->angle);
280 if (AngleDegVal.IsHolding<float>())
281 {
282 // Convert from cone apex angle to solid angle
283 float AngleGrad = AngleDegVal.Get<float>();
284 float AngleRadians = DegToRad(AngleGrad);
285 float SolidAngleSteradians = 2.f * PI_F * (1.f - std::cos(AngleRadians / 2.0));
286 return SolidAngleSteradians;
287 }
288 }
289
290 return 1.0;
291}
292
293static float GetShapingConeAngle(pxr::HdSceneDelegate& SceneDelegate, const pxr::SdfPath& Id)
294{

Callers 1

ApproximateAreaLightMethod · 0.85

Calls 1

GetLightParamValueMethod · 0.80

Tested by

no test coverage detected