View Full Version : Normals in vertex arrays (triangle normals vs. vertex normals)

I exported a VRML model out of a CAD workstation that gave me a vertex array with normals for each triangle. Rendering this manually (rendering the triangles in a loop in my program) looks ok but I would like to use vertex arrays to let OpenGL do the work.

First I just calculated the vertex normals to be the mean of all triangle normals that use this vertex. I found out that I was not the first one who made this mistake: vertices on every edge look wrong because I need two normals here. I understand that.

But how can I solve my problem without generating two different vertices on edges?

Is the GL_EDGE_FLAG_ARRAY something that can help me here?

What is the GL_EDGE_FLAG_ARRAY? There isn't much about it in the Red Book.

Thx - Volker

CrazyButcher

04-13-2004, 11:20 PM

I dont know about those edge flags, but to make a hard edges you will need to have 2 vertices per edge, one vertex facing lets say up, the other one facing left (normals) and then create the appropriate triangles using either one or the other vertex.

basically you just share positions, but from what I know when working with vertex arrays, you will get two vertices in the array, one time with one normal, the other one with another normal

it works fast so dont worry :)

think of just sharing the same vertices if things are smooth, else you need to break up.

When working with software like max, its similar the smoothing groups are assigned to the tris, and from that the vertex normals are created and if needed split into to vertices... just that they appear to be one in the sofware.

charliejay

04-14-2004, 01:49 AM

Edge Flags are for indicating whether or not a particular edge of a polygon should be draw, when you're drawing the outline in, say, wireframe mode.

They can't help you here, they're intended to let you do things like drawing the outline of a concave polygon correctly.

Since OpenGL only supports convex primitives, a concave polygon would need to be made up of several smaller convex primitives, some of which would share edges.

Edge flags lets you designate the shared edges as internal, so that when the concave polygon is drawn, its outline is correct...

CJ

@ charliejay:

You're right - this has nothing to do with my problem. But thanks anyway!

@ CrazyButcher:

I can't use two vertices for the edge because I have (or want) to use the data that came as an export out of the CAD system. There are about 16000 triangles - no chance to search the ones at the edges and double them :-)

CrazyButcher

04-14-2004, 12:52 PM

dont know if it could work but another idea might be turning on/off FLAT shading at the right time instead of SMOOTH...

Overmind

04-14-2004, 01:36 PM

No, the idea with turning flat shading on/off doesn't work because the normal would still be wrong...

Since you can't give two independant indices for vertex and normal arrays, you have to double the vertices, but that's not nearly as much work as it sounds, not even for 16000 triangles.

Consider this simple algorithm:

Start with the vertex array from your CAD system and initialize the normals to zero. For each triangle look at the normals of the vertices.

- If it is zero, overwrite with the triangle normal.

- If it is already equal to the triangle normal, leave it alone.

- If it is different, double the vertex and change the index in your triangle list to the new copy.

This has to be done only at model load time, and it runs in linear time, so on modern CPUs you could process millions of triangles in no time. Ok, it could produce double vertices with identical normals, but handling that is not so difficult either...

EDIT: Formatting... :rolleyes:

I should initialize the normals to zero and look at them afterwards...?

I think I got your idea but I wouldn't double them if they are not equal. That would double even those vertices of triangles that have just a little bit different normals. But in these cases I want the vertex normals to be the mean of the two triangle normals because it makes the surfaces smooth.

Only if the triangle normals differ around lets say 90 (or 80 or whatever) degrees then I can be sure that there is an edge and I have to double the two vertices and edit the vertex indices of both triangles.

I think I'll try that!

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.