X-Git-Url: http://git.euphorik.ch/?p=GPU.git;a=blobdiff_plain;f=WCudaMSE%2FStudent_Cuda_Image%2Fsrc%2Fcpp%2Fcore%2F04_RayTracing%2Fmoo%2Fhost%2FRayTracing.cu;fp=WCudaMSE%2FStudent_Cuda_Image%2Fsrc%2Fcpp%2Fcore%2F04_RayTracing%2Fmoo%2Fhost%2FRayTracing.cu;h=36e3862fb35adaa23a1c69033e0d24cffe467018;hp=0000000000000000000000000000000000000000;hb=ebdad7dc732d4742d09fd72d312175cb07d27a59;hpb=00dcb50daad8129676832b0b646e675770ee51a0 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 index 0000000..36e3862 --- /dev/null +++ b/WCudaMSE/Student_Cuda_Image/src/cpp/core/04_RayTracing/moo/host/RayTracing.cu @@ -0,0 +1,79 @@ +#include +#include +#include +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<<>>(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)) + } + }