History

More work on LOD rendering; now rendering in preview.

Andrzej Kapolka committed 11 years ago

Commit 0a329bb1 parent 790b0855 files · +94 −81Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 5 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+71−59
@@ -550,10 +550,47 @@ void MetavoxelSystem::setVoxelMaterial(const SharedObjectPointer& spanner, const · 549 unmodified lines
550550 applyMaterialEdit(edit, true);
551551 }
552552
553−class SpannerCursorRenderVisitor : public SpannerVisitor {
553+class SpannerRenderVisitor : public SpannerVisitor {
554+public:
555+
556+ SpannerRenderVisitor(const MetavoxelLOD& lod);
557+
558+ virtual int visit(MetavoxelInfo& info);
559+ virtual bool visit(Spanner* spanner);
560+
561+protected:
562+
563+ int _containmentDepth;
564+};
565+
566+SpannerRenderVisitor::SpannerRenderVisitor(const MetavoxelLOD& lod) :
567+ SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(),
568+ QVector<AttributePointer>(), QVector<AttributePointer>(), lod,
569+ encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())),
570+ _containmentDepth(INT_MAX) {
571+}
572+
573+int SpannerRenderVisitor::visit(MetavoxelInfo& info) {
574+ if (_containmentDepth >= _depth) {
575+ Frustum::IntersectionType intersection = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType(
576+ info.getBounds());
577+ if (intersection == Frustum::NO_INTERSECTION) {
578+ return STOP_RECURSION;
579+ }
580+ _containmentDepth = (intersection == Frustum::CONTAINS_INTERSECTION) ? _depth : INT_MAX;
581+ }
582+ return SpannerVisitor::visit(info);
583+}
584+
585+bool SpannerRenderVisitor::visit(Spanner* spanner) {
586+ spanner->getRenderer()->render(_lod, _containmentDepth <= _depth);
587+ return true;
588+}
589+
590+class SpannerCursorRenderVisitor : public SpannerRenderVisitor {
554591 public:
555592
556− SpannerCursorRenderVisitor(const Box& bounds);
593+ SpannerCursorRenderVisitor(const MetavoxelLOD& lod, const Box& bounds);
557594
558595 virtual bool visit(Spanner* spanner);
559596
@@ -564,20 +601,20 @@ private: · 4 unmodified lines
564601 Box _bounds;
565602 };
566603
567−SpannerCursorRenderVisitor::SpannerCursorRenderVisitor(const Box& bounds) :
568− SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute()),
604+SpannerCursorRenderVisitor::SpannerCursorRenderVisitor(const MetavoxelLOD& lod, const Box& bounds) :
605+ SpannerRenderVisitor(lod),
569606 _bounds(bounds) {
570607 }
571608
572609 bool SpannerCursorRenderVisitor::visit(Spanner* spanner) {
573610 if (spanner->isHeightfield()) {
574− spanner->getRenderer()->render(true);
611+ spanner->getRenderer()->render(_lod, _containmentDepth <= _depth, true);
575612 }
576613 return true;
577614 }
578615
579616 int SpannerCursorRenderVisitor::visit(MetavoxelInfo& info) {
580− return info.getBounds().intersects(_bounds) ? SpannerVisitor::visit(info) : STOP_RECURSION;
617+ return info.getBounds().intersects(_bounds) ? SpannerRenderVisitor::visit(info) : STOP_RECURSION;
581618 }
582619
583620 void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float radius) {
@@ -604,7 +641,7 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r · 20 unmodified lines
604641 glActiveTexture(GL_TEXTURE0);
605642
606643 glm::vec3 extents(radius, radius, radius);
607− SpannerCursorRenderVisitor visitor(Box(position - extents, position + extents));
644+ SpannerCursorRenderVisitor visitor(getLOD(), Box(position - extents, position + extents));
608645 guide(visitor);
609646
610647 _heightfieldCursorProgram.release();
@@ -678,7 +715,7 @@ void MetavoxelSystem::renderVoxelCursor(const glm::vec3& position, float radius) · 67 unmodified lines
678715
679716 _heightfieldCursorProgram.bind();
680717
681− SpannerCursorRenderVisitor spannerVisitor(bounds);
718+ SpannerCursorRenderVisitor spannerVisitor(getLOD(), bounds);
682719 guide(spannerVisitor);
683720
684721 _heightfieldCursorProgram.release();
@@ -1880,43 +1917,6 @@ void DefaultMetavoxelRendererImplementation::simulate(MetavoxelData& data, float · 1195 unmodified lines
18801917 data.guide(spannerSimulateVisitor);
18811918 }
18821919
1883−class SpannerRenderVisitor : public SpannerVisitor {
1884−public:
1885−
1886− SpannerRenderVisitor(const MetavoxelLOD& lod);
1887−
1888− virtual int visit(MetavoxelInfo& info);
1889− virtual bool visit(Spanner* spanner);
1890−
1891−private:
1892−
1893− int _containmentDepth;
1894−};
1895−
1896−SpannerRenderVisitor::SpannerRenderVisitor(const MetavoxelLOD& lod) :
1897− SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(),
1898− QVector<AttributePointer>(), QVector<AttributePointer>(), lod,
1899− encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())),
1900− _containmentDepth(INT_MAX) {
1901−}
1902−
1903−int SpannerRenderVisitor::visit(MetavoxelInfo& info) {
1904− if (_containmentDepth >= _depth) {
1905− Frustum::IntersectionType intersection = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType(
1906− info.getBounds());
1907− if (intersection == Frustum::NO_INTERSECTION) {
1908− return STOP_RECURSION;
1909− }
1910− _containmentDepth = (intersection == Frustum::CONTAINS_INTERSECTION) ? _depth : INT_MAX;
1911− }
1912− return SpannerVisitor::visit(info);
1913−}
1914−
1915−bool SpannerRenderVisitor::visit(Spanner* spanner) {
1916− spanner->getRenderer()->render();
1917− return true;
1918−}
1919−
19201920 class BufferRenderVisitor : public MetavoxelVisitor {
19211921 public:
19221922
@@ -1970,7 +1970,7 @@ SphereRenderer::SphereRenderer() { · 47 unmodified lines
19701970 }
19711971
19721972
1973−void SphereRenderer::render(bool cursor) {
1973+void SphereRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
19741974 Sphere* sphere = static_cast<Sphere*>(_spanner);
19751975 const QColor& color = sphere->getColor();
19761976 glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF());
@@ -1990,7 +1990,7 @@ void SphereRenderer::render(bool cursor) { · 13 unmodified lines
19901990 CuboidRenderer::CuboidRenderer() {
19911991 }
19921992
1993−void CuboidRenderer::render(bool cursor) {
1993+void CuboidRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
19941994 Cuboid* cuboid = static_cast<Cuboid*>(_spanner);
19951995 const QColor& color = cuboid->getColor();
19961996 glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF());
@@ -2041,7 +2041,7 @@ void StaticModelRenderer::simulate(float deltaTime) { · 44 unmodified lines
20412041 _model->simulate(deltaTime);
20422042 }
20432043
2044−void StaticModelRenderer::render(bool cursor) {
2044+void StaticModelRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
20452045 _model->render();
20462046 }
20472047
@@ -2083,10 +2083,9 @@ void HeightfieldRenderer::init(Spanner* spanner) { · 35 unmodified lines
20832083 updateRoot();
20842084 }
20852085
2086−void HeightfieldRenderer::render(bool cursor) {
2086+void HeightfieldRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
20872087 Heightfield* heightfield = static_cast<Heightfield*>(_spanner);
2088− _root->render(heightfield->getTranslation(), heightfield->getRotation(), glm::vec3(heightfield->getScale(),
2089− heightfield->getScale() * heightfield->getAspectY(), heightfield->getScale() * heightfield->getAspectZ()), cursor);
2088+ _root->render(heightfield, heightfield->transformLOD(lod), glm::vec2(), 1.0f, contained, cursor);
20902089 }
20912090
20922091 void HeightfieldRenderer::updateRoot() {
@@ -2117,15 +2116,28 @@ HeightfieldRendererNode::~HeightfieldRendererNode() { · 24 unmodified lines
21172116 const int X_MAXIMUM_FLAG = 1;
21182117 const int Y_MAXIMUM_FLAG = 2;
21192118
2120−void HeightfieldRendererNode::render(const glm::vec3& translation, const glm::quat& rotation,
2121− const glm::vec3& scale, bool cursor) {
2122− if (!isLeaf()) {
2123− glm::vec3 nextScale(scale.x * 0.5f, scale.y, scale.z * 0.5f);
2124− glm::vec3 xOffset = rotation * glm::vec3(nextScale.x, 0.0f, 0.0f);
2125− glm::vec3 zOffset = rotation * glm::vec3(0.0f, 0.0f, nextScale.z);
2119+void HeightfieldRendererNode::render(Heightfield* heightfield, const MetavoxelLOD& lod,
2120+ const glm::vec2& minimum, float size, bool contained, bool cursor) {
2121+ const glm::quat& rotation = heightfield->getRotation();
2122+ glm::vec3 scale(heightfield->getScale() * size, heightfield->getScale() * heightfield->getAspectY(),
2123+ heightfield->getScale() * heightfield->getAspectZ() * size);
2124+ glm::vec3 translation = heightfield->getTranslation() + rotation * glm::vec3(minimum.x * heightfield->getScale(),
2125+ 0.0f, minimum.y * heightfield->getScale() * heightfield->getAspectZ());
2126+ if (!contained) {
2127+ Frustum::IntersectionType type = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType(
2128+ glm::translate(translation) * glm::mat4_cast(rotation) * Box(glm::vec3(), scale));
2129+ if (type == Frustum::NO_INTERSECTION) {
2130+ return;
2131+ }
2132+ if (type == Frustum::CONTAINS_INTERSECTION) {
2133+ contained = true;
2134+ }
2135+ }
2136+ if (!isLeaf() && lod.shouldSubdivide(minimum, size)) {
2137+ float nextSize = size * 0.5f;
21262138 for (int i = 0; i < CHILD_COUNT; i++) {
2127− _children[i]->render(translation + (i & X_MAXIMUM_FLAG ? xOffset : glm::vec3()) +
2128− (i & Y_MAXIMUM_FLAG ? zOffset : glm::vec3()), rotation, nextScale, cursor);
2139+ _children[i]->render(heightfield, lod, minimum + glm::vec2(i & X_MAXIMUM_FLAG ? nextSize : 0.0f,
2140+ i & Y_MAXIMUM_FLAG ? nextSize : 0.0f), nextSize, contained, cursor);
21292141 }
21302142 return;
21312143 }