(I've really just skimmed your message quickly)
Do you know about the "built-in" OSG uniforms osg_ViewMatrix and
osg_ViewMatrixInverse?  Combined with the GLSL built-in
gl_ModelViewMatrix, perhaps all the info you need is already available
to the shader?

cheers
-- mew




On Sun, May 25, 2008 at 2:42 AM, zhangguilian <[EMAIL PROTECTED]> wrote:
> Hi,
> I use glsl for shader and build a scene using osg2.4, the scene graph tree
> is shown in the diagram, I render the same scene in two passes with two
> cameras, I want to get the world coordinate of vertex in both of the two
> vertex shaders, I use this method:
>
> //to each of the geode added to the scene:
> osg::Matrix ComputeAllParentsTransforms(Geode& node)
> {
>
>  Matrix ret;
>  ret.identity();
>  //if(!node)return ret;
>
>  if(node.getNumParents()>0)
>  {
>   Node* parent=node.getParent(0);
>
>   do
>   {
>
>    MatrixTransform* mt=dynamic_cast<MatrixTransform*>(parent);
>    if(mt)
>    {
>     ret*=mt->getMatrix();
>    }
>    parent=parent->getParent(0);
>
>   }
>   while((parent->getNumParents()>0)&&(parent->getName()!="MRT_CAMERA"));//the
> first pass camera and the second pass camera is named "MRT_CAMERA"
>
>  }
>  return ret;
>
> }
>  I set this matrix as a uniform("LocalToWorldMatrix ",Matrix()) to the
> vertex shader, and do:worldPosition= LocalToWorldMatrix * gl_Vertex; I think
> this result is the world coordinate of the vertex, am I right? Can I get the
> world coordinate of the vertex using this method? Are there any good and
> right method to get the world coordinate of the vertex? And Can I get the
> world normal through this way:
>
>  vec4 nrm=vec4(gl_Normal,0.0);
>  WorldNrm= (LocalToWorldMatrix *nrm).xyz;
> If it is a bad method, Could you please give me some advice about how to get
> the world coordinate and world normal? Any information about this will be
> OK.
>
> I would appreciate it very much if you would help me with it. Thanks very
> much!
>
> ________________________________
> zhangguilian
> 2008-05-25
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>



-- 
Mike Weiblen -- Austin Texas USA -- http://mew.cx/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to