File: lights.h

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 (151 lines) | stat: -rw-r--r-- 4,215 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright 2009-2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "../default.h"

namespace embree
{
  namespace SceneGraph
  {
    enum LightType
    {
      LIGHT_AMBIENT,
      LIGHT_POINT,
      LIGHT_DIRECTIONAL,
      LIGHT_SPOT,
      LIGHT_DISTANT,
      LIGHT_TRIANGLE,
      LIGHT_QUAD,
    };

    class Light : public RefCount
    {
      ALIGNED_CLASS_(16)

    public:
      Light(LightType type) : type(type) {}

      LightType getType() const { return type; }
      virtual Ref<Light> transform(const AffineSpace3fa& space) const = 0;

    private:
      LightType type;
    };

    class AmbientLight : public Light
    {
    public:
      AmbientLight (const Vec3fa& L)
        : Light(LIGHT_AMBIENT), L(L) {}

      Ref<Light> transform(const AffineSpace3fa& space) const {
        return new AmbientLight(L);
      }

    public:
      Vec3fa L;                  //!< radiance of ambient light
    };

    class PointLight : public Light
    {
    public:
      PointLight (const Vec3fa& P, const Vec3fa& I)
        : Light(LIGHT_POINT), P(P), I(I) {}

      Ref<Light> transform(const AffineSpace3fa& space) const {
        return new PointLight(xfmPoint(space,P),I);
      }

    public:
      Vec3fa P;                  //!< position of point light
      Vec3fa I;                  //!< radiant intensity of point light
    };

    class DirectionalLight : public Light
    {
    public:
      DirectionalLight (const Vec3fa& D, const Vec3fa& E)
        : Light(LIGHT_DIRECTIONAL), D(D), E(E) {}

      Ref<Light> transform(const AffineSpace3fa& space) const {
        return new DirectionalLight(xfmVector(space,D),E);
      }

    public:
      Vec3fa D;                  //!< Light direction
      Vec3fa E;                  //!< Irradiance (W/m^2)
    };

    class SpotLight : public Light
    {
    public:
      SpotLight (const Vec3fa& P, const Vec3fa& D, const Vec3fa& I, float angleMin, float angleMax)
        : Light(LIGHT_SPOT), P(P), D(D), I(I), angleMin(angleMin), angleMax(angleMax) {}

      Ref<Light> transform(const AffineSpace3fa& space) const {
        return new SpotLight(xfmPoint(space,P),xfmVector(space,D),I,angleMin,angleMax);
      }

    public:
      Vec3fa P;                 //!< Position of the spot light
      Vec3fa D;                 //!< Light direction of the spot light
      Vec3fa I;                 //!< Radiant intensity (W/sr)
      float angleMin, angleMax; //!< Linear falloff region
    };

    class DistantLight : public Light
    {
    public:
      DistantLight (const Vec3fa& D, const Vec3fa& L, const float halfAngle)
        : Light(LIGHT_DISTANT), D(D), L(L), halfAngle(halfAngle), radHalfAngle(deg2rad(halfAngle)), cosHalfAngle(cos(deg2rad(halfAngle))) {}

      Ref<Light> transform(const AffineSpace3fa& space) const {
        return new DistantLight(xfmVector(space,D),L,halfAngle);
      }

    public:
      Vec3fa D;            //!< Light direction
      Vec3fa L;            //!< Radiance (W/(m^2*sr))
      float halfAngle;     //!< Half illumination angle
      float radHalfAngle;  //!< Half illumination angle in radians
      float cosHalfAngle;  //!< Cosine of half illumination angle
    };

    class TriangleLight : public Light
    {
    public:
      TriangleLight (const Vec3fa& v0, const Vec3fa& v1, const Vec3fa& v2, const Vec3fa& L)
        : Light(LIGHT_TRIANGLE), v0(v0), v1(v1), v2(v2), L(L) {}

      Ref<Light> transform(const AffineSpace3fa& space) const {
        return new TriangleLight(xfmPoint(space,v0),xfmPoint(space,v1),xfmPoint(space,v2),L);
      }

    public:
      Vec3fa v0;
      Vec3fa v1;
      Vec3fa v2;
      Vec3fa L;
    };

    class QuadLight : public Light
    {
    public:
      QuadLight (const Vec3fa& v0, const Vec3fa& v1, const Vec3fa& v2, const Vec3fa& v3, const Vec3fa& L)
        : Light(LIGHT_QUAD), v0(v0), v1(v1), v2(v2), v3(v3), L(L) {}

      Ref<Light> transform(const AffineSpace3fa& space) const {
        return new QuadLight(xfmPoint(space,v0),xfmPoint(space,v1),xfmPoint(space,v2),xfmPoint(space,v3),L);
      }

    public:
      Vec3fa v0;
      Vec3fa v1;
      Vec3fa v2;
      Vec3fa v3;
      Vec3fa L;
    };
  }
}