diff --git a/src/pe/raytracing/Raytracer.cpp b/src/pe/raytracing/Raytracer.cpp index f0c73e765f4cd21531dd4fc48364361dc3875dde..7eaed3b7f619bf3405cbe5bb92adf97eaca394ef 100644 --- a/src/pe/raytracing/Raytracer.cpp +++ b/src/pe/raytracing/Raytracer.cpp @@ -39,6 +39,7 @@ namespace raytracing { * \param cameraPosition Position of the camera in the global world frame. * \param lookAtPoint Point the camera looks at in the global world frame. * \param upVector Vector indicating the upwards direction of the camera. + * \param backgroundColor Background color of the scene. * \param blockAABBIntersectionPadding The padding applied in block AABB intersection pretesting. Usually not required. * Set it to the value of the farthest distance a object might protrude from * its containing block. @@ -49,12 +50,14 @@ Raytracer::Raytracer(const shared_ptr<BlockStorage> forest, BlockDataID storageI real_t fov_vertical, const Vec3& cameraPosition, const Vec3& lookAtPoint, const Vec3& upVector, const Lighting& lighting, + const Vec3& backgroundColor, real_t blockAABBIntersectionPadding) : forest_(forest), storageID_(storageID), globalBodyStorage_(globalBodyStorage), pixelsHorizontal_(pixelsHorizontal), pixelsVertical_(pixelsVertical), fov_vertical_(fov_vertical), cameraPosition_(cameraPosition), lookAtPoint_(lookAtPoint), upVector_(upVector), lighting_(lighting), + backgroundColor_(backgroundColor), blockAABBIntersectionPadding_(blockAABBIntersectionPadding), tBufferOutputEnabled_(false), imageOutputEnabled_(false), @@ -71,7 +74,7 @@ Raytracer::Raytracer(const shared_ptr<BlockStorage> forest, BlockDataID storageI * * The config block has to contain image_x (int), image_y (int), fov_vertical (real, in degrees) * and tbuffer_output_directory (string) parameters. Additionally a vector of reals - * for each of cameraPosition, lookAt and the upVector. Optional is blockAABBIntersectionPadding (real). + * for each of cameraPosition, lookAt and the upVector. Optional is blockAABBIntersectionPadding (real) and backgroundColor (Vec3). * To output both process local and global tbuffers after raytracing, set tbuffer_output_directory (string). * For image output after raytracing, set image_output_directory (string); for local image output additionally set * local_image_output_enabled (bool) to true. @@ -107,7 +110,8 @@ Raytracer::Raytracer(const shared_ptr<BlockStorage> forest, BlockDataID storageI lookAtPoint_ = config.getParameter<Vec3>("lookAt"); upVector_ = config.getParameter<Vec3>("upVector"); lighting_ = Lighting(config.getBlock("Lighting")); - + backgroundColor_ = config.getParameter<Vec3>("backgroundColor", Vec3(0.1, 0.1, 0.1)); + blockAABBIntersectionPadding_ = config.getParameter<real_t>("blockAABBIntersectionPadding", real_t(0.0)); setupView_(); diff --git a/src/pe/raytracing/Raytracer.h b/src/pe/raytracing/Raytracer.h index dee4ce7172e09600e7a02a4e2177adbd809988a9..fbaeff0ca3d95ab601a10004cc60e7e8fbf9b32c 100644 --- a/src/pe/raytracing/Raytracer.h +++ b/src/pe/raytracing/Raytracer.h @@ -59,6 +59,7 @@ public: real_t fov_vertical, const Vec3& cameraPosition, const Vec3& lookAtPoint, const Vec3& upVector, const Lighting& lighting, + const Vec3& backgroundColor = Vec3(0.1, 0.1, 0.1), real_t blockAABBIntersectionPadding = real_t(0.0)); explicit Raytracer(const shared_ptr<BlockStorage> forest, BlockDataID storageID, const shared_ptr<BodyStorage> globalBodyStorage, @@ -81,6 +82,7 @@ private: marks the center of the view plane.*/ Vec3 upVector_; //!< The vector indicating the upwards direction of the camera. Lighting lighting_; //!< The lighting of the scene. + Vec3 backgroundColor_; //!< Background color of the scene. real_t blockAABBIntersectionPadding_; /*!< The padding applied in block AABB intersection pretesting, as some objects within a block might protrude from the block's AABB.*/ @@ -113,6 +115,7 @@ public: inline const Vec3& getCameraPosition() const; inline const Vec3& getLookAtPoint() const; inline const Vec3& getUpVector() const; + inline const Vec3& getBackgroundColor() const; inline bool getTBufferOutputEnabled() const; inline const std::string& getTBufferOutputDirectory() const; inline bool getImageOutputEnabled() const; @@ -122,6 +125,7 @@ public: /*!\name Set functions */ //@{ + inline void setBackgroundColor(const Vec3& color); inline void setTBufferOutputEnabled(const bool enabled); inline void setTBufferOutputDirectory(const std::string& path); inline void setImageOutputEnabled(const bool enabled); @@ -203,7 +207,17 @@ inline const Vec3& Raytracer::getLookAtPoint() const { inline const Vec3& Raytracer::getUpVector() const { return upVector_; } - + +/*!\brief Returns the background color of the scene. + * + * \return Color. + * + * Returns the background color of the scene. + */ +inline const Vec3& Raytracer::getBackgroundColor() const { + return backgroundColor_; +} + /*!\brief Returns true if tbuffer output to a file is enabled. * * \return True if tbuffer output enabled, otherwise false. @@ -243,6 +257,14 @@ inline bool Raytracer::getLocalImageOutputEnabled() const { inline const std::string& Raytracer::getImageOutputDirectory() const { return imageOutputDirectory_; } + +/*!\brief Set the background color of the scene. + * + * \param color New background color. + */ +inline void Raytracer::setBackgroundColor(const Vec3& color) { + backgroundColor_ = color; +} /*!\brief Enable / disable outputting the tBuffer to a file in the specified directory. * \param enabled Set to true / false to enable / disable tbuffer output. @@ -507,15 +529,15 @@ inline Vec3 Raytracer::getColor(const BodyID body, const Ray& ray, real_t t, con real_t shininess = 100; if (body->getTypeID() == Plane::getStaticTypeID()) { - diffuseColor = Vec3(real_t(0.55), real_t(0.55), real_t(0.55)); + diffuseColor = Vec3(real_t(0.7), real_t(0.7), real_t(0.7)); ambientColor.set(real_t(0.5), real_t(0.5), real_t(0.5)); specularColor.set(real_t(0), real_t(0), real_t(0)); shininess = real_t(0); } if (body->getTypeID() == Sphere::getStaticTypeID()) { - diffuseColor = Vec3(real_t(0.5), real_t(0.5), real_t(0.5)); - ambientColor.set(real_t(0.4), real_t(0.4), real_t(0.4)); - specularColor.set(real_t(0.774597), real_t(0.774597), real_t(0.774597)); + diffuseColor = Vec3(real_t(0.98), real_t(0.1), real_t(0.1)); + ambientColor.set(real_t(0.6), real_t(0.05), real_t(0.05)); + specularColor.set(real_t(1), real_t(1), real_t(1)); shininess = real_t(30); } //---- @@ -537,7 +559,7 @@ inline Vec3 Raytracer::getColor(const BodyID body, const Ray& ray, real_t t, con } Vec3 color = multiplyColors(lighting_.ambientColor, ambientColor) - + multiplyColors(lighting_.diffuseColor, diffuseColor)*lambertian + + multiplyColors(lighting_.diffuseColor, diffuseColor)*lambertian//*real_c(pow(lambertian, real_t(4))) + multiplyColors(lighting_.specularColor, specularColor)*specular; real_t colorMax = color.max();