[osg-users] How to translate the light posiotion from world space to eye space in glsl

2008-09-08 Thread guilianzhang
Hi,
To make phong shading using shaders(in GLSL), I have to pass the the light 
position to the vertex shader,  But the position of the vertex will be in 
eyespace (after multiplication with the ModelView matrix). So I need the light 
position in eye-space as well. Which is the best way of obtaining the correct 
light position? Either I need the vertex position to be in world space, I do in 
this way:

 
mat4 modelMatrix = osg_ViewMatrixInverse* gl_ModelViewMatrix ;
WorldPos=modelMatrix * gl_Vertex;
mat3 normalmatrix=mat3(modelMatrix);
WorldNrm=normalize(normalmatrix * gl_Normal);

though it works well to get the world space coordinate of each vertex, but to 
compute specular of object I have to know the eye position, since we are not in 
eye coordinates the eye postion is no longer (0,0,0), must the eye coordinate 
be passed by uniform?

Or I need the light position in eye space. I try to translate the light 
position into eye coordinate in this way:
 Pos_light0 =  osg_ViewMatrix *light0_pos  ; 
 or 
 Pos_light0 =  light0_pos * osg_ViewMatrix ; 

 but it seems not work.

What are the general strategy for this problem?


Thanks very much!


Julie
2008-09-09
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] How does each object set its own light parameters?

2008-08-28 Thread guilianzhang
Hi,
I build a scene using osg which is composed of many objects and many lights, I 
want to traverse each object to find the nearest  light away from it and 
associate the light with GL_LIGHT0, so each object has its own GL_LIGHT0 
parameters. 
The problem is that the light is added to the scene by adding a 
osg::LightSource, and the LightSource node then is added to the scene graph, 
Must I add LightSources for each object to set its own light parameters? Is 
there any better method?

Thanks very much!
 



guilianzhang
2008-08-28
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] How to control RTT camera sometimes work and sometimes don't work

2008-07-02 Thread guilianzhang

Hi,
I want to let the RTT camera render the scene only when the scene changed, are 
there any callback mechanism that I can control the RTT camera when it has to 
update the texture and when it should stop working? 

If I make the RTT camera stop working, will the textures it renders be 
destroyed instantly? 
If the texture will be destroyed, how can I save the data of MRT to images for 
I will use these data every frame in the later pass?
Are there any method that make the MRT data avoid being destroyed instead of 
copy those data to images?

Thanks very much!



guilianzhang
2008-07-03
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Which matrix decides the world position of the vertex

2008-07-01 Thread guilianzhang
Hi,
This problem has confused me for a long time, I have made a lot of effort to 
get the matrix which translate the vertex from local coordinate to world space 
coordinate in osg, however, the result seems that the matirx I get from 
MatrixTransform does not work in glsl.

Though it seems that I can get the world position of the vertex through 
osg_ViewMatrixInverse combined with gl_ModelViewMatrix, but I think it is not 
advisable for there are so much instructions for vertex shader.

I build the indoor scene using osg2.4. Each object added to the scene is added 
to a MatrixTransform(mt) node which containing all the information of 
translation,rotation and so on, this MatrixTransform node is then added to the 
root. I send the matrix(ModelWorld = mt-getMatrix()) to the vertex shader to 
get the world position of the vertex, but the result of gl_Vertex * ModelWorld 
in glsl seems not the world position of the vertex.

Any informations about this will be appreciated.
Thanks very much for your help!



guilianzhang
2008-07-01
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] World position of the vertex

2008-06-29 Thread guilianzhang
Hi,
I build a indoor scene using osg2.4. Each object added to the scene is added to 
a MatrixTransform(mt) node which containing all the information of 
translation,rotation and so on, this MatrixTransform node is then added to the 
root.

Since the matrix contains the information about position of the node, I send 
this matrix(ModelWorld = mt-getMatrix()) to the vertex shader to get the world 
position of the vertex, but the result of gl_Vertex * ModelWorld in glsl seems 
not the world position of the vertex.

So I have many problems:
1. Does gl_Vertex in glsl has any relationship with the matrix of 
MatrixTransform which the node added to in osg? Can I say that gl_Vertex is 
just the local coordinate of the vertex of the node? 
2. I think this matrix do translate the object to world space, but why 
gl_Vertex * ModelWorld is not the world position of the vertex?
3. As is known to all , gl_ModelViewMatrix in glsl translate the vertex from 
local space to eye space, I want to know how does osg use this matrix 
(getMatrix from MatrixTransform) to translate the object to world space and 
then how does it combined with view matrix to get the modelviewmatrix that we 
get in glsl in the form of gl_ModelViewMatrix.

Thanks very much!

guilianzhang
2008-06-29
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] The sceneview data is cleared up when restore the minimized programs

2008-06-01 Thread guilianzhang
Hi,

I'm using osgUtil:: SceneView, sometimes when restore the minimized programs 
the sceneview data seems to be cleared up and only background color left, the 
whole scene appear on the screen until I do some operations such as click a 
button, Does anybody else come across this problem? 

I don't know this problem has relationship with what and how to solve this 
problem, any suggestions would be appreciated.

Thanks.



guilianzhang
2008-06-02
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Getting world space normal

2008-05-27 Thread guilianzhang
Hello Mike and Paul,

I can easily get the point transformation matrix in this way:
 mat4 ToWorldMatrix = osg_ViewMatrixInverse* gl_ModelViewMatrix;
 WorldPos= ToWorldMatrix * gl_Vertex;

How can I get the inverse transpose of the ToWorldMatrix and set its 
translation part to zero? There seems to be no inverse and transpose funtions 
in glsl.

Thank you very much!



guilianzhang
2008-05-28



发件人: Mike Weiblen
发送时间: 2008-05-28 01:36:52
收件人: OpenSceneGraph Users
抄送: 
主题: Re: [osg-users] Getting world space normal

Well, not so much a requirement as OpenGL convention.

GL defines a normal as a 3-component vector (there are only the
glNormal3*() calls, unlike glVertex which has many sizes)

And the GLSL builtins : gl_NormalMatrix is a mat3 and gl_Normal is a vec3.

But sure, you can make the math with larger number of components.

-- mew



On Tue, May 27, 2008 at 9:41 AM, Paul Melis  [EMAIL PROTECTED]  wrote:
 Mike Weiblen schreef:
 
  Normals must be transformed by a normal matrix (which is a mat3).  It
  is not correct to promote a normal to a vec4 and try to use the
  transformation matrix (which is a mat4).
 

 Just curious: the mat3 requirement comes from the OpenGL shading language?
 As mathematically there's nothing wrong with representing a normal with (x,
 y, z, 1) as long as the 4x4 matrix being multiplied with is the inverse
 transponse of the point transformation (as you remarked) and has a zero
 translation part.

 Paul
 
  You'll need to generate a new normal matrix, which is defined as the
  upper-left mat3 of the inverse transpose of the transformation matrix.
 
  -- mew
 
 
 
 
  On Tue, May 27, 2008 at 8:30 AM, zhangguilian  [EMAIL PROTECTED] 
  wrote:
 
  
   Hi,
  
   I want to get the normal in world space, I can not use
   gl_NormalMatrix because it will translate the normal from local space to
   eye
   space, from you hint I do in this way:
  
   mat4 ToWorldMatrix = osg_ViewMatrixInverse* gl_ModelViewMatrix;
   WorldPos= ToWorldMatrix * gl_Vertex;
  
vec4 normal=vec4(gl_Normal,0.0);
WorldNrm= (ToWorldMatrix * normal).xyz;
WorldNrm=normalize(WorldNrm);
  
   the worldpos seems right, but worldNrm seems has problem, Can I get the
   world space normal in this way?
  
   Thanks very much for your consideration!
  
   
   zhangguilian
   2008-05-27
   ___
   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




-- 
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
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org