Re: [osg-users] Drawing poly line, jitter/vibration issue when moving camera
Hi Preet, Rui was a little cryptic is his explanation so I'll expand on it further. What you are seeing is numerical precisions issues down on the graphics card as internally the graphics card uses floats for vertices and floats for the modelview matrix. The solution to this problem is make sure all geometry data has a local origin and use a transform node (such as an osg::MatrixTransform) that decorates your geometry and places it in world coordinates. The OSG by default uses double's for the Camera's View matrix and double's for the transform nodes and when accumulating all the matrices during the cull traversal uses doubles as well so that by the time the OSG maintains precision all the way till it passes the modelview matrix to OpenGL. Typically when you are close to your geometry the translation component of Camera's View matrix will cancel out with the translation component of your scene graph transform node, so that you end up with a final modelview passed to OpenGL with modest translation component that doesn't present any numerical precision issues, solving the precision. This approach is commonly used when tackling whole earth geospatial data, and you'll see it in action in the paged databases that VirtualPlanetBuilder creates, 3rd party NodeKit's like osgEarth use this approach as well. Robert. On 14 February 2012 02:26, Preet prismatic.proj...@gmail.com wrote: Hiya, I'm trying to draw a simple poly line from a vertex array with the GL_LINE_STRIP primitive. When I view the object using osgviewer, it looks like everything is alright. Once I move the camera around with the mouse however, the lines begin to jitter, like the polyline was made of jello (honestly can't find better description). The effect is especially visible at higher zooms. I'm using large (values in the hundred-millions), high precision numbers (doubles) for the vertices of the line strip, and I think that's what's causing the problem (I couldn't recreate the issue using smaller, more sane numbers from 1-500 for example, even though the same double datatype is used to store both numbers). I've posted my code here: http://pastie.org/3377862 The code only relies on STL and osg, so it should 'just compile' if you have an osg environment setup. The relevant calls to osg are on lines 121-141. I'm using OSG 3.0.1 on Arch Linux, kernel 3.2.x if it's relevant. Does anyone have any ideas as to what's going on? Regards, Pris ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Drawing poly line, jitter/vibration issue when moving camera
Hey Robert, Thanks for the detailed response. I had a few follow up questions. On Tue, Feb 14, 2012 at 7:39 AM, Robert Osfield robert.osfi...@gmail.com wrote: Hi Preet, Rui was a little cryptic is his explanation so I'll expand on it further. What you are seeing is numerical precisions issues down on the graphics card as internally the graphics card uses floats for vertices and floats for the modelview matrix. The solution to this problem is make sure all geometry data has a local origin and use a transform node (such as an osg::MatrixTransform) that decorates your geometry and places it in world coordinates. I didn't understand what was meant by local origin here. Let's say I have a model of the Sphinx I want to show on the surface of the Earth (coincidentally I'm trying to display geospatial data). Are you suggesting that I draw the model with coordinates relative to the origin of of the scene first ('local'), then parent the corresponding geode with a matrix transform that scales/moves/rotates it out to the correct position on the Earth's surface ('world coordinates')? I found a few references online to a somewhat similar solution that suggested transforming the entire scene so it's centered at the origin before passing it to OpenGL. Is this a worse or better approach than the suggested fix? The OSG by default uses double's for the Camera's View matrix and double's for the transform nodes and when accumulating all the matrices during the cull traversal uses doubles as well so that by the time the OSG maintains precision all the way till it passes the modelview matrix to OpenGL. Typically when you are close to your geometry the translation component of Camera's View matrix will cancel out with the translation component of your scene graph transform node, so that you end up with a final modelview passed to OpenGL with modest translation component that doesn't present any numerical precision issues, solving the precision. I understand that numerical precision decreases when rendering a scene further from the origin, because there are a finite set of numbers you can represent in floating point. Using doubles for the transform and carrying doubles throughout the scene graph traversals increases precision right up until the data is passed to OpenGL. I didn't quite follow your explanation about the camera and geometry translations cancelling out though... could you expand on this a bit? This approach is commonly used when tackling whole earth geospatial data, and you'll see it in action in the paged databases that VirtualPlanetBuilder creates, 3rd party NodeKit's like osgEarth use this approach as well. I'll take a look at the source for both of these projects, thanks :) Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Drawing poly line, jitter/vibration issue when moving camera
Hi, Preet, Robert is probably offline now, so I'll attempt to pick up where he left off... On 02/14/2012 12:47 PM, Preet wrote: I didn't understand what was meant by local origin here. Let's say I have a model of the Sphinx I want to show on the surface of the Earth (coincidentally I'm trying to display geospatial data). Are you suggesting that I draw the model with coordinates relative to the origin of of the scene first ('local'), then parent the corresponding geode with a matrix transform that scales/moves/rotates it out to the correct position on the Earth's surface ('world coordinates')? Exactly. This would allow the vertex coordinates (which are represented with 32 bit floats) to work with enough precision to prevent the instability you're seeing. I found a few references online to a somewhat similar solution that suggested transforming the entire scene so it's centered at the origin before passing it to OpenGL. Is this a worse or better approach than the suggested fix? I'm not sure I follow this question. Centered at what origin? I understand that numerical precision decreases when rendering a scene further from the origin, because there are a finite set of numbers you can represent in floating point. Using doubles for the transform and carrying doubles throughout the scene graph traversals increases precision right up until the data is passed to OpenGL. I didn't quite follow your explanation about the camera and geometry translations cancelling out though... could you expand on this a bit? Both the camera's View matrix and the transforms in the scene (which will be accumulated by OSG into a Model matrix) are represented with doubles by default. This gives them plenty of precision to represent large values. Now, say you move the camera close to your sphinx model. This will cause the Camera's View matrix to have a translation value that is close to the inverse of the sphinx's accumulated Model matrix. When the scene is traversed for rendering, the Model and View matrices are combined into the OpenGL ModelView matrix, which must now be represented as floats. However, the large (but opposite) translation values will combine to a ModelView translation that is relatively small before the matrix is sent to OpenGL. This means that the transformed vertex coordinates will also be relatively small, and they'll still have plenty of precision to work with when they're sent down the OpenGL pipeline for rasterization. --J ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Drawing poly line, jitter/vibration issue when moving camera
Hiya, I'm trying to draw a simple poly line from a vertex array with the GL_LINE_STRIP primitive. When I view the object using osgviewer, it looks like everything is alright. Once I move the camera around with the mouse however, the lines begin to jitter, like the polyline was made of jello (honestly can't find better description). The effect is especially visible at higher zooms. I'm using large (values in the hundred-millions), high precision numbers (doubles) for the vertices of the line strip, and I think that's what's causing the problem (I couldn't recreate the issue using smaller, more sane numbers from 1-500 for example, even though the same double datatype is used to store both numbers). I've posted my code here: http://pastie.org/3377862 The code only relies on STL and osg, so it should 'just compile' if you have an osg environment setup. The relevant calls to osg are on lines 121-141. I'm using OSG 3.0.1 on Arch Linux, kernel 3.2.x if it's relevant. Does anyone have any ideas as to what's going on? Regards, Pris ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Drawing poly line, jitter/vibration issue when moving camera
Hi Preet, 2012/2/14 Preet prismatic.proj...@gmail.com I'm using large (values in the hundred-millions), high precision numbers (doubles) for the vertices of the line strip, and I think that's what's causing the problem (I couldn't recreate the issue using smaller, more sane numbers from 1-500 for example, even though the same double datatype is used to store both numbers). I believe this is the cause of your problem. Use a transform node as the parent of your geodes and use it to reduce the number of digits. Regards, Wang Rui ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org