-
Notifications
You must be signed in to change notification settings - Fork 0
/
light.h
53 lines (45 loc) · 1.35 KB
/
light.h
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
#ifndef __LIGHT_H__
#define __LIGHT_H__
#include "cuda_runtime_api.h"
#include "directional_light.h"
#include "point_light.h"
#include "volumetric_light.h"
#include <vector_types.h>
class LightVariant
{
public:
__host__ LightVariant(VolumetricLight const &v) : _tag(Tag::Volumetric) { _payload.v = v; }
__host__ LightVariant(PointLight const &p) : _tag(Tag::Point) { _payload.p = p; }
__host__ LightVariant(DirectionalLight const &d) : _tag(Tag::Directional) { _payload.d = d; }
__host__ __device__ [[nodiscard]] float3 wi(float3 const &p, unsigned int &seed) const
{
switch (_tag) {
case Tag::Point:
return _payload.p.wi(p, seed);
case Tag::Directional:
return _payload.d.wi(p, seed);
case Tag::Volumetric:
return _payload.v.wi(p, seed);
}
}
__host__ __device__ [[nodiscard]] float3 lumi() const
{
switch (_tag) {
case Tag::Point:
return _payload.p.lumi();
case Tag::Directional:
return _payload.d.lumi();
case Tag::Volumetric:
return _payload.v.lumi();
}
}
private:
union Payload {
PointLight p;
DirectionalLight d;
VolumetricLight v;
Payload() : p() {}
} _payload;
enum class Tag { Point, Directional, Volumetric } _tag{};
};
#endif