pathtracer.h 3.63 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
10

#include <engine/rendering/ShaderProgram.h>
#include <engine/rendering/GraphNode.h>
#include <engine/graphics/Skybox.h>
#include <util/images.h>
11
#include <util/messaging.h>
unknown's avatar
unknown committed
12

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

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

unknown's avatar
unknown committed
23
24
25
26
27
28
29
30
31
32
		enum class EffectType
		{
			eDiffuse = 0,
			eTranslucent = 1,
			eReflection = 2,
			eRefraction = 3,
			eTransparent = 4,
			eEmissive = 5
		};

33
		class Pathtracer : public messaging::Receiver
unknown's avatar
unknown committed
34
35
		{
		public:
36
37
38
39
40
			Pathtracer();
			Pathtracer(std::shared_ptr<RayGeneratorBase> ray_generator);
			Pathtracer(std::shared_ptr<SceneCollector> collector);
			Pathtracer(std::shared_ptr<SceneCollector> collector, std::shared_ptr<RayGeneratorBase> ray_generator);
			~Pathtracer();
unknown's avatar
unknown committed
41

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

44
			const core::TextureRGBA_32F &render(uint32_t width, uint32_t height);
unknown's avatar
unknown committed
45
46
47
48
49
50
			void saveRender(fs::path target) const;

			//template<typename DataStruct>
			void setGenerator(std::shared_ptr<RayGeneratorBase> generator);
			void initialize(std::shared_ptr<SceneCollector> collector);

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

			void reset();

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

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

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

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

94
95
			float getDistanceThreshold() const;
			void setDistanceThreshold(float distance_threshold);
96

unknown's avatar
unknown committed
97
98
99
100
		private:
			uint32_t m_last_width = 0;
			uint32_t m_last_height = 0;

101
102
103
104
105
106
107
108
109
110
111
112
			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;

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

unknown's avatar
unknown committed
117
			std::array<uint8_t, 8> m_bounce_count_thresholds;
118
			std::array<uint8_t, 8> m_ls_bounce_count_thresholds;
unknown's avatar
unknown committed
119
				
unknown's avatar
unknown committed
120
121
122
123
124
125
126
127
128
129
130
131
			std::shared_ptr<SceneCollector> m_collector;
			std::unique_ptr<core::TextureRGBA_32F> m_render_target;
			std::unique_ptr<core::TextureRGBA_32F> m_color_store;
			std::unique_ptr<core::ShaderProgram> m_render_shader;
			std::unique_ptr<core::Buffer<gl::BufferType::eShaderStorage>> m_trace_buffer;
			std::shared_ptr<core::Skybox> m_skybox;

			std::shared_ptr<RayGeneratorBase> m_ray_generator;
		};
	}
}

132
#endif //INCLUDE_PATHTRACER_H