Hello all,

I'm having a problem with the builtin uniform osg_ViewMatrix, in that it doesn't seem to be what I expect. Here's what I want to do:

- I have a planar surface (made out of a lot of adjacent quads) that I want to distort so that it looks like a sphere; only from a fixed position of course - To distort every vertex I use a vertex shader that takes the current vertex, calculates the vector between itself and the virtual center of the sphere, normalizes this vector and multiplies it with the radius of the virtual sphere. In shader form:

void main() {
  [...color stuff...]

  float radius = 2.0;
  vec4 center = vec4(0,0,1,1);

  vec4 delta = gl_Vertex - center;
  delta = normalize(delta);
  delta = delta * radius;

  vec4 newPosition = center + delta;
  gl_Position = gl_ModelViewProjectionMatrix * newPosition;
}

- The above code works fine when pasted into the OpenGL Shader Builder application that is bundled with the Xcode development tools - I understand that this approach doesn't work without modifications in a scene graph because of the local coordinate system of each node. - I have to transform the global virtual sphere center into every node's coordinate system to achieve the correct projection. I used osg_ViewMatrix do do exactly that:
  "center = osg_ViewMatrix * vec4(0,0,1,1);"

=> However, the result was that the center always seemed to have the same position relative to the current node's coordinate system... so that every projection looked the same, the quads weren't next to each other anymore.

My questions are:
- Is the problem clear? Or is it better if I posted some sample code?
- Do I use the uniform osg_ViewMatrix correctly? Or do I have the concepts confused? - Do I have to do anything to make osg_ViewMatrix have the correct value? As I understand it, osg does that for me.

Thanks in advance,
Erik.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to