#ifndef EX02_RAY_TRACER_HPP #define EX02_RAY_TRACER_HPP #define EX02_RAY_TRACER_VIEW_RATIO 0.5f #define EX02_RAY_TRACER_DEFAULT_NEAR_PLANE 0.2f #define EX02_RAY_TRACER_DEFAULT_FAR_PLANE 4.0f #define EX02_RAY_TRACER_COLL_INCREMENT 2.0f #define EX02_RAY_TRACER_GRAY_SPHERE_RADIUS 1.5f #include #include #include #include #include #include #include #include namespace Ex02 { namespace RT { struct Pixel { Pixel(); unsigned char r, g, b; }; class Image { public: Image(unsigned int width, unsigned int height); Pixel &getPixel(unsigned int x, unsigned int y); const Pixel &getPixel(unsigned int x, unsigned int y) const; void writeToFile(const std::string &filename) const; private: unsigned int width; std::vector data; }; namespace Internal { typedef std::optional> RTSVisibleType; struct LightSource { LightSource(); glm::vec3 pos; float falloffStart; float falloffEnd; glm::vec3 color; void applyLight(glm::vec3 pos, Pixel &pixelOut) const; void applyLight(glm::vec3 pos, Pixel &pixelOut, std::mutex *mutex) const; }; struct Sphere { Sphere(); glm::vec3 pos; float radius; std::optional rayToSphere(glm::vec3 rayPos, glm::vec3 rayDirUnit) const; RTSVisibleType rayToSphereVisible(glm::vec3 rayPos, glm::vec3 rayDirUnit, const LightSource &light) const; }; // returns pos of collision std::optional rayToSphere(glm::vec3 rayPos, glm::vec3 rayDirUnit, glm::vec3 spherePos, float sphereRadius); float angleBetweenRays(glm::vec3 a, glm::vec3 b); float distBetweenPositions(glm::vec3 a, glm::vec3 b); // first vec3 is result from rayToSphere(), second is ray to light source RTSVisibleType rayToSphereVisible(glm::vec3 rayPos, glm::vec3 rayDirUnit, glm::vec3 spherePos, float sphereRadius, glm::vec3 lightPos); } // namespace Internal Image renderGraySphere(unsigned int outputWidth, unsigned int outputHeight, unsigned int threadCount = 1); Image renderColorsWithSpheres(unsigned int outputWidth, unsigned int outputHeight, unsigned int threadCount = 1); } // namespace RT } // namespace Ex02 #endif