View Full Version : gl_normal
In opengl, we can associate a vertex with several different normals. For example, three adjacent planes of a cube will have a common vertex, i.e., a vertex may belong to three different planes. Then when we specify each of these three polygons, the common vertex will be given three different normals. My question is, in the vertex shader, which normal will be returned by gl_Normal?
09-23-2007, 02:29 AM
The vertex shader will be run 3 times, once for each normal.
Thanks. Does it mean that opengl will create a new vertex whenever it sees a glVertex command even in the case that the vertex may have the same coordinates as the one given before?
09-23-2007, 05:30 AM
Vertices can only be re-used when you use indexed vertex arrays and access the same index twice.
09-23-2007, 10:33 AM
Yes, each glVertex call will generate a new vertex and use the other currently set parameters (normal, color, tex coords) for this vertex.
You can only have vertex sharing if you use strips, fans or indexed vertex arrays. When using vertex arrays you would have to store your vertices three times though (once for each variation in the attributes). For large meshes preprocessing the models with a tool like nvtristrip might give the best performace.
[ www.trenki.net (http://www.trenki.net) | vector_math (3d math library) (http://www.trenki.net/content/view/16/36/) | software renderer (http://www.trenki.net/content/view/18/38/) ]
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.