Add ability to disable vegetation rendering

It is disabled in opengl rendering for now
This commit is contained in:
Michaël Lemaire 2015-10-18 17:35:42 +02:00
parent b430f6037e
commit cd7f30ecae
4 changed files with 48 additions and 14 deletions

View file

@ -7,6 +7,7 @@
#include "OpenGLWater.h"
#include "OpenGLTerrain.h"
#include "CloudsRenderer.h"
#include "VegetationRenderer.h"
#include "Color.h"
#include "Scenery.h"
#include "LightingManager.h"
@ -61,6 +62,16 @@ OpenGLRenderer::~OpenGLRenderer()
delete shared_state;
}
void OpenGLRenderer::prepare()
{
SoftwareRenderer::prepare();
getCloudsRenderer()->setEnabled(false);
getLightingManager()->setSpecularity(false);
getGodRaysSampler()->setEnabled(false);
getVegetationRenderer()->setEnabled(false);
}
void OpenGLRenderer::initialize()
{
ready = functions->initializeOpenGLFunctions();
@ -71,10 +82,6 @@ void OpenGLRenderer::initialize()
prepare();
getCloudsRenderer()->setEnabled(false);
getLightingManager()->setSpecularity(false);
getGodRaysSampler()->setEnabled(false);
skybox->initialize();
skybox->updateScenery();

View file

@ -24,6 +24,8 @@ public:
inline OpenGLTerrain *getTerrain() const {return terrain;}
inline bool isDisplayed() const {return displayed;}
virtual void prepare() override;
void initialize();
void prepareOpenGLState();
void resize(int width, int height);

View file

@ -47,6 +47,11 @@ VegetationRenderer::VegetationRenderer(SoftwareRenderer *parent):
{
}
void VegetationRenderer::setEnabled(bool enabled)
{
this->enabled = enabled;
}
RayCastingResult VegetationRenderer::renderInstance(const SpaceSegment &segment, const VegetationInstance &instance, bool only_hit)
{
RayCastingResult final;
@ -71,12 +76,19 @@ RayCastingResult VegetationRenderer::renderInstance(const SpaceSegment &segment,
RayCastingResult VegetationRenderer::getResult(const SpaceSegment &segment, bool only_hit)
{
// Find instances potentially crossing the segment
// TODO Collect the nearest hit, don't stop at the first one
VegetationGridIterator it(segment, this, parent->getScenery()->getVegetation()->debug_model, only_hit);
if (not segment.projectedOnYPlane().scaled(1.0 / DEBUG_DENSITY_FACTOR).iterateOnGrid(it))
if (enabled)
{
return it.getResult();
// Find instances potentially crossing the segment
// TODO Collect the nearest hit, don't stop at the first one
VegetationGridIterator it(segment, this, parent->getScenery()->getVegetation()->debug_model, only_hit);
if (not segment.projectedOnYPlane().scaled(1.0 / DEBUG_DENSITY_FACTOR).iterateOnGrid(it))
{
return it.getResult();
}
else
{
return RayCastingResult();
}
}
else
{
@ -86,12 +98,19 @@ RayCastingResult VegetationRenderer::getResult(const SpaceSegment &segment, bool
bool VegetationRenderer::applyLightFilter(LightComponent &light, const Vector3 &at)
{
// Get segment to iterate
SpaceSegment segment(at, at.add(light.direction.scale(-1.0 * parent->render_quality)));
if (getResult(segment, true).hit)
if (enabled)
{
light.color = COLOR_BLACK;
return false;
// Get segment to iterate
SpaceSegment segment(at, at.add(light.direction.scale(-1.0 * parent->render_quality)));
if (getResult(segment, true).hit)
{
light.color = COLOR_BLACK;
return false;
}
else
{
return true;
}
}
else
{

View file

@ -13,6 +13,11 @@ class SOFTWARESHARED_EXPORT VegetationRenderer: public LightFilter
public:
VegetationRenderer(SoftwareRenderer *parent);
/**
* Totally enable or disable the vegetation layers rendering.
*/
void setEnabled(bool enabled);
inline SoftwareRenderer *getParent() const {return parent;}
/**
@ -29,6 +34,7 @@ public:
private:
SoftwareRenderer *parent;
bool enabled;
};
}