light.h 1.77 KB
Newer Older
TheNumbat's avatar
TheNumbat committed
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

#pragma once

#include <string>

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

#include "pose.h"
#include "object.h"

enum class Light_Type : int {
	directional,
	sphere,
	hemisphere,
	point,
	spot,
	rectangle,
	count
};
extern const char* Light_Type_Names[(int)Light_Type::count];

class Scene_Light {
public:
	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;

private:
	void regen_mesh();

	bool _dirty = true;
	Scene_ID _id = 0;
	GL::Mesh _mesh;
	GL::Lines _lines;
	HDR_Image _emissive;
};

bool operator!=(const Scene_Light::Options& l, const Scene_Light::Options& r);