--- /dev/null
+#include <iostream>
+#include <stdio.h>
+using namespace std;
+
+#include "Indice2D.h"
+#include "IndiceTools.h"
+#include "cudaTools.h"
+#include "Device.h"
+
+#include "RayTracingDevice.h"
+#include "RayTracingMath.h"
+
+__global__
+void rayTracing(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, float t)
+ {
+ const int TID = Indice2D::tid();
+ const int NB_THREAD = Indice2D::nbThread();
+ const int WH = w * h;
+
+ RayTracingMath rayTracing; // TODO: prendre
+
+ uchar4 color;
+ color.w = 255; // Par défaut, l'image est opaque.
+
+ double x, y;
+ int pixelI, pixelJ;
+
+ int s = TID;
+ while (s < WH)
+ {
+ IndiceTools::toIJ(s, w, &pixelI, &pixelJ); // update (pixelI, pixelJ)
+
+ // (i,j) domaine écran.
+ // (x,y) domaine math.
+ // domaineMath.toXY(pixelI, pixelJ, &x, &y); // (i,j) -> (x,y).
+
+ // newtonMath.colorXY(&color, x, y);
+
+ ptrDevPixels[s] = color;
+
+ s += NB_THREAD;
+ }
+ }
--- /dev/null
+#ifndef RAY_TRACING_DEVICE_H
+#define RAY_TRACING_DEVICE_H
+
+#include "DomaineMath.h"
+
+__global__
+void rayTracing(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, float t);
+
+#endif
--- /dev/null
+#ifndef SPHERE_H
+#define SPHERE_H
+
+#include "cudaTools.h"
+#include "cudaType_CPU.h"
+#include "mathTools.h"
+
+#endif
+class Sphere
+ {
+ public:
+ __host__
+ Sphere(float3 centre, float r, float hue) :
+ centre(centre),
+ hueInitial(hue)
+ {
+ this->setR(r);
+ }
+
+ __host__
+ Sphere()
+ {
+ }
+
+ __host__
+ void setCentre(float3 centre)
+ {
+ this->centre = centre;
+ }
+
+ __host__
+ void setR(float r)
+ {
+ this->r = r;
+ this->rCarre = r*r;
+ }
+
+ __host__
+ void setHueInitial(float hue)
+ {
+ this->hueInitial = hue;
+ }
+
+ __device__
+ float hCarre(float2 xySol)
+ {
+ float a = (centre.x - xySol.x);
+ float b = (centre.y - xySol.y);
+ return a * a + b * b;
+ }
+
+ __device__
+ bool isEnDessous(float hCarre)
+ {
+ return hCarre < rCarre;
+ }
+
+ __device__
+ float dz(float hCarre)
+ {
+ return sqrtf(rCarre - hCarre);
+ }
+
+ __device__
+ float brightness(float dz)
+ {
+ return dz / r;
+ }
+
+ __device__
+ float distance(float dz)
+ {
+ return centre.z - dz;
+ }
+
+ __device__
+ float getHueInitial()
+ {
+ return this->hueInitial;
+ }
+
+ __device__
+ float hue(float t) // usefull for animation
+ {
+ return 0.5 + 0.5 * sin(t + T + 3 * PI / 2);
+ }
+
+ private:
+ float r;
+ float3 centre;
+ float hueInitial;
+ float rCarre;
+
+ float T; // Utilisé pour l'animation.
+ };
+#endif
--- /dev/null
+#ifndef RAY_TRACING_MATH_H
+#define RAY_TRACING_MATH_H
+
+class RayTracingMath
+ {
+
+ };
+
+#endif
--- /dev/null
+#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))
+ }
+ }
--- /dev/null
+#ifndef RAY_TRACING_H
+#define RAY_TRACING_H
+
+#include "cudaTools.h"
+#include "Animable_I.h"
+#include "MathTools.h"
+#include "Sphere.h"
+
+class RayTracing : public Animable_I
+ {
+ public:
+ RayTracing(int w, int h);
+ ~RayTracing();
+
+ void runGPU(uchar4* ptrDevPixels) /*override*/;
+ void animationStep() /*override*/;
+
+ int getW() /*override*/;
+ int getH() /*override*/;
+
+ float getT() /*override*/;
+
+ string getTitle(void) /*override*/;
+
+ private:
+ Sphere* createSpheres(int n);
+
+ float t;
+
+ const int w;
+ const int h;
+
+ const dim3 dg;
+ const dim3 db;
+
+ const string title;
+ };
+
+#endif
--- /dev/null
+#include "RayTracingProvider.h"
+
+RayTracing* RayTracingProvider::create()
+ {
+ int dw = 16 * 50;
+ int dh = 16 * 50;
+
+ return new RayTracing(dw, dh);
+ }
+
+ImageFonctionel* RayTracingProvider::createGL()
+ {
+ ColorRGB_01* ptrColorTitre = new ColorRGB_01(0, 0, 0);
+ return new ImageFonctionel(create(), ptrColorTitre); // both ptr destroy by destructor of ImageFonctionel
+ }
--- /dev/null
+#ifndef RAYTRACING_PROVIDER_H
+#define RAYTRACING_PROVIDER_H
+
+#include "RayTracing.h"
+#include "ImageFonctionel.h"
+
+class RayTracingProvider
+ {
+ public:
+ static RayTracing* create();
+ static ImageFonctionel* createGL();
+ };
+
+#endif