1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-11 15:40:39 +00:00

Merge branch 'DistantTerrainDebugChunks' into 'master'

Debug terrain chunks

See merge request OpenMW/openmw!1169
This commit is contained in:
psi29a 2021-09-18 15:21:26 +00:00
commit 68db9869f5
9 changed files with 61 additions and 21 deletions

View File

@ -390,7 +390,7 @@ namespace MWRender
, mRefTrackerLocked(false)
{
mActiveGrid = Settings::Manager::getBool("object paging active grid", "Terrain");
mDebugBatches = Settings::Manager::getBool("object paging debug batches", "Terrain");
mDebugBatches = Settings::Manager::getBool("debug chunks", "Terrain");
mMergeFactor = Settings::Manager::getFloat("object paging merge factor", "Terrain");
mMinSize = Settings::Manager::getFloat("object paging min size", "Terrain");
mMinSizeMergeFactor = Settings::Manager::getFloat("object paging min size merge factor", "Terrain");

View File

@ -9,6 +9,7 @@
#include "../esm/loadland.hpp"
#include <components/resource/scenemanager.hpp>
#include <components/terrain/storage.hpp>
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,
float offset, osg::Vec4f color)
{
const int cellSize = ESM::Land::REAL_SIZE;
const int borderSegments = 40;
const float offset = 10.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::Vec4Array> colors = new osg::Vec4Array;
@ -35,22 +37,22 @@ void CellBorder::createCellBorderGeometry(int x, int y)
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)
{
osg::Vec3f pos = i < borderSegments ?
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 += osg::Vec3f(0,0,mWorld->getHeightAt(pos) + offset);
pos += osg::Vec3f(0,0, terrain->getHeightAt(pos) + offset);
vertices->push_back(pos);
osg::Vec4f col = i % 2 == 0 ?
osg::Vec4f(0,0,0,1) :
osg::Vec4f(1,1,0,1);
color;
colors->push_back(col);
}
@ -76,10 +78,15 @@ void CellBorder::createCellBorderGeometry(int x, int y)
polygonmode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
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);
mCellBorderNodes[std::make_pair(x,y)] = borderGeode;

View File

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

View File

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

View File

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

View File

@ -252,6 +252,7 @@ QuadTreeWorld::QuadTreeWorld(osg::Group *parent, osg::Group *compileRoot, Resour
, mVertexLodMod(vertexLodMod)
, mViewDistance(std::numeric_limits<float>::max())
, mMinSize(1/8.f)
, mDebugTerrainChunks(Settings::Manager::getBool("debug chunks", "Terrain"))
{
mChunkManager->setCompositeMapSize(compMapResolution);
mChunkManager->setCompositeMapLevel(compMapLevel);
@ -351,7 +352,7 @@ void loadRenderingNode(ViewData::Entry& entry, ViewData* vd, int vertexLodMod, f
}
}
void updateWaterCullingView(HeightCullCallback* callback, ViewData* vd, osgUtil::CullVisitor* cv, float cellworldsize, bool outofworld)
void updateWaterCullingView(HeightCullCallback* callback, ViewData* vd, osgUtil::CullVisitor* cv, float cellworldsize, bool outofworld, bool debugTerrainChunk)
{
if (!(cv->getTraversalMask() & callback->getCullMask()))
return;
@ -367,7 +368,11 @@ void updateWaterCullingView(HeightCullCallback* callback, ViewData* vd, osgUtil:
for (unsigned int i=0; i<vd->getNumEntries(); ++i)
{
ViewData::Entry& entry = vd->getEntry(i);
osg::BoundingBox bb = static_cast<TerrainDrawable*>(entry.mRenderingNode->asGroup()->getChild(0))->getWaterBoundingBox();
osg::BoundingBox bb;
if(debugTerrainChunk)
bb = static_cast<TerrainDrawable*>(entry.mRenderingNode->asGroup()->getChild(0)->asGroup()->getChild(0))->getWaterBoundingBox();
else
bb = static_cast<TerrainDrawable*>(entry.mRenderingNode->asGroup()->getChild(0))->getWaterBoundingBox();
if (!bb.valid())
continue;
osg::Vec3f ofs (entry.mNode->getCenter().x()*cellworldsize, entry.mNode->getCenter().y()*cellworldsize, 0.f);
@ -443,7 +448,7 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv)
}
if (mHeightCullCallback && isCullVisitor)
updateWaterCullingView(mHeightCullCallback, vd, static_cast<osgUtil::CullVisitor*>(&nv), mStorage->getCellWorldSize(), !isGridEmpty());
updateWaterCullingView(mHeightCullCallback, vd, static_cast<osgUtil::CullVisitor*>(&nv), mStorage->getCellWorldSize(), !isGridEmpty(), mDebugTerrainChunks);
vd->markUnchanged();

View File

@ -72,6 +72,7 @@ namespace Terrain
int mVertexLodMod;
float mViewDistance;
float mMinSize;
bool mDebugTerrainChunks;
};
}

View File

@ -100,6 +100,18 @@ 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,
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).
If object paging is set to true then this debug setting will allows you to see what objects have been merged in the scene
by making them colored randomly.
object paging
-------------
@ -194,12 +206,3 @@ object paging min size cost multiplier
This setting adjusts the calculated cost of merging an object used in the mentioned functionality.
The larger this value is, the less expensive objects can be before they are discarded.
See the formula above to figure out the math.
object paging debug batches
---------------------------
:Type: boolean
:Range: True/False
:Default: False
This debug setting allows you to see what objects have been merged in the scene
by making them colored randomly.

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.
max composite geometry size = 4.0
# Draw lines arround chunks.
debug chunks = false
# Use object paging for non active cells
object paging = true