Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Normals and GL_TRIANGLE_STRIP

354 views
Skip to first unread message

Chris Mark

unread,
Sep 12, 1996, 3:00:00 AM9/12/96
to

I am creating a 3D surface plot (mesh) from a series of triangle
strips laid side by side. I now want to use lighting on this so I
need to supply the normal vector for each triangle.

Each triangle within the strip could be facing in any direction and I
know how to calculate its normal vector,
BUT in a strip each triangle shares two vertices with the adjacent one
( like: /\/\/\/ ), so which normal do you set these to when adjacent
triangles are facing in different directions?

I have tried making the surface from individual triangles and setting
all three vertices to the same normal. This works but is 56%
(percent) slower than using triangle strips.

Is there any way to do this?

Thankyou for any help you may have,
Chris

--
Christopher Mark
Software Engineer,
Edinburgh Instruments Ltd., UK

Brian J. Green

unread,
Sep 13, 1996, 3:00:00 AM9/13/96
to chri...@edinst.com

Chris,

The short answer is that you'll need to average the normals of the
adjacent triangles. For example, consider two triangles that
share an edge. The first triangle has normal (-0.707, 0.707, 0).
The second triangle has normal (0.707, 0.707, 0). The normal
at any point along the shared edge (which include the 2 shared vertices)
is (0.0, 1.0, 0.0). Just viuslize the projection onto the
X-Y Plane.

So in psuedo-code
For each vertex:
get adjacent triangles
compute the normal for each triangle
average the normals

Remember, to average the normals you add them component wise and
then normalize the result.

Brian J. Green
Programmer
Logicon RDA

Angus Dorbie

unread,
Sep 16, 1996, 3:00:00 AM9/16/96
to

Brian J. Green wrote:
>
> Chris Mark wrote:
> >
> > I am creating a 3D surface plot (mesh) from a series of triangle
> > strips laid side by side. I now want to use lighting on this so I
> > need to supply the normal vector for each triangle.
> >
> > Each triangle within the strip could be facing in any direction and I
> > know how to calculate its normal vector,
> > BUT in a strip each triangle shares two vertices with the adjacent one
> > ( like: /\/\/\/ ), so which normal do you set these to when adjacent
> > triangles are facing in different directions?
> >
> > I have tried making the surface from individual triangles and setting
> > all three vertices to the same normal. This works but is 56%
> > (percent) slower than using triangle strips.
> >
> > Is there any way to do this?
> >
> > Thankyou for any help you may have,
> > Chris
> >
> > --
> > Christopher Mark
> > Software Engineer,
> > Edinburgh Instruments Ltd., UK
>
> Chris,
>
> The short answer is that you'll need to average the normals of the
> adjacent triangles.

The other approach is to use flat shading and send
a single normal for each triangle. Just ensure the
appropriate normal is sent before the last vertex of
the triangle in the mesh.

glShadeModel(GL_FLAT);

You may notice some very minor anomalies with specular effects or
local light sources.

Rgds,
Angus.

Andy V

unread,
Sep 16, 1996, 3:00:00 AM9/16/96
to

chri...@edinst.com (Chris Mark) writes:
>I am creating a 3D surface plot (mesh) from a series of triangle
>strips laid side by side. I now want to use lighting on this so I
>need to supply the normal vector for each triangle.
>
>Each triangle within the strip could be facing in any direction and I
>know how to calculate its normal vector,
>BUT in a strip each triangle shares two vertices with the adjacent one
>( like: /\/\/\/ ), so which normal do you set these to when adjacent
>triangles are facing in different directions?
>
>I have tried making the surface from individual triangles and setting
>all three vertices to the same normal. This works but is 56%
>(percent) slower than using triangle strips.

Chris, if you are using a triangular mesh as an approximation to a smooth
surface, then the 'proper' thing to do is to specify the normal at a vertex
as the normal to that smooth surface at that point. As long as the surface
you want is smooth and has no discontinuities, you want the same normal
at a vertex for all triangles that share that vertex.

Now consider a cylinder. There are three surfaces -- two flat ends
and a curved side. Where the side meets an end you have vertices that are
on both surfaces -- but they are on a line of discontinuity. You want to draw
the curved side using normals that point directly outward from the center
line of the cylinder through the point in question. You want to draw the
end using normals that are parallel to the center line. With OpenGL you
cannot use a triangle strip to cross that discontinuity because you cannot
specify two normals for that one vertex. You can insert a zero-area triangle,
but that is equivalent to starting a new triangle strip. You can use
a triangle list but that may be somewhat slower, as you have found out.

If you really need to specify a surface with triangular facets and sharp
edges (modelling a diamond, for example), you must specify one facet
independently from adjoining facets.

If you have a surface that represents a smooth surface and you want to see
the tessellation of that surface, you can try flat shading (call
glShadeModel (GL_FLAT)). This assigns the computed color for one vertex to
an entire triangle. Not knowing exactly what you are modelling, this may
or may not be acceptable.

--
Andy V (A Digital spoke, not a Digital Spokesperson)
mailto:andy....@eng.pko.dec.com

jul...@ncgraphics.co.uk

unread,
Sep 19, 1996, 3:00:00 AM9/19/96
to

In article <323D49...@reading.sgi.com>
Angus Dorbie <dor...@reading.sgi.com> wrote:


Chris Mark wrote:

> I am creating a 3D surface plot (mesh) from a series of triangle

> strips laid side by side. ...

> I need to supply the normal vector for each triangle.

> BUT in a strip each triangle shares two vertices with the adjacent one,

> so which normal do you set these to when adjacent triangles are facing
> in different directions?


Brian J. Green wrote:

> The other approach is to use flat shading and send
> a single normal for each triangle. Just ensure the
> appropriate normal is sent before the last vertex of
> the triangle in the mesh.
>
> glShadeModel(GL_FLAT);


Does this work? I haven't had time to experiment (by drawing two
cubes side by side in GL_FLAT but with some of the faces chained
up in a strip.

It doesn't say in any of the manuals I've seen what you should expect
when you combine GL_FLAT mode and GL_(TRIANGLE/QUAD)_STRIP mode.

I think we should be told.

JT.


David Blythe

unread,
Sep 20, 1996, 3:00:00 AM9/20/96
to

normals are used to to produce a color. the glShadeModel man page
describes the treatment of colors for different primitives:

Flat and smooth shading are indistinguishable for points. Counting
vertices and primitives from one starting when glBegin is issued, each
flat-shaded line segment i is given the computed color of vertex i+1, its
second vertex. Counting similarly from one, each flat-shaded polygon is
given the computed color of the vertex listed in the following table.
This is the last vertex to specify the polygon in all cases except single
polygons, where the first vertex specifies the flat-shaded color.

______________________________________
|primitive_type_of_polygon_i_|_vertex_|
|Single polygon (i=1) | 1 |
|Triangle strip | i+2 |
|Triangle fan | i+2 |
|Independent triangle | 3i |
|Quad strip | 2i+2 |
|Independent quad | 4i |
|____________________________|________|

>
>JT.
>

0 new messages