Do not rasterize vegetation when there is no layer

This commit is contained in:
Michaël Lemaire 2015-12-14 22:20:28 +01:00
parent a36570f5a6
commit 26cba26847
13 changed files with 71 additions and 16 deletions

View file

@ -203,9 +203,15 @@ static void testNearFrustum() {
SoftwareCanvasRenderer renderer(&scenery); SoftwareCanvasRenderer renderer(&scenery);
renderer.setSize(400, 300); renderer.setSize(400, 300);
renderer.setQuality(0.1); renderer.setQuality(0.1);
renderer.enablePostprocess(false);
startTestRender(&renderer, "near_frustum_good_raw");
renderer.enablePostprocess(true);
startTestRender(&renderer, "near_frustum_good"); startTestRender(&renderer, "near_frustum_good");
renderer.getWaterRasterizer()->setAutoCutLimit(1000.0); renderer.getWaterRasterizer()->setAutoCutLimit(1000.0);
renderer.enablePostprocess(false);
startTestRender(&renderer, "near_frustum_bad_raw");
renderer.enablePostprocess(true);
startTestRender(&renderer, "near_frustum_bad"); startTestRender(&renderer, "near_frustum_bad");
} }

View file

@ -21,7 +21,7 @@ struct paysages::software::ScanPoint {
double y; double y;
double z; double z;
} location; } location;
int client; unsigned short client;
bool front_facing; bool front_facing;
}; };
@ -32,7 +32,7 @@ struct paysages::software::RenderScanlines {
int right; int right;
}; };
Rasterizer::Rasterizer(SoftwareRenderer *renderer, RenderProgress *progress, int client_id, const Color &color) Rasterizer::Rasterizer(SoftwareRenderer *renderer, RenderProgress *progress, unsigned short client_id, const Color &color)
: renderer(renderer), progress(progress), client_id(client_id) { : renderer(renderer), progress(progress), client_id(client_id) {
this->color = new Color(color); this->color = new Color(color);

View file

@ -19,7 +19,7 @@ typedef struct RenderScanlines RenderScanlines;
*/ */
class SOFTWARESHARED_EXPORT Rasterizer { class SOFTWARESHARED_EXPORT Rasterizer {
public: public:
Rasterizer(SoftwareRenderer *renderer, RenderProgress *progress, int client_id, const Color &color); Rasterizer(SoftwareRenderer *renderer, RenderProgress *progress, unsigned short client_id, const Color &color);
virtual ~Rasterizer(); virtual ~Rasterizer();
inline SoftwareRenderer *getRenderer() const { inline SoftwareRenderer *getRenderer() const {

View file

@ -14,8 +14,8 @@
#define SPHERE_SIZE 20000.0 #define SPHERE_SIZE 20000.0
SkyRasterizer::SkyRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, int client_id) SkyRasterizer::SkyRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, unsigned short client_id)
: Rasterizer(renderer, progress, client_id, Color(0.9, 0.9, 1.0)) { : Rasterizer(renderer, progress, client_id, Color(0.7, 0.7, 1.0)) {
} }
int SkyRasterizer::prepareRasterization() { int SkyRasterizer::prepareRasterization() {

View file

@ -10,7 +10,7 @@ namespace software {
class SOFTWARESHARED_EXPORT SkyRasterizer : public Rasterizer { class SOFTWARESHARED_EXPORT SkyRasterizer : public Rasterizer {
public: public:
SkyRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, int client_id); SkyRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, unsigned short client_id);
virtual int prepareRasterization() override; virtual int prepareRasterization() override;
virtual void rasterizeToCanvas(CanvasPortion *canvas) override; virtual void rasterizeToCanvas(CanvasPortion *canvas) override;

View file

@ -12,8 +12,8 @@
#include "CanvasFragment.h" #include "CanvasFragment.h"
#include "RenderProgress.h" #include "RenderProgress.h"
TerrainRasterizer::TerrainRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, int client_id) TerrainRasterizer::TerrainRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, unsigned short client_id)
: Rasterizer(renderer, progress, client_id, Color(1.0, 0.9, 0.9)) { : Rasterizer(renderer, progress, client_id, Color(1.0, 0.7, 0.7)) {
setBackFaceCulling(true); setBackFaceCulling(true);
yoffset = 0.0; yoffset = 0.0;
} }

View file

@ -20,7 +20,7 @@ class SOFTWARESHARED_EXPORT TerrainRasterizer : public Rasterizer {
} TerrainChunkInfo; } TerrainChunkInfo;
public: public:
TerrainRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, int client_id); TerrainRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, unsigned short client_id);
/** /**
* Set the rasterization quality. * Set the rasterization quality.

View file

@ -1,18 +1,37 @@
#include "VegetationRasterizer.h" #include "VegetationRasterizer.h"
#include <cassert> #include <cassert>
#include "Scenery.h"
#include "CanvasFragment.h" #include "CanvasFragment.h"
#include "Color.h" #include "Color.h"
#include "SpaceSegment.h" #include "SpaceSegment.h"
#include "SoftwareRenderer.h" #include "SoftwareRenderer.h"
#include "VegetationDefinition.h"
#include "VegetationRenderer.h" #include "VegetationRenderer.h"
#include "RayCastingResult.h" #include "RayCastingResult.h"
VegetationRasterizer::VegetationRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, int client_id) VegetationRasterizer::VegetationRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, unsigned short client_id)
: TerrainRasterizer(renderer, progress, client_id) { : TerrainRasterizer(renderer, progress, client_id) {
setYOffset(0.5); setYOffset(0.5);
setColor(Color(0.8, 1.0, 0.8, 0.5)); setColor(Color(0.7, 1.0, 0.7, 0.5));
}
bool VegetationRasterizer::isUseful() const {
return renderer->getScenery()->getVegetation()->getMaxHeight() > 0.0;
}
int VegetationRasterizer::prepareRasterization() {
if (isUseful()) {
return TerrainRasterizer::prepareRasterization();
} else {
return 0;
}
}
void VegetationRasterizer::rasterizeToCanvas(CanvasPortion *canvas) {
if (isUseful()) {
TerrainRasterizer::rasterizeToCanvas(canvas);
}
} }
Color VegetationRasterizer::shadeFragment(const CanvasFragment &fragment, const CanvasFragment *previous) const { Color VegetationRasterizer::shadeFragment(const CanvasFragment &fragment, const CanvasFragment *previous) const {

View file

@ -10,8 +10,15 @@ namespace software {
class SOFTWARESHARED_EXPORT VegetationRasterizer : public TerrainRasterizer { class SOFTWARESHARED_EXPORT VegetationRasterizer : public TerrainRasterizer {
public: public:
VegetationRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, int client_id); VegetationRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, unsigned short client_id);
/**
* Returns true if the rasterization process is useful.
*/
bool isUseful() const;
virtual int prepareRasterization() override;
virtual void rasterizeToCanvas(CanvasPortion *canvas) override;
virtual Color shadeFragment(const CanvasFragment &fragment, const CanvasFragment *previous) const override; virtual Color shadeFragment(const CanvasFragment &fragment, const CanvasFragment *previous) const override;
}; };
} }

View file

@ -6,8 +6,8 @@
#include "CanvasFragment.h" #include "CanvasFragment.h"
#include "RenderProgress.h" #include "RenderProgress.h"
WaterRasterizer::WaterRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, int client_id) WaterRasterizer::WaterRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, unsigned short client_id)
: Rasterizer(renderer, progress, client_id, Color(0.9, 0.95, 1.0)) { : Rasterizer(renderer, progress, client_id, Color(0.7, 0.85, 1.0)) {
} }
static inline Vector3 _getFirstPassVertex(SoftwareRenderer *renderer, double x, double z) { static inline Vector3 _getFirstPassVertex(SoftwareRenderer *renderer, double x, double z) {

View file

@ -10,7 +10,7 @@ namespace software {
class WaterRasterizer : public Rasterizer { class WaterRasterizer : public Rasterizer {
public: public:
WaterRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, int client_id); WaterRasterizer(SoftwareRenderer *renderer, RenderProgress *progress, unsigned short client_id);
void rasterizeQuad(CanvasPortion *canvas, double x, double z, double size); void rasterizeQuad(CanvasPortion *canvas, double x, double z, double size);

View file

@ -37,6 +37,7 @@ class Rasterizer;
class OverlayRasterizer; class OverlayRasterizer;
class SkyRasterizer; class SkyRasterizer;
class TerrainRasterizer; class TerrainRasterizer;
class VegetationRasterizer;
class LightingManager; class LightingManager;
class LightStatus; class LightStatus;

View file

@ -0,0 +1,22 @@
#include "BaseTestCase.h"
#include "VegetationRasterizer.h"
#include "SoftwareCanvasRenderer.h"
#include "Scenery.h"
#include "VegetationDefinition.h"
#include "VegetationLayerDefinition.h"
TEST(VegetationRasterizer, isUseful) {
Scenery scenery;
SoftwareCanvasRenderer renderer(&scenery);
VegetationRasterizer rast(&renderer, renderer.getProgressHelper(), 0);
EXPECT_FALSE(rast.isUseful());
VegetationLayerDefinition layer(NULL, "test");
layer.applyPreset(VegetationLayerDefinition::VEGETATION_BASIC_TREES);
scenery.getVegetation()->addLayer(layer);
EXPECT_TRUE(rast.isUseful());
}