Implémentation du raytracing pour Global Memory/Shared Memory/Constant Memory
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 04_RayTracing / moo / device / Sphere.h
index a437dab..3c8df6e 100644 (file)
@@ -7,19 +7,28 @@
 class Sphere
     {
     public:
-        __host__
+        /*__host__
         Sphere(float3 centre, float r, float hue) :
             centre(centre),
             hueInitial(hue)
             {
             this->setR(r);
-            }
+            }*/
 
         __host__
+        __device__
         Sphere()
             {
             }
 
+        /*Sphere(const Sphere& other) :
+            r(other.r),
+            centre(other.centre),
+            rCarre(other.rCarre),
+            T(other.T)
+            {
+            }*/
+
         __host__
         void setCentre(const float3& centre)
             {
@@ -30,64 +39,74 @@ class Sphere
         void setR(float r)
             {
             this->r = r;
-            this->rCarre = r*r;
+            this->rCarre = r * r;
             }
 
         __host__
         void setHueInitial(float hue)
             {
-            this->hueInitial = hue;
+            this->T = asinf(2 * hue - 1) - 3 * PI / 2;
             }
 
+        /*
+         * Calcul de h².
+         */
         __device__
-        float hCarre(float2 xySol)
+        float hSquare(float2 xySol) const
             {
-            float a = (centre.x - xySol.x);
-            float b = (centre.y - xySol.y);
+            const float a = (this->centre.x - xySol.x);
+            const float b = (this->centre.y - xySol.y);
             return a * a + b * b;
             }
 
+        /*
+         * Est-ce que la sphre se trouve en dessous d'un point (x, y) en fonction de h².
+         * Voir la méthode 'hCarre(..)'.
+         */
         __device__
-        bool isEnDessous(float hCarre)
+        bool isBelow(float hCarre) const
             {
-            return hCarre < rCarre;
+            return hCarre < this->rCarre;
             }
 
+        /*
+         * Hauteur du point de collision du rayon par rapport au centre de la sphère.
+         */
         __device__
-        float dz(float hCarre)
+        float dz(float hCarre) const
             {
             return sqrtf(rCarre - hCarre);
             }
 
         __device__
-        float brightness(float dz)
+        float distance(float dz) const
             {
-            return dz / r;
+            return this->centre.z - dz;
             }
 
+        /**
+         * Renvoie la le B de HSB compris entre 0 et 1.
+         */
         __device__
-        float distance(float dz)
+        float brightness(float dz) const
             {
-            return centre.z - dz;
+            return dz / this->r;
             }
 
+        /*
+         * La couleur
+         */
         __device__
-        float getHueInitial()
+        float hue(float t) const
             {
-            return this->hueInitial;
-            }
-
-        __device__
-        float hue(float t) // usefull for animation
-            {
-            return 0.5 + 0.5 * sin(t + T + 3 * PI / 2);
+            return 0.5 + 0.5 * sinf(t + this->T + 3 * PI / 2);
             }
 
     private:
-        float r;
-        float3 centre;
-        float hueInitial;
-        float rCarre;
+        float r; // Rayon.
+        float3 centre; // Position.
+
+        float rCarre; // Précalul de r².
 
         float T; // Utilisé pour l'animation.
     };