1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-03 21:09:41 +00:00

Debug terrain chunks

This commit is contained in:
Cédric Mocquillon 2021-07-29 15:33:58 +02:00
parent e2d0e86020
commit 98a0819d52
7 changed files with 47 additions and 8 deletions

View file

@ -9,6 +9,7 @@
#include "../esm/loadland.hpp" #include "../esm/loadland.hpp"
#include <components/resource/scenemanager.hpp> #include <components/resource/scenemanager.hpp>
#include <components/terrain/storage.hpp>
namespace Terrain namespace Terrain
{ {
@ -21,13 +22,14 @@ CellBorder::CellBorder(Terrain::World *world, osg::Group *root, int borderMask,
{ {
} }
void CellBorder::createCellBorderGeometry(int x, int y) osg::ref_ptr<osg::Geode> CellBorder::createBorderGeometry(float x, float y, float size, Terrain::Storage* terrain, Resource::SceneManager* sceneManager, int mask)
{ {
const int cellSize = ESM::Land::REAL_SIZE; const int cellSize = ESM::Land::REAL_SIZE;
const int borderSegments = 40; const int borderSegments = 40;
const float offset = 10.0; const float offset = 10.0;
osg::Vec3 cellCorner = osg::Vec3(x * cellSize,y * cellSize,0); osg::Vec3 cellCorner = osg::Vec3(x * cellSize,y * cellSize,0);
size *= cellSize;
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array; osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
@ -35,16 +37,16 @@ void CellBorder::createCellBorderGeometry(int x, int y)
normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f)); normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));
float borderStep = cellSize / ((float) borderSegments); float borderStep = size / ((float)borderSegments);
for (int i = 0; i <= 2 * borderSegments; ++i) for (int i = 0; i <= 2 * borderSegments; ++i)
{ {
osg::Vec3f pos = i < borderSegments ? osg::Vec3f pos = i < borderSegments ?
osg::Vec3(i * borderStep,0.0f,0.0f) : osg::Vec3(i * borderStep,0.0f,0.0f) :
osg::Vec3(cellSize,(i - borderSegments) * borderStep,0.0f); osg::Vec3(size, (i - borderSegments) * borderStep,0.0f);
pos += cellCorner; pos += cellCorner;
pos += osg::Vec3f(0,0,mWorld->getHeightAt(pos) + offset); pos += osg::Vec3f(0,0, terrain->getHeightAt(pos) + offset);
vertices->push_back(pos); vertices->push_back(pos);
@ -76,10 +78,15 @@ void CellBorder::createCellBorderGeometry(int x, int y)
polygonmode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE); polygonmode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
stateSet->setAttributeAndModes(polygonmode,osg::StateAttribute::ON); stateSet->setAttributeAndModes(polygonmode,osg::StateAttribute::ON);
mSceneManager->recreateShaders(borderGeode, "debug"); sceneManager->recreateShaders(borderGeode, "debug");
borderGeode->setNodeMask(mask);
borderGeode->setNodeMask(mBorderMask); return borderGeode;
}
void CellBorder::createCellBorderGeometry(int x, int y)
{
auto borderGeode = createBorderGeometry(x, y, 1.f, mWorld->getStorage(), mSceneManager, mBorderMask);
mRoot->addChild(borderGeode); mRoot->addChild(borderGeode);
mCellBorderNodes[std::make_pair(x,y)] = borderGeode; mCellBorderNodes[std::make_pair(x,y)] = borderGeode;

View file

@ -11,6 +11,7 @@ namespace Resource
namespace Terrain namespace Terrain
{ {
class Storage;
class World; class World;
/** /**
@ -31,6 +32,8 @@ namespace Terrain
*/ */
void destroyCellBorderGeometry(); void destroyCellBorderGeometry();
static osg::ref_ptr<osg::Geode> createBorderGeometry(float x, float y, float size, Storage* terrain, Resource::SceneManager* sceneManager, int mask);
protected: protected:
Terrain::World *mWorld; Terrain::World *mWorld;
Resource::SceneManager* mSceneManager; Resource::SceneManager* mSceneManager;

View file

@ -5,6 +5,7 @@
#include <osg/Texture2D> #include <osg/Texture2D>
#include <osg/ClusterCullingCallback> #include <osg/ClusterCullingCallback>
#include <osg/Material> #include <osg/Material>
#include <osg/MatrixTransform>
#include <osgUtil/IncrementalCompileOperation> #include <osgUtil/IncrementalCompileOperation>
@ -12,12 +13,14 @@
#include <components/resource/scenemanager.hpp> #include <components/resource/scenemanager.hpp>
#include <components/sceneutil/lightmanager.hpp> #include <components/sceneutil/lightmanager.hpp>
#include <components/settings/settings.hpp>
#include "terraindrawable.hpp" #include "terraindrawable.hpp"
#include "material.hpp" #include "material.hpp"
#include "storage.hpp" #include "storage.hpp"
#include "texturemanager.hpp" #include "texturemanager.hpp"
#include "compositemaprenderer.hpp" #include "compositemaprenderer.hpp"
#include <components/misc/constants.hpp>
namespace Terrain namespace Terrain
{ {
@ -32,6 +35,7 @@ ChunkManager::ChunkManager(Storage *storage, Resource::SceneManager *sceneMgr, T
, mCompositeMapSize(512) , mCompositeMapSize(512)
, mCompositeMapLevel(1.f) , mCompositeMapLevel(1.f)
, mMaxCompGeometrySize(1.f) , mMaxCompGeometrySize(1.f)
, mDebugChunks(Settings::Manager::getBool("debug chunks", "Terrain"))
{ {
mMultiPassRoot = new osg::StateSet; mMultiPassRoot = new osg::StateSet;
mMultiPassRoot->setRenderingHint(osg::StateSet::OPAQUE_BIN); mMultiPassRoot->setRenderingHint(osg::StateSet::OPAQUE_BIN);
@ -234,7 +238,19 @@ osg::ref_ptr<osg::Node> ChunkManager::createChunk(float chunkSize, const osg::Ve
} }
geometry->setNodeMask(mNodeMask); geometry->setNodeMask(mNodeMask);
return geometry; osg::ref_ptr<osg::Group> result(new osg::Group);
result->addChild(geometry);
if (mDebugChunks)
{
auto chunkBorder = CellBorder::createBorderGeometry(chunkCenter.x() - chunkSize / 2.f, chunkCenter.y() - chunkSize / 2.f, chunkSize, mStorage, mSceneManager, getNodeMask());
osg::Vec3f center = { chunkCenter.x(), chunkCenter.y(), 0 };
osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform(osg::Matrixf::translate(-center*Constants::CellSizeInUnits));
trans->setDataVariance(osg::Object::STATIC);
trans->addChild(chunkBorder);
result->addChild(trans);
}
return result;
} }
} }

View file

@ -72,6 +72,7 @@ namespace Terrain
unsigned int mCompositeMapSize; unsigned int mCompositeMapSize;
float mCompositeMapLevel; float mCompositeMapLevel;
float mMaxCompGeometrySize; float mMaxCompGeometrySize;
bool mDebugChunks = false;
}; };
} }

View file

@ -367,7 +367,7 @@ void updateWaterCullingView(HeightCullCallback* callback, ViewData* vd, osgUtil:
for (unsigned int i=0; i<vd->getNumEntries(); ++i) for (unsigned int i=0; i<vd->getNumEntries(); ++i)
{ {
ViewData::Entry& entry = vd->getEntry(i); ViewData::Entry& entry = vd->getEntry(i);
osg::BoundingBox bb = static_cast<TerrainDrawable*>(entry.mRenderingNode->asGroup()->getChild(0))->getWaterBoundingBox(); osg::BoundingBox bb = static_cast<TerrainDrawable*>(entry.mRenderingNode->asGroup()->getChild(0)->asGroup()->getChild(0))->getWaterBoundingBox();
if (!bb.valid()) if (!bb.valid())
continue; continue;
osg::Vec3f ofs (entry.mNode->getCenter().x()*cellworldsize, entry.mNode->getCenter().y()*cellworldsize, 0.f); osg::Vec3f ofs (entry.mNode->getCenter().x()*cellworldsize, entry.mNode->getCenter().y()*cellworldsize, 0.f);

View file

@ -100,6 +100,15 @@ max composite geometry size
Controls the maximum size of simple composite geometry chunk in cell units. With small values there will more draw calls and small textures, Controls the maximum size of simple composite geometry chunk in cell units. With small values there will more draw calls and small textures,
but higher values create more overdraw (not every texture layer is used everywhere). but higher values create more overdraw (not every texture layer is used everywhere).
debug chunks
------------
:Type: boolean
:Range: True/False
:Default: False
This debug setting allows you to see the borders of each chunks of the world by drawing lines arround them (as with toggleborder).
object paging object paging
------------- -------------

View file

@ -139,6 +139,9 @@ composite map resolution = 512
# Controls the maximum size of composite geometry, should be >= 1.0. With low values there will be many small chunks, with high values - lesser count of bigger chunks. # Controls the maximum size of composite geometry, should be >= 1.0. With low values there will be many small chunks, with high values - lesser count of bigger chunks.
max composite geometry size = 4.0 max composite geometry size = 4.0
# Draw lines arround chunks.
debug chunks = false
# Use object paging for non active cells # Use object paging for non active cells
object paging = true object paging = true