pathtracer.h 3.76 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

7
8
9
#include <core/base/program.h>
#include <core/graph/node.h>
#include <core/objects/skybox.h>
10
#include <util/messaging.h>
unknown's avatar
unknown committed
11

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

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

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

29
		class Pathtracer : public messaging::Receiver
unknown's avatar
unknown committed
30
31
		{
		public:
32
			Pathtracer();
33
			Pathtracer(std::shared_ptr<core::GraphNode> graph_root);
34
35
			Pathtracer(std::shared_ptr<core::GraphNode> graph_root, RayGeneratorType ray_generator);
			Pathtracer(RayGeneratorType ray_generator);
36
			Pathtracer(std::shared_ptr<SceneCollector> collector);
37
			Pathtracer(std::shared_ptr<SceneCollector> collector, RayGeneratorType ray_generator);
38
			~Pathtracer();
unknown's avatar
unknown committed
39

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

42
			const core::TextureRGBA_32F &render(uint32_t width, uint32_t height);
43
			void renderToScreen(uint32_t width, uint32_t height);
unknown's avatar
unknown committed
44
45
46
			void saveRender(fs::path target) const;

			//template<typename DataStruct>
47
48
			void setGenerator(RayGeneratorType generator);
			RayGeneratorType getGenerator() const;
unknown's avatar
unknown committed
49
			void initialize(std::shared_ptr<SceneCollector> collector);
50
			void reload(std::shared_ptr<core::GraphNode> graph_root);
unknown's avatar
unknown committed
51

52
			void handle(messaging::message_t &message) override;
unknown's avatar
unknown committed
53
54
55
56
57
58

			void reset();

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

Johannes Braun's avatar
Johannes Braun committed
59
			const core::Program& shader() const;
unknown's avatar
unknown committed
60
61
62
			core::Buffer<gl::BufferType::eShaderStorage>& traceBuffer() const;
			const core::TextureRGBA_32F& renderTarget() const;
			std::shared_ptr<SceneCollector> collector() const;
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
			unsigned currentSample() const;

			void setEffectBounces(EffectType type, uint8_t bounces);
			uint8_t getEffectBounces(EffectType type);

			void setLinespaceBounceThresholds(EffectType type, uint8_t bounces);
			uint8_t getLinespaceBounceThreshold(EffectType type);

			void setSkybox(std::shared_ptr<core::Skybox> skybox);
			std::shared_ptr<core::Skybox> Pathtracer::getSkybox() const;

			void setBounces(unsigned count);
			unsigned getBounces() const;

			void setMaxSamples(unsigned count);
			unsigned getMaxSamples() const;

			void setSamplesPerFrame(unsigned count);
			unsigned getSamplesPerFrame() const;

			float getClampDirect() const;
			void setClampDirect(float clamp_direct);
unknown's avatar
unknown committed
85

86
87
			float getClampIndirect() const;
			void setClampIndirect(float clamp_indirect);
88
			
89
90
			float getAccuracyThreshold() const;
			void setAccuracyThreshold(float accuracy_threshold);
91

92
93
			float getShadowThreshold() const;
			void setShadowThreshold(float shadow_threshold);
94

95
96
			float getDistanceThreshold() const;
			void setDistanceThreshold(float distance_threshold);
97
98
99
100
101
102
103
104
105
			struct {
				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;

106
107
108
109
110

		private:
			uint32_t m_last_width = 0;
			uint32_t m_last_height = 0;

111
112
113
			struct {
				float accuracy_threshold;
				float shadow_threshold;
114
				uint32_t bounce_thresholds;
115
				float distance_threshold;
116
			} m_linespace_config;
unknown's avatar
unknown committed
117

118
119
			std::array<uint8_t, 4> m_bounce_count_thresholds;
			std::array<uint8_t, 4> m_ls_bounce_count_thresholds;
unknown's avatar
unknown committed
120
				
unknown's avatar
unknown committed
121
122
123
			std::shared_ptr<SceneCollector> m_collector;
			std::unique_ptr<core::TextureRGBA_32F> m_render_target;
			std::unique_ptr<core::TextureRGBA_32F> m_color_store;
Johannes Braun's avatar
Johannes Braun committed
124
			std::unique_ptr<core::Program> m_render_shader;
unknown's avatar
unknown committed
125
126
127
			std::unique_ptr<core::Buffer<gl::BufferType::eShaderStorage>> m_trace_buffer;
			std::shared_ptr<core::Skybox> m_skybox;

128
			RayGeneratorType m_generator_type = RayGeneratorType::eTrace;
unknown's avatar
unknown committed
129
130
131
132
		};
	}
}

133
#endif //INCLUDE_PATHTRACER_H