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

Reply via email to