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 > > > [email protected] > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > > > > > > > > > > > > > > > > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > -- Mike Weiblen -- Austin Texas USA -- http://mew.cx/ _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

