# Color per Vertex... but not smooth color

This topic is 4157 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm programming radiosity program, almost done. Each polygon(triangle) have own polygon color. To calculate the vertexcolor, color of adjacent polygon about one vertex, that is summed and divided by number of adjacent polygon, is to be vertex color. Anyway, I draw triangle using each vertex color, like this. for each face get VertexIndexNum glColor3f( vertex_color_of_index... ) glVertex3f( vertex_position_of_index... ) Most region is smooth, but some is not. Some triangles are appeared with boundaries. How can I solve this problem? (I set 'glShadeModel( GL_SMOOTH )', of course.)

##### Share on other sites
Do you need distinct normals for each face? If so, I guess you don't share vertices between faces but have copies with different normals. Did you check that all copies of a vertex have the same color assigned?

Additionally, if you use lighting with distinct normals per face you're likely to have those sharp edges (in fact that's what you normally want to achieve with distinct normals).

You could try to share vertices between adjacent faces (even if they have only one vertex in common!) or make sure that all copies of a vertex have the same color.

Additionally, you should NOT have any T-vertices in your mesh. In your example, there could be such a T-vertex linking those two dark triangles. However, if this vertex is not shared by the "bottom" face, color interpolation is likely to produce those apparent edges.

##### Share on other sites
Quote:
 Original post by Lord_EvilDo you need distinct normals for each face? If so, I guess you don't share vertices between faces but have copies with different normals. Did you check that all copies of a vertex have the same color assigned? Additionally, if you use lighting with distinct normals per face you're likely to have those sharp edges (in fact that's what you normally want to achieve with distinct normals).You could try to share vertices between adjacent faces (even if they have only one vertex in common!) or make sure that all copies of a vertex have the same color.Additionally, you should NOT have any T-vertices in your mesh. In your example, there could be such a T-vertex linking those two dark triangles. However, if this vertex is not shared by the "bottom" face, color interpolation is likely to produce those apparent edges.

Each face has exactly same vertex because I used vertex index for each face.

And.. I don't use lighting (glDisable( GL_LIGHTING )), so, I didn't care about the normals. But even though I tried turn lighting on, and give the vertex normals for each vertex, edges are still appeared. This edge is appeared not only in T-vertex.

ps. I used...
glDisable( GL_LIGHTING );
glEnable( GL_COLOR_MATERIAL );

##### Share on other sites
Well then, could you post your rendering code so that we could have a deeper look?

##### Share on other sites
code is.... quite.......;;

il4Mesh *mesh = NULL;unsigned int num;for( unsigned int i = 0; i < obj->g_dwNumMesh; i++ ){	mesh = obj->g_pMesh;	for( unsigned int j = 0; j < mesh->dwNumFaces; j++ )	{	glBegin( GL_TRIANGLES );		num = mesh->GetVertexIndexNumber( j, 0 );		glColor3fv( pVertexColorOfMesh[num].elements );		glNormal3fv( mesh->GetVertexNormal( num ).elements );		glVertex3f( mesh->pvVertex[num].x, mesh->pvVertex[num].y, mesh->pvVertex[num].z );		num = mesh->GetVertexIndexNumber( j, 1 );		glColor3fv( pVertexColorOfMesh[num].elements );		glNormal3fv( mesh->GetVertexNormal( num ).elements );		glVertex3f( mesh->pvVertex[num].x, mesh->pvVertex[num].y, mesh->pvVertex[num].z );		num = mesh->GetVertexIndexNumber( j, 2 );		glColor3fv( pVertexColorOfMesh[num].elements );		glNormal3fv( mesh->GetVertexNormal( num ).elements );		glVertex3f( mesh->pvVertex[num].x, mesh->pvVertex[num].y, mesh->pvVertex[num].z );	glEnd();	}}

I've replaced the model.
But, in common, these edges are apeeared around the vertex that shares many faces.

##### Share on other sites
I can't see any error in your code although IMO you should move the colors to the mesh, too (thus resulting in mesh->getColorOfVertex( num ) calls).

Since you say those edges appear around vertices that are shared by many vertices I would still say there's something wrong with your indices. Maybe for some reasons the vertices are still copied. Could you check if all faces sharing a vertex where the edge appears are using the same index?

##### Share on other sites
Your pVertexColorOfMesh array contains one colour for each vertex: the only way to get these inconsistencies is to reference different vertices from different mesh triangles when you should be referencing the same one.
Instead of the obviously guiltless drawing code, you should post the part that builds the mesh data structure incorrectly.

##### Share on other sites
I found that two adjacent faces sharing the edge, do not share two vertices, share only one vertex.

I don't understand why this is happened. In 3ds MAX, it is all connected well.
When the edge of two adjacent faces is moved, polygon is modified as expected. There are no several vertex at one point.

Anyone know why this is happened? I exported to 3ds file in 3ds MAX.

##### Share on other sites
If you have different smoothing groups in 3ds max they will certainly cause the vertices to be duplicated. Depends on the exporter. I wrote my own exporter and had to account for that fact, so whenever two faces share a vertex but don't share at least one smoothing group, the vertex should be duplicated. I guess the 3ds exporter does something similar.

##### Share on other sites
I didn't care about the smoothing group, so far..
I'm not good at 3ds max. I just needed 3d model for radiosity.

Anyway, there is another problem which is related with this.
I just built another 3d model, room.
In this model, there are many T-vertices. So, when I render this model in my program, not show vertex color, but only face color, the edge of all T-vertices are appeared.

I think calculating normal vector causes this problem.
For each vertex, I summed up normals of all the adjacent faces, and normalize it. It becomes vector normal. In smooth surface, it works well. But in T-vertex, edges are appeared.

Must I duplicate vertices in Max? or in my program?
Is it better that I build the own exporter?

I unfamiliar with smoothing group, I searched internet...
So, I know just what it is.. but, how can I solve this problem about smoothing group.

• 17
• 11
• 12
• 9
• 49
• ### Forum Statistics

• Total Topics
631395
• Total Posts
2999758
×