matrix and polygon (or vertex) normals

matrix and polygon (or vertex) normals

Post by Lucas Monte » Mon, 30 Jun 2003 19:21:03



hello,

i'm doing a basic 3d modeler with a perspective view. i'd like to know
how i can adapt the perspective transformation matrix for normals, or if
it simply doesn't need to be adapted?

the formulas for perspective transformation are (when vertex are in the
eye space with the camera oriented along the x axis) :

xs = F * ((1 - D) / xe) / (F - D)

ys = D * ye / (h * xe)

zs = D * ze / (h * xe)

with D is the distance between the eye and the view plane, F is the
distance of the far clipping plane, and h the dimension of the view plane.

to transform into matrix form we separate like this :

xc = (h * F *  xe) / (D * (F - D)  -  (h * F) / (F - D)

yc = ye

zc = ze

w = (h * xe) / D

and then xs = xc / w ,  ys = xc / w   and   zs = zc / w

this gives the matrix :

| (hF) / (D(F-D)   0     0     (-hF) / (F - D) |
|       0          1     0             0       |
|       0          0     1             0       |
|      h/d         0     0             0       |

so the thing i'd like to know is how to obtain the equivalent matrix for
normals ?

i'v heard that it can be done by deleting the translations elements
(M30, M31 and M32), and then getting the transpose of the inverse of the
matrix M. but as i'm not sure of that i'd like different opinion.

Thanks,

--
Lucas
Montes

 
 
 

matrix and polygon (or vertex) normals

Post by Hans-Bernhard Broeke » Tue, 01 Jul 2003 02:28:40



Quote:> hello,
> i'm doing a basic 3d modeler with a perspective view. i'd like to know
> how i can adapt the perspective transformation matrix for normals, or if
> it simply doesn't need to be adapted?

Depends on what your matrix does.  The true story is that normals
transform like "dual vectors".  I.e. if you transform vectors by a
matrix M, normals get transformed by inverse(transpose(M)).

For pure rotations with determinant +1 (no mirroring), that results in
M itself, again.

Quote:> i'v heard that it can be done by deleting the translations elements
> (M30, M31 and M32), and then getting the transpose of the inverse of the
> matrix M. but as i'm not sure of that i'd like different opinion.

You don't have to delete any elements.  Just make sure your normals,
just like your vectors, have 4 coordinates, the fourth one being zero.
As a benefit, this will let you transform whole plane equations, not
just normal vectors.
--

Even if all the snow were burnt, ashes would remain.

 
 
 

matrix and polygon (or vertex) normals

Post by Michael Garrit » Wed, 02 Jul 2003 05:01:22



> In comp.graphics.algorithms Lucas Montes

>> hello,

>> i'm doing a basic 3d modeler with a perspective view. i'd like to
>> know
>> how i can adapt the perspective transformation matrix for normals,
>> or if
>> it simply doesn't need to be adapted?

> Depends on what your matrix does.  The true story is that normals
> transform like "dual vectors".  I.e. if you transform vectors by a
> matrix M, normals get transformed by inverse(transpose(M)).

 That's correct. And if you are going to end up renormalizing the
vectors, then you can use the adjoint instead of the inverse because
they differ by a constant factor. That can save you the division by
the determinant.

Of course you might want to consider doing the lighting before
the projection transform. That's usually a bit simpler. Same math
applies though, in case of things like nonuniform scaling.

    -MPG-

 
 
 

matrix and polygon (or vertex) normals

Post by Lucas Monte » Wed, 02 Jul 2003 19:19:26




>>In comp.graphics.algorithms Lucas Montes

>>>hello,

>>>i'm doing a basic 3d modeler with a perspective view. i'd like to
>>>know
>>>how i can adapt the perspective transformation matrix for normals,
>>>or if
>>>it simply doesn't need to be adapted?

>>Depends on what your matrix does.  The true story is that normals
>>transform like "dual vectors".  I.e. if you transform vectors by a
>>matrix M, normals get transformed by inverse(transpose(M)).

>  That's correct. And if you are going to end up renormalizing the
> vectors, then you can use the adjoint instead of the inverse because
> they differ by a constant factor. That can save you the division by
> the determinant.

> Of course you might want to consider doing the lighting before
> the projection transform. That's usually a bit simpler. Same math
> applies though, in case of things like nonuniform scaling.

thanks to you.

i'm a little lost because my book ("advanced animation and rendering
techniques" by Alan and Mark WATT) they say:
working in homogeneous coordinates it can be shown that the
transformation matrix for the normals, Mn, is derived from the
transformation matrix of the vertices M in the following steps :

  - Remove the components of the matrix M that are responsible for
translation. In practice this means setting M30, M31, M32 to zero. This
gives us the transformation matrix for the tangential directions of the
object (MT).

- then, using the fact that T . N = 0, and T' . N' must stay zero, the
matrix for the normals is obtained by taking the transpose of the
inverse of the tangent's transformation matrix, that is :
   Mn = (MT-1)t.

did i have misunderstand something or is there special cases?

i do shading after the perspective transformation, at the same time as
hidden surface removal and rasterization, that's why i need to get
normals in screen space.

thanks again,

--
Lucas
Montes

 
 
 

matrix and polygon (or vertex) normals

Post by Hans-Bernhard Broeke » Wed, 02 Jul 2003 19:56:00



> i'm a little lost because my book ("advanced animation and rendering
> techniques" by Alan and Mark WATT) they say:

Just because they describe it differently doesn't mean it's a
different technique altogether, much less that only one of the two
techniques being described could be correct.  They both are.

Quote:>   - Remove the components of the matrix M that are responsible for
> translation. In practice this means setting M30, M31, M32 to zero. This
> gives us the transformation matrix for the tangential directions of the
> object (MT).

This is not really necessary.  It's actually a step that limits the
usefulness of this approach a bit.  You will now have a 3x3 matrix,
effectively, not a true 4x4 homogeneous matrix any longer.  This means
you can only transform simple normal *vectors* with the matrix coming
out of this process.  Doing the M^{-T} trick on the full 4x4 gives you
a matrix that works for both normal vectors and full 4-element plane
coefficient vectors.

Quote:> i do shading after the perspective transformation,

I don't think that's a very good plan.  Shading is partially based
upon the size of angles between vectors as input to calculations, but
the perspective transformation doesn't preserve those angles.  This
introduces display errors.  You should do shading in world or view
space, not screen space.

--

Even if all the snow were burnt, ashes would remain.

 
 
 

matrix and polygon (or vertex) normals

Post by Just d' FAQ » Thu, 03 Jul 2003 08:08:30


On Tue, 01 Jul 2003 12:19:26 +0200, Lucas Montes


>i'm a little lost because my book ("advanced animation and rendering
>techniques" by Alan and Mark WATT) they say:
>working in homogeneous coordinates it can be shown that the
>transformation matrix for the normals, Mn, is derived from the
>transformation matrix of the vertices M in the following steps :

At this point we should move beyond a cookbook to get some theory.

We are given a matrix M that transforms points. We wish to transform
normals. Normals are not points, so we must understand how they relate
to points; then we can derive their transform.

A normal is thought of as a vector perpendicular to points in a plane.
Which means if we are given any two points in the plane, say P and Q,
then the vector between them, V = Q-P, is perpendicular to normal U.

  U.(Q-P) = 0

or

  U^T (Q-P) = 0

Even better, we can take the dot product of U with P and get the same
number as with Q or any other point in the plane.

  d = U.Q
    = U.(P+(Q-P))
    = U.P + U.(Q-P)
    = U.P
This gives us an implicit equation for the plane. For plane points P,

  U.P = d

After transforming all the points by matrix M the transformed plane
has a new normal U', which should again satisfy

  U'^T (MP - MQ) = 0

and also, with a new d',

  U'^T MP = d'

So we let

  U'^T = U^T M^-1

or

  U' = (M^-1)^T U

That handles the normal, and with a little extra will give us d'. To
transform the whole plane equation, we merely switch to homogeneous
coordinates. Then U and d together are the 4 components of the plane
equation's homogeneous form, and again (M^-1)^T does the trick.

 
 
 

matrix and polygon (or vertex) normals

Post by Lucas Monte » Thu, 03 Jul 2003 20:30:30



> On Tue, 01 Jul 2003 12:19:26 +0200, Lucas Montes

>>i'm a little lost because my book ("advanced animation and rendering
>>techniques" by Alan and Mark WATT) they say:
>>working in homogeneous coordinates it can be shown that the
>>transformation matrix for the normals, Mn, is derived from the
>>transformation matrix of the vertices M in the following steps :

> At this point we should move beyond a cookbook to get some theory.

> We are given a matrix M that transforms points. We wish to transform
> normals. Normals are not points, so we must understand how they relate
> to points; then we can derive their transform.

> A normal is thought of as a vector perpendicular to points in a plane.
> Which means if we are given any two points in the plane, say P and Q,
> then the vector between them, V = Q-P, is perpendicular to normal U.

>   U.(Q-P) = 0

> or

>   U^T (Q-P) = 0

> Even better, we can take the dot product of U with P and get the same
> number as with Q or any other point in the plane.

>   d = U.Q
>     = U.(P+(Q-P))
>     = U.P + U.(Q-P)
>     = U.P
> This gives us an implicit equation for the plane. For plane points P,

>   U.P = d

> After transforming all the points by matrix M the transformed plane
> has a new normal U', which should again satisfy

>   U'^T (MP - MQ) = 0

> and also, with a new d',

>   U'^T MP = d'

> So we let

>   U'^T = U^T M^-1

> or

>   U' = (M^-1)^T U

> That handles the normal, and with a little extra will give us d'. To
> transform the whole plane equation, we merely switch to homogeneous
> coordinates. Then U and d together are the 4 components of the plane
> equation's homogeneous form, and again (M^-1)^T does the trick.

thanks again.

--
Lucas
Montes

 
 
 

matrix and polygon (or vertex) normals

Post by Gernot Hoffma » Fri, 04 Jul 2003 01:47:06


....

Quote:

> i'm a little lost because my book ("advanced animation and rendering
> techniques" by Alan and Mark WATT) they say:
> working in homogeneous coordinates it can be shown that the
> transformation matrix for the normals, Mn, is derived from the
> transformation matrix of the vertices M in the following steps :

>   - Remove the components of the matrix M that are responsible for
> translation. In practice this means setting M30, M31, M32 to zero. This
> gives us the transformation matrix for the tangential directions of the
> object (MT).

> - then, using the fact that T . N = 0, and T' . N' must stay zero, the
> matrix for the normals is obtained by taking the transpose of the
> inverse of the tangent's transformation matrix, that is :
>    Mn = (MT-1)t.

> did i have misunderstand something or is there special cases?

> i do shading after the perspective transformation, at the same time as
> hidden surface removal and rasterization, that's why i need to get
> normals in screen space.

> thanks again,

Lucas,

lets have a look at a sea-urchin, spherical body and spines which
represent the normals, though the individual doesnt know this.
THESE normals are transformed like any other part of the object.

Geometrical normals are mainly used in 3D, therefore I dont under-
stand why they have to be transformed by a special transformation
into 2D.

For me it looks as if you want to do something like Phong shading.
In this case you would need the 3D representation of the normals
for the calculation of the surface lightness.
How can you check visibility by projected normals ?

Just curious ...

Best regards  --Genot Hoffmann

 
 
 

matrix and polygon (or vertex) normals

Post by Lucas Monte » Fri, 04 Jul 2003 15:39:14


,

Quote:

> Lucas,

> lets have a look at a sea-urchin, spherical body and spines which
> represent the normals, though the individual doesnt know this.
> THESE normals are transformed like any other part of the object.

> Geometrical normals are mainly used in 3D, therefore I dont under-
> stand why they have to be transformed by a special transformation
> into 2D.

> For me it looks as if you want to do something like Phong shading.
> In this case you would need the 3D representation of the normals
> for the calculation of the surface lightness.
> How can you check visibility by projected normals ?

> Just curious ...

because i check for visibility, in the projective screen space, wich is
in 3 dimensions, with the center of projection equal to negative
infinity along the z-axis (for a camera looking in the z-axis
direction). this space is suited to perform hidden surface removal but
shading too...

--
Lucas
Montes

 
 
 

matrix and polygon (or vertex) normals

Post by Hans-Bernhard Broeke » Fri, 04 Jul 2003 19:55:28



> in 3 dimensions, with the center of projection equal to negative
> infinity along the z-axis (for a camera looking in the z-axis
> direction). this space is suited to perform hidden surface removal but
> shading too...

I think I mentioned that in an earlier post, but you seem not to have
noticed: the coordinates after perspective transformation are
typically *not* usable for doing shading with.  The reason is that
perspective transformation doesn't preserve angles, but shading
calculations use lots of angles as inputs, e.g. to calculate all types
of directed lighting effects.  E.g. the perspective-projected version of
a cube may have not a single right angle between any of its edges
left.

If you transform normals the way discussed in this thread, they will
still be orthogonal to their faces, by definition of their specialized
transformation matrix.  This will *not* hold for angles between pairs
of normals, or pairs of edges, though.

--

Even if all the snow were burnt, ashes would remain.

 
 
 

matrix and polygon (or vertex) normals

Post by Lucas Monte » Sat, 05 Jul 2003 21:27:50




>>in 3 dimensions, with the center of projection equal to negative
>>infinity along the z-axis (for a camera looking in the z-axis
>>direction). this space is suited to perform hidden surface removal but
>>shading too...

> I think I mentioned that in an earlier post, but you seem not to have
> noticed: the coordinates after perspective transformation are
> typically *not* usable for doing shading with.  The reason is that
> perspective transformation doesn't preserve angles, but shading
> calculations use lots of angles as inputs, e.g. to calculate all types
> of directed lighting effects.  E.g. the perspective-projected version of
> a cube may have not a single right angle between any of its edges
> left.

> If you transform normals the way discussed in this thread, they will
> still be orthogonal to their faces, by definition of their specialized
> transformation matrix.  This will *not* hold for angles between pairs
> of normals, or pairs of edges, though.

thanks, that part wasn't discussed in my book. i've changed it know and
i calculate intensities in eye space.

--
Lucas
Montes

 
 
 

1. matrix and polygon (or vertex) normals

hello,

i'm doing a basic 3d modeler with a perspective view. i'd like to know
how i can adapt the perspective transformation matrix for normals, or if
it simply doesn't need to be adapted?

the formulas for perspective transformation are (when vertex are in the
eye space with the camera oriented along the x axis) :

xs = F * ((1 - D) / xe) / (F - D)

ys = D * ye / (h * xe)

zs = D * ze / (h * xe)

with D is the distance between the eye and the view plane, F is the
distance of the far clipping plane, and h the dimension of the view plane.

to transform into matrix form we separate like this :

xc = (h * F *  xe) / (D * (F - D)  -  (h * F) / (F - D)

yc = ye

zc = ze

w = (h * xe) / D

and then xs = xc / w ,  ys = xc / w   and   zs = zc / w

this gives the matrix :

| (hF) / (D(F-D)   0     0     (-hF) / (F - D) |
|       0          1     0             0       |
|       0          0     1             0       |
|      h/d         0     0             0       |

so the thing i'd like to know is how to obtain the equivalent matrix for
normals ?

i'v heard that it can be done by deleting the translations elements
(M30, M31 and M32), and then getting the transpose of the inverse of the
matrix M. but as i'm not sure of that i'd like different opinion.

Thanks,

--
Lucas
Montes

2. Intersecting a torus...

3. BSP polygon splitting and vertex normals

4. New COMPAQ: *Includes* DVD Recordable Drive

5. Glassner's Algorithm: Building Vertex Normals from an Unstructured Polygon List

6. Dib -> TBitmap

7. Normals for polygons containing more than 3 vertices

8. pixels in cm

9. Polygon Vertex Normals

10. triangles with per face normals SLOWER than per vertex normals

11. Vertex normals at the Bezier control vertex

12. Xform vertexes of a primitive by different matrixes / VERTEX BLENDING

13. question: vertex arrays under win98 + vertices to polygons