Enabling 'Freeze camera used for chunk culling' from GUI. Helpful for culling debugging

This commit is contained in:
Erik Broberg
2016-05-11 18:38:19 -04:00
parent afd8ba5e9b
commit 0c9ce5af70
6 changed files with 55 additions and 13 deletions
+12 -4
View File
@@ -73,34 +73,42 @@ namespace openspace {
}
Chunk::Status Chunk::update(const RenderData& data) {
Camera* savedCamera = _owner->getSavedCamera();
const Camera& camRef = savedCamera != nullptr ? *savedCamera : data.camera;
RenderData myRenderData = { camRef, data.position, data.doPerformanceMeasurement };
//In the current implementation of the horizon culling and the distance to the
//camera, the closer the ellipsoid is to a
//sphere, the better this will make the splitting. Using the minimum radius to
//be safe. This means that if the ellipsoid has high difference between radii,
//splitting might accur even though it is not needed.
_isVisible = true;
const Ellipsoid& ellipsoid = _owner->ellipsoid();
// Do horizon culling
const int maxHeight = 8700; // should be read from gdal dataset or mod file
_isVisible = HorizonCuller::isVisible(data, _surfacePatch, ellipsoid, maxHeight);
_isVisible = HorizonCuller::isVisible(myRenderData, _surfacePatch, ellipsoid, maxHeight);
if (!_isVisible) {
return WANT_MERGE;
}
// Do frustum culling
_isVisible = FrustumCuller::isVisible(data, _surfacePatch, ellipsoid);
_isVisible = FrustumCuller::isVisible(myRenderData, _surfacePatch, ellipsoid);
if (!_isVisible) {
return WANT_MERGE;
}
auto center = _surfacePatch.center();
Vec3 globePosition = data.position.dvec3();
Vec3 globePosition = myRenderData.position.dvec3();
Vec3 patchPosition = globePosition + ellipsoid.geodetic2ToCartesian(center);
Vec3 cameraPosition = data.camera.position().dvec3();
Vec3 cameraPosition = myRenderData.camera.position().dvec3();
Vec3 cameraToChunk = patchPosition - cameraPosition;
Scalar minimumGlobeRadius = ellipsoid.minimumRadius();
@@ -59,7 +59,9 @@ namespace openspace {
, _rightRoot(new ChunkNode(Chunk(this, RIGHT_HEMISPHERE_INDEX)))
, minSplitDepth(2)
, maxSplitDepth(22)
, _savedCamera(nullptr)
{
auto geometry = std::shared_ptr<BasicGrid>(new BasicGrid(
100,
100,
@@ -76,11 +76,14 @@ namespace openspace {
const int minSplitDepth;
const int maxSplitDepth;
RenderData* getSavedRenderData() const {
return _savedRenderData;
};
Camera* getSavedCamera() const { return _savedCamera; }
void setSaveCamera(Camera* c) {
if (_savedCamera != nullptr) delete _savedCamera;
_savedCamera = c;
}
private:
@@ -101,7 +104,8 @@ namespace openspace {
const Ellipsoid& _ellipsoid;
RenderData* _savedRenderData;
Camera* _savedCamera;
};
} // namespace openspace
@@ -26,7 +26,6 @@
#include <modules/globebrowsing/globes/globemesh.h>
#include <modules/globebrowsing/globes/clipmapglobe.h>
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
// open space includes
#include <openspace/engine/openspaceengine.h>
@@ -52,7 +51,15 @@ namespace openspace {
RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
: _tileProviderManager(std::shared_ptr<TileProviderManager>(new TileProviderManager))
, _saveOrThrowCamera(properties::BoolProperty("saveOrThrowCamera", "saveOrThrowCamera"))
{
setName("RenderableGlobe");
addProperty(_saveOrThrowCamera);
// Read the radii in to its own dictionary
Vec3 radii;
dictionary.getValue(keyRadii, radii);
@@ -98,8 +105,11 @@ namespace openspace {
//addSwitchValue(std::shared_ptr<ClipMapGlobe>(
// new ClipMapGlobe(_ellipsoid, _tileProviderManager)), 1e8);
_distanceSwitch.addSwitchValue(std::shared_ptr<ChunkedLodGlobe>(
new ChunkedLodGlobe(_ellipsoid, _tileProviderManager)), 1e9);
_chunkedLodGlobe = std::shared_ptr<ChunkedLodGlobe>(
new ChunkedLodGlobe(_ellipsoid, _tileProviderManager));
_distanceSwitch.addSwitchValue(_chunkedLodGlobe, 1e9);
_distanceSwitch.addSwitchValue(std::shared_ptr<GlobeMesh>(new GlobeMesh()), 1e10);
}
@@ -120,6 +130,18 @@ namespace openspace {
}
void RenderableGlobe::render(const RenderData& data) {
if (_saveOrThrowCamera.value()) {
_saveOrThrowCamera.setValue(false);
if (_chunkedLodGlobe->getSavedCamera() == nullptr) { // save camera
LDEBUG("Saving snapshot of camera!");
_chunkedLodGlobe->setSaveCamera(new Camera(data.camera));
}
else { // throw camera
LDEBUG("Throwing away saved camera!");
_chunkedLodGlobe->setSaveCamera(nullptr);
}
}
_distanceSwitch.render(data);
}
@@ -36,8 +36,9 @@
#include <modules/globebrowsing/meshes/trianglesoup.h>
#include <modules/globebrowsing/other/distanceswitch.h>
#include <modules/globebrowsing/globes/globemesh.h>
#include <modules/globebrowsing/geodetics/ellipsoid.h>
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
#include <modules/globebrowsing/geodetics/ellipsoid.h>
#include <modules/globebrowsing/other/tileprovidermanager.h>
namespace ghoul {
@@ -61,6 +62,7 @@ public:
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
private:
double _time;
@@ -70,8 +72,11 @@ private:
//std::vector<std::string> _heightMapKeys;
//std::vector<std::string> _colorTextureKeys;
std::shared_ptr<TileProviderManager> _tileProviderManager;
std::shared_ptr<TileProviderManager> _tileProviderManager;
std::shared_ptr<ChunkedLodGlobe> _chunkedLodGlobe;
properties::BoolProperty _saveOrThrowCamera;
DistanceSwitch _distanceSwitch;
};