Your issue is a relatively straightforward linear algebra problem. If you didn't pick up this skill set in grade school or a university-level course, It's unlikely someone will teach you linear algebra on this mail list. (Not trying to sound like a know-it-all; it's simply a fact that software developers attempting to code 3D graphics should have a strong background in linear algebra.)

The OpenGL red book contains a good overview of OpenGL's coordinate spaces, plus there are many good linear algebra books that focus on 3D graphics. You could also hire a consultant to code the solution for you.

Does the distance computation have to run on the GPU? For example, you could read back the depth buffer and then do the distance computation on the CPU. CPU code to do this already exists; see SceneView::projectWindowIntoObject(), in SceneView.cpp at line 1481 as one example. (Note this back-transforms to object space, not world space, so modify it if necessary to suit your situation.)

If the code has to run on the GPU, certainly you can use the SceneView function as inspiration.
   -Paul


On 1/4/2012 12:41 PM, Ethan Fahy wrote:
Thanks GMan for the reply and the source code, much appreciated.  I was able to 
tweak your shaders for my needs and I think I am off to a good start.  However 
I'm still not sure exactly what coordinate system I'm dealing with.  In my 
case, I have an osg terrain loaded in in geocentric coordinates with various 
trees and other objects placed on the terrain.  I will then set my camera 
position.  When I visualize he scene, I have to apply a shader that is able to 
tell me, in meters, the distance between the camera and whatever object is 
being viewed in each pixel.  For example, for a given camera angle, I may have 
a leaf of a tree in the upper left pixel of the frame.  I need to be able to 
get the distance in meters from the camera to that leaf so that I can apply 
some scientific equations and recolor that pixel.  This is important because I 
have a modified osg viewer that reads in the red channel of the pixels from the 
framebuffer and does further calculations based on the val
ue
   of that red channel.  Most GLSL examples are geared at creating visual 
effects, whereas I am encoding real scientific data in the color bands and then 
decoding them at various steps so I can't just scale values according to what 
looks best.  Any advice on how I might get the distance in meters (assuming 
that every osg object in my scene has been loaded in already in meters)?



_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to