MCPcopy Create free account
hub / github.com/RenderKit/embree / Light_SampleRes SpotLight_sample

Function Light_SampleRes SpotLight_sample

tutorials/common/lights/spot_light.cpp:27–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25//////////////////////////////////////////////////////////////////////////////
26
27SYCL_EXTERNAL Light_SampleRes SpotLight_sample(const Light* super,
28 const DifferentialGeometry& dg,
29 const Vec2f& s)
30{
31 const SpotLight* self = (SpotLight*)super;
32 Light_SampleRes res;
33
34 // extant light vector from the hit point
35 res.dir = self->position - dg.P;
36
37 if (self->radius > 0.0f)
38 res.dir = self->frame * uniformSampleDisk(self->radius, s) + res.dir;
39
40 const float dist2 = dot(res.dir, res.dir);
41 const float invdist = rsqrt(dist2);
42
43 // normalized light vector
44 res.dir = res.dir * invdist;
45 res.dist = dist2 * invdist;
46
47 // cosine of the negated light direction and light vector.
48 const float cosAngle = -dot(self->frame.vz, res.dir);
49 const float angularAttenuation = clamp((cosAngle - self->cosAngleMax) * self->cosAngleScale);
50
51 if (self->radius > 0.0f)
52 res.pdf = self->diskPdf * dist2 * abs(cosAngle);
53 else
54 res.pdf = inf; // we always take this res
55
56 // convert from power to radiance by attenuating by distance^2; attenuate by angle
57 res.weight = self->power * (sqr(invdist) * angularAttenuation);
58
59 return res;
60}
61
62SYCL_EXTERNAL Light_EvalRes SpotLight_eval(const Light* super,
63 const DifferentialGeometry& dg,

Callers

nothing calls this directly

Calls 6

uniformSampleDiskFunction · 0.85
dotFunction · 0.50
rsqrtFunction · 0.50
clampFunction · 0.50
absFunction · 0.50
sqrFunction · 0.50

Tested by

no test coverage detected