diff --git a/src/definition/SurfaceMaterial.cpp b/src/definition/SurfaceMaterial.cpp index 42ddebc..59ada29 100644 --- a/src/definition/SurfaceMaterial.cpp +++ b/src/definition/SurfaceMaterial.cpp @@ -3,6 +3,8 @@ #include "PackStream.h" #include "Color.h" +static SurfaceMaterial DEFAULT; + SurfaceMaterial::SurfaceMaterial(): SurfaceMaterial(COLOR_BLACK) { @@ -28,6 +30,11 @@ SurfaceMaterial::~SurfaceMaterial() delete base; } +const SurfaceMaterial &SurfaceMaterial::getDefault() +{ + return DEFAULT; +} + void SurfaceMaterial::setColor(double r, double g, double b, double a) { base->r = r; diff --git a/src/definition/SurfaceMaterial.h b/src/definition/SurfaceMaterial.h index 2d8f988..e085622 100644 --- a/src/definition/SurfaceMaterial.h +++ b/src/definition/SurfaceMaterial.h @@ -14,6 +14,8 @@ public: SurfaceMaterial(const SurfaceMaterial &other); ~SurfaceMaterial(); + static const SurfaceMaterial &getDefault(); + void setColor(double r, double g, double b, double a); void save(PackStream *stream) const; diff --git a/src/render/opengl/OpenGLRenderer.cpp b/src/render/opengl/OpenGLRenderer.cpp index 8362684..1dc7e44 100644 --- a/src/render/opengl/OpenGLRenderer.cpp +++ b/src/render/opengl/OpenGLRenderer.cpp @@ -242,7 +242,7 @@ double OpenGLRenderer::getPrecision(const Vector3 &) return 0.0000001; } -Color OpenGLRenderer::applyMediumTraversal(Vector3, Color color) +Color OpenGLRenderer::applyMediumTraversal(const Vector3&, const Color &color) { return color; } diff --git a/src/render/opengl/OpenGLRenderer.h b/src/render/opengl/OpenGLRenderer.h index af848a3..134fd9a 100644 --- a/src/render/opengl/OpenGLRenderer.h +++ b/src/render/opengl/OpenGLRenderer.h @@ -67,7 +67,7 @@ public: inline OpenGLSharedState* getSharedState() const {return shared_state;} virtual double getPrecision(const Vector3 &location) override; - virtual Color applyMediumTraversal(Vector3 location, Color color) override; + virtual Color applyMediumTraversal(const Vector3 &location, const Color &color) override; private: /** diff --git a/src/render/software/AtmosphereRenderer.cpp b/src/render/software/AtmosphereRenderer.cpp index 9ae2ff4..ac2e446 100644 --- a/src/render/software/AtmosphereRenderer.cpp +++ b/src/render/software/AtmosphereRenderer.cpp @@ -83,7 +83,7 @@ BaseAtmosphereRenderer::BaseAtmosphereRenderer(SoftwareRenderer* renderer): { } -AtmosphereResult BaseAtmosphereRenderer::applyAerialPerspective(Vector3, Color base) +AtmosphereResult BaseAtmosphereRenderer::applyAerialPerspective(const Vector3 &, const Color &base) { AtmosphereResult result; result.base = result.final = base; @@ -91,7 +91,7 @@ AtmosphereResult BaseAtmosphereRenderer::applyAerialPerspective(Vector3, Color b return result; } -AtmosphereResult BaseAtmosphereRenderer::getSkyColor(Vector3) +AtmosphereResult BaseAtmosphereRenderer::getSkyColor(const Vector3 &) { AtmosphereResult result; result.base = result.final = COLOR_WHITE; @@ -127,7 +127,7 @@ SoftwareBrunetonAtmosphereRenderer::~SoftwareBrunetonAtmosphereRenderer() delete model; } -AtmosphereResult SoftwareBrunetonAtmosphereRenderer::applyAerialPerspective(Vector3 location, Color base) +AtmosphereResult SoftwareBrunetonAtmosphereRenderer::applyAerialPerspective(const Vector3 &location, const Color &base) { AtmosphereDefinition* definition = getDefinition(); AtmosphereResult result; @@ -151,7 +151,7 @@ AtmosphereResult SoftwareBrunetonAtmosphereRenderer::applyAerialPerspective(Vect return result; } -AtmosphereResult SoftwareBrunetonAtmosphereRenderer::getSkyColor(Vector3 direction) +AtmosphereResult SoftwareBrunetonAtmosphereRenderer::getSkyColor(const Vector3 &direction) { AtmosphereDefinition* definition; Vector3 sun_direction, sun_position, camera_location; @@ -161,13 +161,13 @@ AtmosphereResult SoftwareBrunetonAtmosphereRenderer::getSkyColor(Vector3 directi camera_location = parent->getCameraLocation(VECTOR_ZERO); sun_direction = getSunDirection(); - direction = direction.normalize(); + Vector3 direction_norm = direction.normalize(); sun_position = sun_direction.scale(SUN_DISTANCE_SCALED); base = COLOR_BLACK; // Get night sky - base = base.add(parent->getNightSky()->getColor(camera_location.y, direction)); + base = base.add(parent->getNightSky()->getColor(camera_location.y, direction_norm)); // Get sun shape /*if (v3Dot(sun_direction, direction) >= 0) @@ -196,11 +196,11 @@ AtmosphereResult SoftwareBrunetonAtmosphereRenderer::getSkyColor(Vector3 directi // Get scattering AtmosphereResult result; - Vector3 location = camera_location.add(direction.scale(6421.0)); + Vector3 location = camera_location.add(direction_norm.scale(6421.0)); switch (definition->model) { case AtmosphereDefinition::ATMOSPHERE_MODEL_BRUNETON: - result = model->getSkyColor(camera_location, direction, sun_position, base); + result = model->getSkyColor(camera_location, direction_norm, sun_position, base); break; default: result = BaseAtmosphereRenderer::applyAerialPerspective(location, result.base); diff --git a/src/render/software/AtmosphereRenderer.h b/src/render/software/AtmosphereRenderer.h index 7f22aec..f29fa58 100644 --- a/src/render/software/AtmosphereRenderer.h +++ b/src/render/software/AtmosphereRenderer.h @@ -14,8 +14,8 @@ public: BaseAtmosphereRenderer(SoftwareRenderer* parent); virtual ~BaseAtmosphereRenderer() {} - virtual AtmosphereResult applyAerialPerspective(Vector3 location, Color base); - virtual AtmosphereResult getSkyColor(Vector3 direction); + virtual AtmosphereResult applyAerialPerspective(const Vector3 &location, const Color &base); + virtual AtmosphereResult getSkyColor(const Vector3 &direction); virtual Vector3 getSunDirection(bool cache=true) const; virtual bool getLightsAt(std::vector &result, const Vector3 &location) const override; @@ -31,8 +31,8 @@ public: SoftwareBrunetonAtmosphereRenderer(SoftwareRenderer* parent); virtual ~SoftwareBrunetonAtmosphereRenderer(); - virtual AtmosphereResult applyAerialPerspective(Vector3 location, Color base) override; - virtual AtmosphereResult getSkyColor(Vector3 direction) override; + virtual AtmosphereResult applyAerialPerspective(const Vector3 &location, const Color &base) override; + virtual AtmosphereResult getSkyColor(const Vector3 &direction) override; virtual bool getLightsAt(std::vector &result, const Vector3 &location) const override; diff --git a/src/render/software/SoftwareRenderer.cpp b/src/render/software/SoftwareRenderer.cpp index a9fff9e..45e93e7 100644 --- a/src/render/software/SoftwareRenderer.cpp +++ b/src/render/software/SoftwareRenderer.cpp @@ -117,14 +117,11 @@ Color SoftwareRenderer::applyLightingToSurface(const Vector3 &location, const Ve return lighting->apply(getCameraLocation(location), location, normal, material); } -Color SoftwareRenderer::applyMediumTraversal(Vector3 location, Color color) +Color SoftwareRenderer::applyMediumTraversal(const Vector3 &location, const Color &color) { - color = atmosphere_renderer->applyAerialPerspective(location, color).final; - color = clouds_renderer->getColor(getCameraLocation(location), location, color); - return color; - - /*Vector3 eye = cameraGetLocation(scenery->getCamera()); - return fluid_medium->applyTraversal(eye, location, color);*/ + Color result = atmosphere_renderer->applyAerialPerspective(location, color).final; + result = clouds_renderer->getColor(getCameraLocation(location), location, result); + return result; } RayCastingResult SoftwareRenderer::rayWalking(const Vector3 &location, const Vector3 &direction, int, int, int, int) diff --git a/src/render/software/SoftwareRenderer.h b/src/render/software/SoftwareRenderer.h index 0bf60e2..63bf250 100644 --- a/src/render/software/SoftwareRenderer.h +++ b/src/render/software/SoftwareRenderer.h @@ -59,7 +59,7 @@ public: inline GodRaysSampler* getGodRaysSampler() const {return godrays;} virtual Color applyLightingToSurface(const Vector3 &location, const Vector3 &normal, const SurfaceMaterial &material); - virtual Color applyMediumTraversal(Vector3 location, Color color); + virtual Color applyMediumTraversal(const Vector3 &location, const Color &color); virtual RayCastingResult rayWalking(const Vector3 &location, const Vector3 &direction, int terrain, int water, int sky, int clouds); private: