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
550 applyMaterialEdit(edit, true);550 applyMaterialEdit(edit, true);
551}551}
552 552
553class SpannerCursorRenderVisitor : public SpannerVisitor {553class SpannerRenderVisitor : public SpannerVisitor {
554public:
555
556 SpannerRenderVisitor(const MetavoxelLOD& lod);
557
558 virtual int visit(MetavoxelInfo& info);
559 virtual bool visit(Spanner* spanner);
560
561protected:
562
563 int _containmentDepth;
564};
565
566SpannerRenderVisitor::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
573int 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
585bool SpannerRenderVisitor::visit(Spanner* spanner) {
586 spanner->getRenderer()->render(_lod, _containmentDepth <= _depth);
587 return true;
588}
589
590class SpannerCursorRenderVisitor : public SpannerRenderVisitor {
554public:591public:
555 592
556 SpannerCursorRenderVisitor(const Box& bounds);593 SpannerCursorRenderVisitor(const MetavoxelLOD& lod, const Box& bounds);
557 594
558 virtual bool visit(Spanner* spanner);595 virtual bool visit(Spanner* spanner);
559 596
@@ -564,20 +601,20 @@ private: · 4 unmodified lines
564 Box _bounds;601 Box _bounds;
565};602};
566 603
567SpannerCursorRenderVisitor::SpannerCursorRenderVisitor(const Box& bounds) :604SpannerCursorRenderVisitor::SpannerCursorRenderVisitor(const MetavoxelLOD& lod, const Box& bounds) :
568 SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute()),605 SpannerRenderVisitor(lod),
569 _bounds(bounds) {606 _bounds(bounds) {
570}607}
571 608
572bool SpannerCursorRenderVisitor::visit(Spanner* spanner) {609bool SpannerCursorRenderVisitor::visit(Spanner* spanner) {
573 if (spanner->isHeightfield()) {610 if (spanner->isHeightfield()) {
574 spanner->getRenderer()->render(true);611 spanner->getRenderer()->render(_lod, _containmentDepth <= _depth, true);
575 }612 }
576 return true;613 return true;
577}614}
578 615
579int SpannerCursorRenderVisitor::visit(MetavoxelInfo& info) {616int 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;
581}618}
582 619
583void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float radius) {620void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float radius) {
@@ -604,7 +641,7 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r · 20 unmodified lines
604 glActiveTexture(GL_TEXTURE0);641 glActiveTexture(GL_TEXTURE0);
605 642
606 glm::vec3 extents(radius, radius, radius);643 glm::vec3 extents(radius, radius, radius);
607 SpannerCursorRenderVisitor visitor(Box(position - extents, position + extents));644 SpannerCursorRenderVisitor visitor(getLOD(), Box(position - extents, position + extents));
608 guide(visitor);645 guide(visitor);
609 646
610 _heightfieldCursorProgram.release();647 _heightfieldCursorProgram.release();
@@ -678,7 +715,7 @@ void MetavoxelSystem::renderVoxelCursor(const glm::vec3& position, float radius) · 67 unmodified lines
678 715
679 _heightfieldCursorProgram.bind();716 _heightfieldCursorProgram.bind();
680 717
681 SpannerCursorRenderVisitor spannerVisitor(bounds);718 SpannerCursorRenderVisitor spannerVisitor(getLOD(), bounds);
682 guide(spannerVisitor);719 guide(spannerVisitor);
683 720
684 _heightfieldCursorProgram.release();721 _heightfieldCursorProgram.release();
@@ -1880,43 +1917,6 @@ void DefaultMetavoxelRendererImplementation::simulate(MetavoxelData& data, float · 1195 unmodified lines
1880 data.guide(spannerSimulateVisitor);1917 data.guide(spannerSimulateVisitor);
1881}1918}
1882 1919
1883class SpannerRenderVisitor : public SpannerVisitor {
1884public:
1885
1886 SpannerRenderVisitor(const MetavoxelLOD& lod);
1887
1888 virtual int visit(MetavoxelInfo& info);
1889 virtual bool visit(Spanner* spanner);
1890
1891private:
1892
1893 int _containmentDepth;
1894};
1895
1896SpannerRenderVisitor::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
1903int 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
1915bool SpannerRenderVisitor::visit(Spanner* spanner) {
1916 spanner->getRenderer()->render();
1917 return true;
1918}
1919
1920class BufferRenderVisitor : public MetavoxelVisitor {1920class BufferRenderVisitor : public MetavoxelVisitor {
1921public:1921public:
1922 1922
@@ -1970,7 +1970,7 @@ SphereRenderer::SphereRenderer() { · 47 unmodified lines
1970}1970}
1971 1971
1972 1972
1973void SphereRenderer::render(bool cursor) {1973void SphereRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
1974 Sphere* sphere = static_cast<Sphere*>(_spanner);1974 Sphere* sphere = static_cast<Sphere*>(_spanner);
1975 const QColor& color = sphere->getColor();1975 const QColor& color = sphere->getColor();
1976 glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF());1976 glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF());
@@ -1990,7 +1990,7 @@ void SphereRenderer::render(bool cursor) { · 13 unmodified lines
1990CuboidRenderer::CuboidRenderer() {1990CuboidRenderer::CuboidRenderer() {
1991}1991}
1992 1992
1993void CuboidRenderer::render(bool cursor) {1993void CuboidRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
1994 Cuboid* cuboid = static_cast<Cuboid*>(_spanner);1994 Cuboid* cuboid = static_cast<Cuboid*>(_spanner);
1995 const QColor& color = cuboid->getColor();1995 const QColor& color = cuboid->getColor();
1996 glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF());1996 glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF());
@@ -2041,7 +2041,7 @@ void StaticModelRenderer::simulate(float deltaTime) { · 44 unmodified lines
2041 _model->simulate(deltaTime);2041 _model->simulate(deltaTime);
2042}2042}
2043 2043
2044void StaticModelRenderer::render(bool cursor) {2044void StaticModelRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
2045 _model->render();2045 _model->render();
2046}2046}
2047 2047
@@ -2083,10 +2083,9 @@ void HeightfieldRenderer::init(Spanner* spanner) { · 35 unmodified lines
2083 updateRoot();2083 updateRoot();
2084}2084}
2085 2085
2086void HeightfieldRenderer::render(bool cursor) {2086void HeightfieldRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
2087 Heightfield* heightfield = static_cast<Heightfield*>(_spanner);2087 Heightfield* heightfield = static_cast<Heightfield*>(_spanner);
2088 _root->render(heightfield->getTranslation(), heightfield->getRotation(), glm::vec3(heightfield->getScale(),2088 _root->render(heightfield, heightfield->transformLOD(lod), glm::vec2(), 1.0f, contained, cursor);
2089 heightfield->getScale() * heightfield->getAspectY(), heightfield->getScale() * heightfield->getAspectZ()), cursor);
2090}2089}
2091 2090
2092void HeightfieldRenderer::updateRoot() {2091void HeightfieldRenderer::updateRoot() {
@@ -2117,15 +2116,28 @@ HeightfieldRendererNode::~HeightfieldRendererNode() { · 24 unmodified lines
2117const int X_MAXIMUM_FLAG = 1;2116const int X_MAXIMUM_FLAG = 1;
2118const int Y_MAXIMUM_FLAG = 2;2117const int Y_MAXIMUM_FLAG = 2;
2119 2118
2120void HeightfieldRendererNode::render(const glm::vec3& translation, const glm::quat& rotation,2119void HeightfieldRendererNode::render(Heightfield* heightfield, const MetavoxelLOD& lod,
2121 const glm::vec3& scale, bool cursor) {2120 const glm::vec2& minimum, float size, bool contained, bool cursor) {
2122 if (!isLeaf()) {2121 const glm::quat& rotation = heightfield->getRotation();
2123 glm::vec3 nextScale(scale.x * 0.5f, scale.y, scale.z * 0.5f);2122 glm::vec3 scale(heightfield->getScale() * size, heightfield->getScale() * heightfield->getAspectY(),
2124 glm::vec3 xOffset = rotation * glm::vec3(nextScale.x, 0.0f, 0.0f);2123 heightfield->getScale() * heightfield->getAspectZ() * size);
2125 glm::vec3 zOffset = rotation * glm::vec3(0.0f, 0.0f, nextScale.z);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;
2126 for (int i = 0; i < CHILD_COUNT; i++) {2138 for (int i = 0; i < CHILD_COUNT; i++) {
2127 _children[i]->render(translation + (i & X_MAXIMUM_FLAG ? xOffset : glm::vec3()) +2139 _children[i]->render(heightfield, lod, minimum + glm::vec2(i & X_MAXIMUM_FLAG ? nextSize : 0.0f,
2128 (i & Y_MAXIMUM_FLAG ? zOffset : glm::vec3()), rotation, nextScale, cursor);2140 i & Y_MAXIMUM_FLAG ? nextSize : 0.0f), nextSize, contained, cursor);
2129 }2141 }
2130 return;2142 return;
2131 }2143 }