简体   繁体   中英

How to draw a terrain model efficiently from Esri Grid (osg)?

I have many Esri Grid files ( https://en.wikipedia.org/wiki/Esri_grid#ASCII ) and I would like to render them in 3D without losing precision, I am using OpenSceneGraph.

The problem is this grids are around 1000x1000 (or more) points, so when I extract the vertices, then compute the triangles to create the geometry, I end up having millions of them and the interaction with the scene is impossible (frame rate drops to 0).

I've tried several approches:

  1. Triangle list

    Basically, as I read the file, I fill an array with 3 vertices per triangle (this leads to duplication);

osg::ref_ptr<osg::Geode> l_pGeodeSurface = new osg::Geode;
osg::ref_ptr<osg::Geometry> l_pGeometrySurface = new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> l_pvTrianglePoints = osg::Vec3Array;
osg::ref_ptr<osg::Vec3Array> l_pvOriginalPoints = osg::Vec3Array;

... // Read the file and fill l_pvOriginalPoints 

for(*triangle inside the file*)
{
   ... // Compute correct triangle indices (l_iP1, l_iP2, l_iP3)

    // Push triangle vertices inside the array
    l_pvTrianglePoints->push_back(l_pvOriginalPoints->at(l_iP1));
    l_pvTrianglePoints->push_back(l_pvOriginalPoints->at(l_iP2));
    l_pvTrianglePoints->push_back(l_pvOriginalPoints->at(l_iP3));
}

l_pGeometrySurface->setVertexArray(l_pvTrianglePoints);
l_pGeometrySurface->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLES, 0, 3, l_pvTrianglePoints->size()));
  1. Indexed triangle list

    Same as before, but the array contains the every vertices just once and I create a second array of indices (basically i tell osg how to build triangles, no duplication)

osg::ref_ptr<osg::Geode> l_pGeodeSurface = new osg::Geode;
osg::ref_ptr<osg::Geometry> l_pGeometrySurface = new osg::Geometry;
osg::ref_ptr<osg::DrawElementsUInt> l_pIndices = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, *number of indices*);
osg::ref_ptr<osg::Vec3Array> l_pvOriginalPoints = osg::Vec3Array;

... // Read the file and fill l_pvOriginalPoints 

for(i = 0; i < *number of indices*; i++)
{
   ... // Compute correct triangle indices (l_iP1, l_iP2, l_iP3)

    // Push vertices indices inside the array
    l_pIndices->at(i) = l_iP1;
    l_pIndices->at(i+1) = l_iP2;
    l_pIndices->at(i+2) = l_iP3;
}

l_pGeometrySurface->setVertexArray(l_pvOriginalPoints );
l_pGeometrySurface->addPrimitiveSet(l_pIndices.get());

三角形列表与三角形索引

  1. Instancing

    this was a bit of an experiment, since I've never used shaders, I tought I could instance a single triangle, then manipulate its coordinates in a vertex shader for every triangle in my scene, using transformation matrices (passing the matrices as a uniform array, one for triangle). I ended up with too many uniforms just with a grid 20x20.

    I used these links as a reference:

    https://learnopengl.com/Advanced-OpenGL/Instancing ,

    https://books.google.it/books?id=x_RkEBIJeFQC&pg=PT265&lpg=PT265&dq=osg+instanced+geometry&source=bl&ots=M8ii8zn8w7&sig=ACfU3U0_92Z5EGCyOgbfGweny4KIUfqU8w&hl=en&sa=X&ved=2ahUKEwj-7JD0nq7qAhUXxMQBHcLaAiUQ6AEwAnoECAkQAQ#v=onepage&q=osg%20instanced%20geometry&f=false

None of the above solved my issue, what else can I try? Am I missing something in terms of rendering techinques? I thought it was fairly simple task, but I'm kind of stuck.

I feel like you should consider taking a step back. If you're visualizing GIS-based terrain data, osgEarth is really designed for doing this and has fairly efficient LOD tools for large terrains. Do you need the data always represented at maximum full LOD or are you looking for dynamic LOD to improve frame rate?

Depending on your goals and requirements you might want to look at some more advanced terrain rendering techniques, like rightfield tracing, etc. If the terrain is always static, you can precompute quadtrees and Signed Distance Functions and trace against the heightfield.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM