light.h 1.92 KB
Newer Older
TheNumbat's avatar
TheNumbat committed
1
2
3
4
5
6
7
8
9
10
11

#pragma once

#include <string>

#include "../lib/spectrum.h"
#include "../platform/gl.h"
#include "../rays/samplers.h"
#include "../util/hdr_image.h"

#include "object.h"
TheNumbat's avatar
TheNumbat committed
12
#include "pose.h"
TheNumbat's avatar
TheNumbat committed
13

TheNumbat's avatar
TheNumbat committed
14
15
enum class Light_Type : int { directional, sphere, hemisphere, point, spot, rectangle, count };
extern const char *Light_Type_Names[(int)Light_Type::count];
TheNumbat's avatar
TheNumbat committed
16
17
18

class Scene_Light {
public:
TheNumbat's avatar
TheNumbat committed
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
    Scene_Light(Light_Type type, Scene_ID id, Pose p, std::string n = {});
    Scene_Light(const Scene_Light &src) = delete;
    Scene_Light(Scene_Light &&src);
    ~Scene_Light() = default;

    void operator=(const Scene_Light &src) = delete;
    Scene_Light &operator=(Scene_Light &&src) = default;

    Scene_ID id() const { return _id; }
    BBox bbox() const;

    void render(const Mat4 &view, bool depth_only = false, bool posed = true);
    void dirty();

    Spectrum radiance() const;
    void set_time(float time);

    std::string emissive_load(std::string file);
    std::string emissive_loaded() const;
    HDR_Image emissive_copy() const;

    const GL::Tex2D &emissive_texture() const;
    void emissive_clear();
    bool is_env() const;

    static const inline int max_name_len = 256;
    struct Options {
        Light_Type type = Light_Type::point;
        char name[max_name_len] = {};
        Spectrum spectrum = Spectrum(1.0f);
        float intensity = 1.0f;
        bool has_emissive_map = false;
        Vec2 angle_bounds = Vec2(30.0f, 35.0f);
        Vec2 size = Vec2(1.0f);
    };

    struct Anim_Light {
        void at(float t, Options &o) const;
        void set(float t, Options o);
        Splines<Spectrum, float, Vec2, Vec2> splines;
    };

    Options opt;
    Pose pose;
    Anim_Pose anim;
    Anim_Light lanim;
TheNumbat's avatar
TheNumbat committed
65
66

private:
TheNumbat's avatar
TheNumbat committed
67
    void regen_mesh();
TheNumbat's avatar
TheNumbat committed
68

TheNumbat's avatar
TheNumbat committed
69
70
71
72
73
    bool _dirty = true;
    Scene_ID _id = 0;
    GL::Mesh _mesh;
    GL::Lines _lines;
    HDR_Image _emissive;
TheNumbat's avatar
TheNumbat committed
74
75
};

TheNumbat's avatar
TheNumbat committed
76
bool operator!=(const Scene_Light::Options &l, const Scene_Light::Options &r);