Ray tracing (pas termine).
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 04_RayTracing / moo / host / RayTracing.cu
diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/04_RayTracing/moo/host/RayTracing.cu b/WCudaMSE/Student_Cuda_Image/src/cpp/core/04_RayTracing/moo/host/RayTracing.cu
new file mode 100644 (file)
index 0000000..36e3862
--- /dev/null
@@ -0,0 +1,79 @@
+#include <iostream>
+#include <assert.h>
+#include <stdio.h>
+using namespace std;
+
+#include "AleaTools.h"
+
+#include "RayTracing.h"
+#include "Device.h"
+#include "RayTracingDevice.h"
+
+RayTracing::RayTracing(int w, int h)
+    : w(w), h(h),
+      dg(8, 8, 1),
+      db(32, 32, 1),
+      title("Ray Tracing")
+    {
+    Device::assertDim(dg, db);
+
+    const int nbSpheres = 10;
+    Sphere* = this->createSpheres(10);
+
+
+    // Copie les spheres dans la constant memory.
+    }
+
+RayTracing::~RayTracing()
+    {
+    delete this->ptrDomaineMathInit;
+    }
+
+void RayTracing::runGPU(uchar4* ptrDevPixels, const DomaineMath& domaineMath)
+    {
+    rayTracing<<<dg,db>>>(ptrDevPixels, this->w, this->h, domaineMath, this->t);
+
+    HANDLE_ERROR(cudaDeviceSynchronize()); // Pour flusher les 'printf' (pour le DEBUG).
+    }
+
+void RayTracing::animationStep()
+    {
+    this->t += 0.1; // TODO
+    }
+
+int RayTracing::getW()
+    {
+    return this->w;
+    }
+
+int RayTracing::getH()
+    {
+    return this->h;
+    }
+
+float RayTracing::getT()
+    {
+    return this->t;
+    }
+
+string RayTracing::getTitle()
+    {
+    return this->title;
+    }
+
+Sphere* createSpheres(int n)
+    {
+    Sphere* spheres = new Sphere[n];
+    const float bord = 200;
+
+    for (int i = 0; i < n; ++i)
+        {
+        spheres[i].setR(float(AleaTools::uniformeAB(20, this->w / 10 - 1)));
+        spheres[i].setCentre(float3 {
+                float(AleaTools::uniformeAB(bord, this->w - bord)),
+                float(AleaTools::uniformeAB(bord, this->h - bord)),
+                float(AleaTools::uniformeAB(10, 2.0 * this->w))
+            });
+        spheres[i].setHue(float(AleaTools::uniformeAB(0, 1))
+        }
+    }