OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Straight lines are broken during rotation


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
adrianj
Newbie


Joined: 19 Jan 2018
Posts: 14

PostPosted: Fri Jan 19, 2018 1:19 am    Post subject:
Straight lines are broken during rotation
Reply with quote

Hi,

I am pretty new to OSG but have been working on it for the past few weeks. I have an application that is rendering a 2D terrain with a constant width. When I rotate my display the line sometime appears broken.

There are no other layers present. I have attached an example. This terrain should be solid and sometimes is depending upon the viewing angle.

Does anyone have any suggestions as to what is happening or what I might be able to do to fix it?

Thank you!

Cheers,
Adrian

Code:
    osg::ref_ptr<osg::Vec3Array> vertexData = new osg::Vec3Array;

    osg::Vec4Array* colors = new osg::Vec4Array;
    colors->push_back(_settingPtr->int2osgColor(3394636));
    _terrain2dGeom->setColorArray(colors, osg::Array::BIND_OVERALL);
    _terrain2dGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
    _terrain2dGeom->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
    _terrain2dGeom->addPrimitiveSet(new osg::DrawArrays(GL_QUAD_STRIP, 0, 2 * TerrainData.size()));

    osg::Vec3d _frontVec, _up, _sideVec , _prevPos;

    for (int i = 0; i < TerrainData.size(); i++)
    {
        VbTerrainData terrainItem = TerrainData.at(i);
        osg::Vec3d longlat = osg::Vec3d(terrainItem.y, terrainItem.x, terrainItem.z);

        _up = lonlat2Metric(osg::Vec3d(longlat.x(), longlat.y(), longlat.z()));

        if (i == 0)
        {
            _prevPos = _up;
            VbTerrainData terrainNextItem = TerrainData.at(1);
            osg::Vec3d nextlonglat = osg::Vec3d(terrainNextItem.y, terrainNextItem.x, terrainNextItem.z);

            _frontVec = lonlat2Metric(osg::Vec3d(nextlonglat.x(), nextlonglat.y(), nextlonglat.z())) - _prevPos;
        }
        else
        {
            _frontVec = _up - _prevPos;
            _prevPos = _up;                       
        }
       
         _sideVec = _up ^ _frontVec;
        _sideVec.normalize();

        vertexData->push_back(_up + _sideVec*width/2);
        vertexData->push_back(_up - _sideVec*width/2);       
    }

    _terrain2dGeom->setVertexArray(vertexData.get());

    _swTerrain->addChild(_terrain2dGeom);
    _swTerrain->setValue(0, true);
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12145

PostPosted: Sat Jan 20, 2018 11:38 am    Post subject:
Straight lines are broken during rotation
Reply with quote

Hi Adrian,

Quote:
From the info given it's not possible to know exactly what is wrong as
there are several possibilities depending upon what the rest of your
application is doing, and the data itself, none of which we have
knowledge of. The best I can do is back some general statements about
handling this type of data.

First up, OpenGL graphics hardware works mostly with floats so that
when working with large vertex values precision can be a big issue,
causing jitter. The way to avoid precision issues when rendering with
the OSG is to create your geometry with a local origin and decorate
this with a Transform node that places this subgraph in it's final
location. The OSG uses doubles to accumulate the Camera View matrix
and all the internal Transform nodes to maintain precision as long as
possible before passing to OpenGL where it'll be cast down to floats.
This technique has been discussed many times in the osg-users mailing
list/forum so have a look through the archives. The osgEarth and
osgTerrain NodeKit's use these technique to handle whole earth
databases with precision problems,

The next possibility is z fighting. You mix discussion of line and
mesh in your post and the picture kinda looks like you might have a
line and mesh together, if you do and the line is
appearing/disappearing if could be due to z fighting. This another
topic discussed many times in the OSG community and out on the web so
have a search.

Robert.

On 19 January 2018 at 01:57, Adrian Jelffs <> wrote:
Quote:
Hi,

I am pretty new to OSG but have been working on it for the past few weeks. I have an application that is rendering a 2D terrain with a constant width. When I rotate my display the line sometime appears broken.

There are no other layers present. I have attached an example. This terrain should be solid and sometimes is depending upon the viewing angle.

Does anyone have any suggestions as to what is happening or what I might be able to do to fix it?

Thank you!

Cheers,
Adrian


Code:
osg::ref_ptr<osg::Vec3Array> vertexData = new osg::Vec3Array;

osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(_settingPtr->int2osgColor(3394636));
_terrain2dGeom->setColorArray(colors, osg::Array::BIND_OVERALL);
_terrain2dGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
_terrain2dGeom->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
_terrain2dGeom->addPrimitiveSet(new osg::DrawArrays(GL_QUAD_STRIP, 0, 2 * TerrainData.size()));

osg::Vec3d _frontVec, _up, _sideVec , _prevPos;

for (int i = 0; i < TerrainData.size(); i++)
{
VbTerrainData terrainItem = TerrainData.at(i);
osg::Vec3d longlat = osg::Vec3d(terrainItem.y, terrainItem.x, terrainItem.z);

_up = lonlat2Metric(osg::Vec3d(longlat.x(), longlat.y(), longlat.z()));

if (i == 0)
{
_prevPos = _up;
VbTerrainData terrainNextItem = TerrainData.at(1);
osg::Vec3d nextlonglat = osg::Vec3d(terrainNextItem.y, terrainNextItem.x, terrainNextItem.z);

_frontVec = lonlat2Metric(osg::Vec3d(nextlonglat.x(), nextlonglat.y(), nextlonglat.z())) - _prevPos;
}
else
{
_frontVec = _up - _prevPos;
_prevPos = _up;
}

_sideVec = _up ^ _frontVec;
_sideVec.normalize();

vertexData->push_back(_up + _sideVec*width/2);
vertexData->push_back(_up - _sideVec*width/2);
}

_terrain2dGeom->setVertexArray(vertexData.get());

_swTerrain->addChild(_terrain2dGeom);
_swTerrain->setValue(0, true);




------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72783#72783




Attachments:
http://forum.openscenegraph.org//files/terrain_172.jpg





------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
adrianj
Newbie


Joined: 19 Jan 2018
Posts: 14

PostPosted: Sat Jan 27, 2018 3:32 am    Post subject:
Reply with quote

Hi Robert,

Many thanks for your reply. I found that when I add the following lines it fixes the 2D terrain problem.

Code:

camera->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES);
   camera->setCullingMode(osg::CullSettings::NO_CULLING);


If I add the following line of code then the problem is much worst:

Code:

camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
 


Would it be possible for you to explain what these are doing or send me a link where I can read about it? I find that the online information is not descriptive enough.

If I add a 3D terrain underneath the 2D terrain then the problem comes back again and the problem looks like the attached image. Even when I add a significant offset to the 2D terrain from the 3D terrain I still get the same results.

I put an offset on the line to check if it was a precision issue and the problem still happens to the line. So I am thinking it must be a Z fighting issue. However, the problem doesn't go away when I zoom in so I thought Z fighting would only be an issue when I zoom out.

When I turn off the 3D and 2D terrains then the single line is fine.

Is there a way to fix this line breaking up issue?

Many thanks for your help!!!

Adrian
Back to top
View user's profile Send private message
adrianj
Newbie


Joined: 19 Jan 2018
Posts: 14

PostPosted: Sat Jan 27, 2018 3:32 am    Post subject:
Line breaking
Reply with quote

Hi Robert,

Many thanks for your reply. I found that when I add the following lines it fixes the 2D terrain problem.

Code:

camera->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES);
   camera->setCullingMode(osg::CullSettings::NO_CULLING);


If I add the following line of code then the problem is much worst:

Code:

camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
 


Would it be possible for you to explain what these are doing or send me a link where I can read about it? I find that the online information is not descriptive enough.

If I add a 3D terrain underneath the 2D terrain then the problem comes back again and the problem looks like the attached image. Even when I add a significant offset to the 2D terrain from the 3D terrain I still get the same results.

I put an offset on the line to check if it was a precision issue and the problem still happens to the line. So I am thinking it must be a Z fighting issue. However, the problem doesn't go away when I zoom in so I thought Z fighting would only be an issue when I zoom out.

When I turn off the 3D and 2D terrains then the single line is fine.

Is there a way to fix this line breaking up issue?

Many thanks for your help!!!

Adrian
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12145

PostPosted: Sat Jan 27, 2018 11:16 am    Post subject:
Straight lines are broken during rotation
Reply with quote

Hi Adrian,

You tests confirm it's a z fighting issue. There will be lots of
discussions about zfighting in the osg-users/forum archives as well as
on general internet, go do a google search.

The ComputeNearFarMode setting the OSG provide control how the OSG
computes the near and far distances used when setting up the
projection matrix. For best precision of the depth buffer you want to
maximum the near/far ratio, this means pulling in the far distances as
much as possible, and pushing out the near distances are much as
possible - the ComputeNearFar modes control the way that OSG attempts
to optimize this ratio, it's not fall proof though.

If you know exactly what near/far distances are appropriate for your
scene you can just disable the CompureNearFar and set the projection
matrix yourself.

Another approach can be to depth partition your scene, or to use a non
linear depth buffer. This are both topics that have been discussed
here on osg-users/forum and on the internet so go search these topics.

Robert.




On 27 January 2018 at 03:32, Adrian Jelffs <> wrote:
Quote:
Hi Robert,

Many thanks for your reply. I found that when I add the following lines it fixes the 2D terrain problem.


Code:

camera->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES);
camera->setCullingMode(osg::CullSettings::NO_CULLING);




If I add the following line of code then the problem is much worst:


Code:

camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);




Would it be possible for you to explain what these are doing or send me a link where I can read about it? I find that the online information is not descriptive enough.

If I add a 3D terrain underneath the 2D terrain then the problem comes back again and the problem looks like the attached image. Even when I add a significant offset to the 2D terrain from the 3D terrain I still get the same results.

I put an offset on the line to check if it was a precision issue and the problem still happens to the line. So I am thinking it must be a Z fighting issue. However, the problem doesn't go away when I zoom in so I thought Z fighting would only be an issue when I zoom out.

When I turn off the 3D and 2D terrains then the single line is fine.

Is there a way to fix this line breaking up issue?

Many thanks for your help!!!

Adrian

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72875#72875








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
adrianj
Newbie


Joined: 19 Jan 2018
Posts: 14

PostPosted: Sat Jan 27, 2018 10:28 pm    Post subject:
Reply with quote

Hi Robert,

Many thanks for your help. The big problem is that whenever you Google an issue as Z Fighting, a trillion results appear about somebodies similar issue in a forum which usually ends up in the answer being "it is probably z fighting, there are many answers on the internet if you Google it" Smile

After several days of Googling I have gathered very little information. There is a distinct lack of examples available on the internet and I am yet to find a single site which can explain to me what each of the settings such as DO_NOT_COMPUTE_NEAR_FAR, COMPUTE_NEAR_FAR_USING_PRIMITIVES etc actually does.

For my own particular problem I found that the following link was the most helpful so far:

https://www.sjbaker.org/steve/omniv/love_your_z_buffer.html

This explained to me some of the issues associated with Z fighting and that I can't make my fustrum as big as I want it to be. I then found, mainly by trial and error, that the setting COMPUTE_NEAR_FAR_USING_PRIMITIVES works the best in my situation. I am yet to find any documentation that tells me how to set the "primitives". Is there actually a location on the internet that has documentation about OSG as opposed to API definitions or forum questions?

Many thanks for your help.

Adrian
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12145

PostPosted: Sun Jan 28, 2018 10:49 am    Post subject:
Straight lines are broken during rotation
Reply with quote

HI Adrian,

Z fighting is a basic topic for real-time computer graphics, we can't
be responsible for teaching you everything about computer graphics

As for primitives well again it's basic topic for real-time computer
graphics, just like OpenGL the OSG uses the primitives, we've adopted
the same language for the same features when wrapping up OpenGL
features in the OSG.

To understand primitives have a look online, or at OSG examples like
osggeometry, in particular where it sets of the PrimitiveSet's for the
geometry. Also have a look at the
OpenSceneGraph/include/osg/PrimitiveSet header class.

Robert.

On 27 January 2018 at 22:28, Adrian Jelffs <> wrote:
Quote:
Hi Robert,

Many thanks for your help. The big problem is that whenever you Google an issue as Z Fighting, a trillion results appear about somebodies similar issue in a forum which usually ends up in the answer being "it is probably z fighting, there are many answers on the internet if you Google it" :)

After several days of Googling I have gathered very little information. There is a distinct lack of examples available on the internet and I am yet to find a single site which can explain to me what each of the settings such as DO_NOT_COMPUTE_NEAR_FAR, COMPUTE_NEAR_FAR_USING_PRIMITIVES etc actually does.

For my own particular problem I found that the following link was the most helpful so far:

https://www.sjbaker.org/steve/omniv/love_your_z_buffer.html

This explained to me some of the issues associated with Z fighting and that I can't make my fustrum as big as I want it to be. I then found, mainly by trial and error, that the setting COMPUTE_NEAR_FAR_USING_PRIMITIVES works the best in my situation. I am yet to find any documentation that tells me how to set the "primitives". Is there actually a location on the internet that has documentation about OSG as opposed to API definitions or forum questions?

Many thanks for your help.

Adrian

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72879#72879








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Textured PointSprites broken when upg... brianh General 2 Wed Sep 05, 2018 4:29 pm View latest post
No new posts Trackball Manipulation Broken? ehensens General 2 Tue May 08, 2018 9:44 pm View latest post
No new posts Broken link arennuit General 2 Mon Aug 14, 2017 10:10 am View latest post
No new posts Related to osg lines Rambabu General 5 Tue Apr 18, 2017 9:22 am View latest post
No new posts Fix FBX rotation matrix computation Farshid Lashkari Submission 1 Tue Apr 11, 2017 11:21 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP