1 #pragma once
2 
3 #include "SyntopiaCore/Math/Vector3.h"
4 #include "../Object3D.h"
5 #include "AtomicCounter.h"
6 #include "VoxelStepper.h"
7 #include "Sampler.h"
8 #include "ProgressiveOutput.h"
9 #include "SyntopiaCore/Math/Random.h"
10 
11 namespace SyntopiaCore {
12 	namespace GLEngine {
13 
14 		using namespace SyntopiaCore::Math;
15 
16 
17 		class RenderThread : public QThread {
18 		public:
19 			enum Task { Raytrace, RaytraceProgressive } ;
20 			RenderThread();
21 			~RenderThread();
setTask(Task task)22 			void setTask(Task task) { this->task = task; };
23 			RenderThread(const RenderThread& other);
24 			void raytrace(int newUnit);
25 			void raytraceProgressive(int newUnit);
26 			void setCounters(AtomicCounter* nextUnit, AtomicCounter* completedUnits, int maxUnits);
27 			void alloc(int w, int h);
28 			void setObjects(int count);
msleep(int i)29 			static void msleep(int i) { QThread::msleep(i); }
30 			void run();
31 			Vector3f rayCastPixel(float x, float y);
setTerminated(bool value)32 			void setTerminated(bool value) { terminated = value; }
seed(int value)33 			void seed(int value) { rg.setSeed(value); };
34 			double getAOStrength(Object3D* object, Vector3f objectNormal, Vector3f objectIntersection);
35 			Vector3f rayCast(Vector3f startPoint, Vector3f direction, Object3D* excludeThis, int level = 0);
36 
37 		private:
38 			Task task;
39 			AtomicCounter* nextUnit;
40 			AtomicCounter* completedUnits;
41 			int maxUnits;
42 			int w;
43 			int h;
44 
45 			bool terminated;
46 
47 			Vector3f frontStart;
48 			Vector3f frontX;
49 			Vector3f frontY;
50 			Vector3f backStart;
51 			Vector3f backX;
52 			Vector3f backY;
53 
54 			Vector3f lightPos;
55 			Vector3f backgroundColor;
56 			int rayID;
57 			QVector<int> rayIDs;
58 			int pixels;
59 			int maxDepth;
60 			int checks;
61 			VoxelStepper* accelerator;
62 
63 			int aoSamples;
64 			int totalAOCasts;
65 			int aaSamples;
66 			int width;
67 			int height;
68 			bool useShadows;
69 			double dofCenter;
70 			double dofFalloff;
71 
72 			Math::RandomNumberGenerator rg;
73 
74 			Vector3f color;
75 			bool copy;
76 
77 			Sampler* sampler;
78 			ProgressiveOutput* progressiveOutput;
79 			friend class RayTracer;
80 			int rayNumber;
81 			Filter* filter;
82 		};
83 
84 
85 
86 	}
87 }
88 
89