File: ambient_light.cpp

package info (click to toggle)
embree 3.12.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 27,412 kB
  • sloc: cpp: 173,822; xml: 3,737; ansic: 2,955; python: 1,628; sh: 480; makefile: 193; csh: 42
file content (83 lines) | stat: -rw-r--r-- 2,224 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2009-2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "light.h"
#include "../math/sampling.h"
#include "../math/linearspace.h"

namespace embree {

struct AmbientLight
{
  Light super;      //!< inherited light fields

  Vec3fa radiance;   //!< RGB color and intensity of light
};


// Implementation
//////////////////////////////////////////////////////////////////////////////

// XXX importance sampling is only done into the positive hemisphere
// ==> poor support for translucent materials
Light_SampleRes AmbientLight_sample(const Light* super,
                                    const DifferentialGeometry& dg,
                                    const Vec2f& s)
{
  AmbientLight* self = (AmbientLight*)super;
  Light_SampleRes res;

  const Vec3fa localDir = cosineSampleHemisphere(s);
  res.dir = frame(dg.Ns) * localDir;
  res.pdf = cosineSampleHemispherePDF(localDir);
  res.dist = inf;
  res.weight = self->radiance * rcp(res.pdf);

  return res;
}

Light_EvalRes AmbientLight_eval(const Light* super,
                                const DifferentialGeometry& dg,
                                const Vec3fa& dir)
{
  AmbientLight* self = (AmbientLight*)super;
  Light_EvalRes res;

  res.value = self->radiance;
  res.dist = inf;
  res.pdf = cosineSampleHemispherePDF(max(dot(dg.Ns, dir), 0.f));

  return res;
}


void AmbientLight_Constructor(AmbientLight* self,
                              const Vec3fa& radiance)
{
  Light_Constructor(&self->super);
  self->radiance = radiance;
  self->super.sample = AmbientLight_sample;
  self->super.eval = AmbientLight_eval;
}


// Exports (called from C++)
//////////////////////////////////////////////////////////////////////////////

//! Create an ispc-side AmbientLight object
extern "C" void *AmbientLight_create()
{
  AmbientLight* self = (AmbientLight*) alignedMalloc(sizeof(AmbientLight),16);
  AmbientLight_Constructor(self, Vec3fa(1.f));
  return self;
}

//! Set the parameters of an ispc-side AmbientLight object
extern "C" void AmbientLight_set(void* super,
                             const Vec3fa& radiance)
{
  AmbientLight* self = (AmbientLight*)super;
  self->radiance = radiance;
}

} // namespace embree