pathtracer.h 4.89 KB
Newer Older
1
2
#ifndef INCLUDE_PATHTRACER_H
#define INCLUDE_PATHTRACER_H
unknown's avatar
unknown committed
3

unknown's avatar
unknown committed
4
#include <array>
5
#include <filesystem>
unknown's avatar
unknown committed
6

Johannes Braun's avatar
Johannes Braun committed
7
#include <core/state.h>
8
#include <core/base/program.h>
Johannes Braun's avatar
Johannes Braun committed
9
#include <core/graph/scene_node.h>
10
#include <core/objects/skybox.h>
Johannes Braun's avatar
Johannes Braun committed
11
#include <util/messages.h>
12
#include <util/property.h>
unknown's avatar
unknown committed
13

14
#include <raytrace/data/global_collector.h>
15
#include "raygenerator.h"
unknown's avatar
unknown committed
16

17
namespace glare::raytrace
unknown's avatar
unknown committed
18
{
19
20
21
	namespace fs = std::experimental::filesystem;

	enum class EffectType
unknown's avatar
unknown committed
22
	{
23
24
25
26
27
		eDiffusion = 0,
		eReflection = 1,
		eTransmission = 2,
		eEmission = 3
	};
unknown's avatar
unknown committed
28

Johannes Braun's avatar
Johannes Braun committed
29
	class Pathtracer : public msg::Observer
30
31
32
	{
	public:
		Pathtracer();
Johannes Braun's avatar
Johannes Braun committed
33
34
		Pathtracer(std::shared_ptr<core::SceneNode> graph_root);
		Pathtracer(std::shared_ptr<core::SceneNode> graph_root, RayGeneratorType ray_generator);
35
36
37
38
39
40
41
42
		Pathtracer(RayGeneratorType ray_generator);
		Pathtracer(std::shared_ptr<SceneCollector> collector);
		Pathtracer(std::shared_ptr<SceneCollector> collector, RayGeneratorType ray_generator);
		~Pathtracer();

		void loadSettings(const fs::path &xml_file);

		const core::TextureRGBA_32F &render(uint32_t width, uint32_t height);
43
		void draw(std::shared_ptr<core::SceneNode> node = core::Context::current().graph());
44
45
46
47
48
		void saveRender(fs::path target) const;

		void setGenerator(RayGeneratorType generator);
		RayGeneratorType getGenerator() const;
		void initialize(std::shared_ptr<SceneCollector> collector);
Johannes Braun's avatar
Johannes Braun committed
49
		void reload(std::shared_ptr<core::SceneNode> graph_root);
50

Johannes Braun's avatar
Johannes Braun committed
51
		void onNotify(msg::id_type id, msg::message_type message) override;
52
53
54
55
56
57
58

		void reset();

		uint32_t width() const;
		uint32_t height() const;

		const core::Program& shader() const;
Johannes Braun's avatar
Johannes Braun committed
59
		core::Buffer& traceBuffer();
60
61
62
63
		const core::TextureRGBA_32F& renderTarget() const;
		std::shared_ptr<SceneCollector> collector() const;
		unsigned currentSample() const;

Johannes Braun's avatar
Johannes Braun committed
64
	/*	void setEffectBounces(EffectType type, uint8_t bounces);
65
		uint8_t getEffectBounces(EffectType type);
unknown's avatar
unknown committed
66

67
68
69
70
71
		void setLinespaceBounceThresholds(EffectType type, uint8_t bounces);
		uint8_t getLinespaceBounceThreshold(EffectType type);

		void setBounces(unsigned count);
		unsigned getBounces() const;
Johannes Braun's avatar
Johannes Braun committed
72

73
74
		void setMaxSamples(unsigned count);
		unsigned getMaxSamples() const;
Johannes Braun's avatar
Johannes Braun committed
75

76
77
		void setSamplesPerFrame(unsigned count);
		unsigned getSamplesPerFrame() const;
Johannes Braun's avatar
Johannes Braun committed
78

79
80
		float getClampDirect() const;
		void setClampDirect(float clamp_direct);
Johannes Braun's avatar
Johannes Braun committed
81

82
83
		float getClampIndirect() const;
		void setClampIndirect(float clamp_indirect);
Johannes Braun's avatar
Johannes Braun committed
84

85
86
		float getAccuracyThreshold() const;
		void setAccuracyThreshold(float accuracy_threshold);
Johannes Braun's avatar
Johannes Braun committed
87

88
89
		float getShadowThreshold() const;
		void setShadowThreshold(float shadow_threshold);
Johannes Braun's avatar
Johannes Braun committed
90

91
		float getDistanceThreshold() const;
Johannes Braun's avatar
Johannes Braun committed
92
		void setDistanceThreshold(float distance_threshold);*/
Johannes Braun's avatar
Johannes Braun committed
93

Johannes Braun's avatar
Johannes Braun committed
94
	/*	struct
95
96
97
98
99
100
101
102
103
104
		{
			unsigned current_sample = 0;
			unsigned max_samples = 80000;
			unsigned samples_per_frame = 1;
			unsigned bounces = 1;
			float clamp_direct = 10.f;
			float clamp_indirect = 10.f;
		} m_render_config;

		struct
unknown's avatar
unknown committed
105
		{
106
			bool print_render_times = false;
Johannes Braun's avatar
Johannes Braun committed
107
		} debug;*/
108
109

	private:
Johannes Braun's avatar
Johannes Braun committed
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
152
153
154
155
156
157
158
159
		struct Configuration {
			struct {
				unsigned count = 16;
				std::array<uint8_t, 4> thresholds;
			} bounces;

			struct {
				float direct = 10.f;
				float indirect = 10.f;
			} clamp;

			struct {
				bool show_times = false;
			} debug;

			struct {
				struct
				{
					float accuracy = 0.5f;
					float shadow = 0.5f;
				} quality;

				struct
				{
					float distance = 10.f;
					std::array<uint8_t, 4> bounces;
				} thresholds;
			} linespace;

			bool operator!=(const Configuration& other) {
				return bounces.count != other.bounces.count &&
					bounces.thresholds == other.bounces.thresholds &&
					clamp.direct == other.clamp.direct &&
					clamp.indirect == other.clamp.indirect &&
					linespace.quality.accuracy == other.linespace.quality.accuracy &&
					linespace.quality.shadow == other.linespace.quality.shadow &&
					linespace.thresholds.distance = other.linespace.thresholds.distance &&
					linespace.thresholds.bounces = other.linespace.thresholds.bounces;
			}

		} dynamic_config;

		struct {
			unsigned current = 0;
			unsigned max = 80'000;
			unsigned per_frame = 1;
		} samples;

		static std::unique_ptr<core::Program> m_render_shader;

160
161
162
		uint32_t m_last_width = 0;
		uint32_t m_last_height = 0;

Johannes Braun's avatar
Johannes Braun committed
163
		/*struct {
164
165
166
167
168
169
170
			float accuracy_threshold;
			float shadow_threshold;
			uint32_t bounce_thresholds;
			float distance_threshold;
		} m_linespace_config;

		std::array<uint8_t, 4> m_bounce_count_thresholds;
Johannes Braun's avatar
Johannes Braun committed
171
		std::array<uint8_t, 4> m_ls_bounce_count_thresholds;*/
172
173
174

		std::shared_ptr<SceneCollector> m_collector;
		std::unique_ptr<core::TextureRGBA_32F> m_render_target;
Johannes Braun's avatar
Johannes Braun committed
175
176
		std::unique_ptr<core::TextureRGBA_32F> m_color_storage;
		core::Buffer m_trace_buffer;
177
178

		RayGeneratorType m_generator_type = RayGeneratorType::eTrace;
Johannes Braun's avatar
Johannes Braun committed
179
180
181
182
183
184
185
186

	public:
		make_property<Configuration, Pathtracer, Configuration> configuration()
		{
			return make_property<Configuration, Pathtracer, Configuration>([this](const auto&) {
				reset();
			}, [this]() { return dynamic_config; });
		}
187
	};
unknown's avatar
unknown committed
188
189
}

190
#endif //INCLUDE_PATHTRACER_H