Board index FlightGear Development Canvas

Synthetic terrain

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Synthetic terrain

Postby Hooray » Thu Nov 12, 2015 12:38 pm

Jabiru J-170 (DEVELOPMENT)
omega95 wrote: can you give me an idea on how to use od_gauge to continuously render a camera view to texture? I don't really know much about it but then every says that Project Rembrandt involves continuous rendering to texture.

And, is there a way to get terrain as a view? I mean, sorta like changing the color based on terrain. Oh, and I'd also need to place my own texture on the terrain, instead of the materials textures..

So, that's not just using od_gauge, for a terrain view, I'd need to actually re-render the whole terrain with some extra stuff...

Here's a picture of the real thing..

Image

So, I was thinking we have the basic terrain and have a checker box texture over it.

Image

And then diffuse it according to this gradient based on altitude.

Image

Any ideas? 8)


I've been adding a bunch of related code snippets to the "Canvas Sandbox" article on the wiki http://wiki.flightgear.org/Canvas_Sandbox

Such a 3D view would be best accomplished by using a scenery child cam, and applying custom effects/shaders to it - but for that, we would need to expose effects/shaders to Canvas::Element.

Alternatively, it would also be possible to come up with a custom "heightfield" element using osg.:HeightField: http://trac.openscenegraph.org/document ... 00364.html



http://osghelp.com/?p=163
http://snipplr.com/view/30974/osg-height-field-example/
http://www.emoticode.net/c-plus-plus/os ... ample.html

It would be relatively straightforward to turn this into a custom Canvas::Element and even hook it up to the built-in terrain presampler, using a configurable resolution.

Anybody familiar with building from source, using git and willing to work through a handful of OSG tutorials should be able to come up with a working "heightfield" element to support such synthetic terrain views.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Synthetic terrain

Postby psadro_gm » Thu Nov 12, 2015 12:44 pm

Instead of using the terrain sampler, it may be faster to create the mesh directly from the scenegraph in c++ space. we already do this in the LOD callback to place the random trees and buildings. We then have a triangle mesh.

edit: didn't read the whole post :) - using an extra camera on the already generated graph is a much more elegant solution.
8.50 airport parser, textured roads and streams...
psadro_gm
 
Posts: 751
Joined: Thu Aug 25, 2011 2:23 am
Location: Atlanta, GA USA
IRC name: psadro_*
Version: git
OS: Fedora 21

Re: Synthetic terrain

Postby Hooray » Thu Nov 12, 2015 12:48 pm

thanks for the pointer, could you possibly also post a link to the corresponding C++ code in SG/FG ?
I am asking to take a look, without having to spend 10 minutes finding the right file/function.

But I guess that you are right, it would be redundant to re-sample the terrain over again, and it should be more efficient to reuse the mesh and "reduce" a subset of it accordingly

As can be seen on the wiki, I am currently prototyping a few experimental elements, specifically in response to the discussions/feature requests we have seen over the years - so depending on spare time (and interest), I may also pursue this sooner or later, even if just to post a proof-of-concept that others can adopt/extend over time.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Synthetic terrain

Postby psadro_gm » Mon Nov 16, 2015 1:48 pm

sure:

https://sourceforge.net/p/flightgear/si ... angles.hxx

the OSG visitor you want is here:

class GetNodeTriangles : public osg::NodeVisitor

The tricky thing will be to find the relevant _rootNode(s). For the detailed callback, it's saved when the tile is first generated. When the visitor is applied, it's only applied to this node, so it traverses all the children for just this tile.

You probably don't want to sample ALL of the scenegraph for the geometry...

Pete
8.50 airport parser, textured roads and streams...
psadro_gm
 
Posts: 751
Joined: Thu Aug 25, 2011 2:23 am
Location: Atlanta, GA USA
IRC name: psadro_*
Version: git
OS: Fedora 21

Re: Synthetic terrain

Postby Hooray » Mon Nov 16, 2015 1:59 pm

http://sourceforge.net/p/flightgear/sim ... angles.hxx
Code: Select all
// This visitor will generate an SGTriangleInfo.
// currently, it looks like it could save multiple lists, which could be the case
// if multiple osg::geods are found with osg::Geometry.
// But right now, we store a single PrimitiveSet under a single EffectGeod. 
// so the traversal should only find a single EffectGeod - building a single SGTriangleInfo
class GetNodeTriangles : public osg::NodeVisitor
{
public:
    GetNodeTriangles(const SGVec3d& c, std::vector<SGTriangleInfo>* nt) : osg::NodeVisitor( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ), center(c), nodeTris(nt) {}
   
    // This method gets called for every node in the scene
    //   graph. Check each node to see if it has user
    //   out target. If so, save the node's address.
    virtual void apply( osg::Node& node )
    {
        EffectGeode* eg = dynamic_cast<EffectGeode*>(&node);
        if ( eg ) {
            // get the material from the user info
            SGTriangleInfo triInfo( center );
            triInfo.setMaterial( eg->getMaterial() );

            // let's find the drawables for this node
            int numDrawables = eg->getNumDrawables();
            for ( int i=0; i<numDrawables; i++ ) {
                triInfo.addGeometry( eg->getDrawable(i)->asGeometry() );
            }
           
            nodeTris->push_back( triInfo );
        }
       
        // Keep traversing the rest of the scene graph.
        traverse( node );
    }
   
protected:
    SGVec3d                         center;
    std::vector<SGTriangleInfo>*    nodeTris;
};



thank you, looking at the code, it really seems not only more efficient, but also much easier, to take an existing Camera texture and render a view of the same scene onto it, we really only need a way to use effects/shaders at the CanvasElement level to simplify the terrain mesh and apply custom texturing to come up with a synthetic terrain view. The added benefit being that OSG does support a thread-per-camera rendering mode where separate camera views can be updated/culled asynchronously before they get drawn.

https://www.packtpub.com/books/content/ ... scenegraph
Image
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11376
Joined: Tue Mar 25, 2008 8:40 am


Return to Canvas

Who is online

Users browsing this forum: No registered users and 1 guest