Ray tracing (pas termine).
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 04_RayTracing / moo / host / RayTracing.cu
1 #include <iostream>
2 #include <assert.h>
3 #include <stdio.h>
4 using namespace std;
5
6 #include "AleaTools.h"
7
8 #include "RayTracing.h"
9 #include "Device.h"
10 #include "RayTracingDevice.h"
11
12 RayTracing::RayTracing(int w, int h)
13     : w(w), h(h),
14       dg(8, 8, 1),
15       db(32, 32, 1),
16       title("Ray Tracing")
17     {
18     Device::assertDim(dg, db);
19
20     const int nbSpheres = 10;
21     Sphere* = this->createSpheres(10);
22
23
24     // Copie les spheres dans la constant memory.
25     }
26
27 RayTracing::~RayTracing()
28     {
29     delete this->ptrDomaineMathInit;
30     }
31
32 void RayTracing::runGPU(uchar4* ptrDevPixels, const DomaineMath& domaineMath)
33     {
34     rayTracing<<<dg,db>>>(ptrDevPixels, this->w, this->h, domaineMath, this->t);
35
36     HANDLE_ERROR(cudaDeviceSynchronize()); // Pour flusher les 'printf' (pour le DEBUG).
37     }
38
39 void RayTracing::animationStep()
40     {
41     this->t += 0.1; // TODO
42     }
43
44 int RayTracing::getW()
45     {
46     return this->w;
47     }
48
49 int RayTracing::getH()
50     {
51     return this->h;
52     }
53
54 float RayTracing::getT()
55     {
56     return this->t;
57     }
58
59 string RayTracing::getTitle()
60     {
61     return this->title;
62     }
63
64 Sphere* createSpheres(int n)
65     {
66     Sphere* spheres = new Sphere[n];
67     const float bord = 200;
68
69     for (int i = 0; i < n; ++i)
70         {
71         spheres[i].setR(float(AleaTools::uniformeAB(20, this->w / 10 - 1)));
72         spheres[i].setCentre(float3 {
73                 float(AleaTools::uniformeAB(bord, this->w - bord)),
74                 float(AleaTools::uniformeAB(bord, this->h - bord)),
75                 float(AleaTools::uniformeAB(10, 2.0 * this->w))
76             });
77         spheres[i].setHue(float(AleaTools::uniformeAB(0, 1))
78         }
79     }