Today and yesterday I was having trouble understanding why my faces are culled with backface culling enabled in opengl.
I can't figure out how the winding works ( I thought I knew before )
Does it matter how vertices are arranged in array?
Or does only indices matter when winding a mesh? If so that would mean that no matter how vertices are arranged in array as long as indices point to same vertices the winding wouldn't differ?
Mesh face winding
Mesh face winding
Working on game: Marrbles (Currently stopped).
Re: Mesh face winding
Vertex order shouldn't matter as only the indices describe the order. That's unless you work without indices in which case I think some defaults are used and then vertex order would matter.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Mesh face winding
The indices matters. They describe the order of the sides of a triangle and thus its winding. The only way to make sure that nothing is hidden wrong is to disable the backface culling.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: Mesh face winding
CuteAlien wrote:Vertex order shouldn't matter as only the indices describe the order. That's unless you work without indices in which case I think some defaults are used and then vertex order would matter.
I see, so I knew it correctly from the beginningMel wrote:The indices matters. They describe the order of the sides of a triangle and thus its winding.
Then it must be something wrong with indices.
the thing is that front faces get culled and back faces don't with backface culling.Mel wrote:The only way to make sure that nothing is hidden wrong is to disable the backface culling.
If I wind them CW I get normal results, but I my front faces are set to CCW.
Here's how I wind the cube:
Faces:
Code: Select all
faceIndices
({
{7,6,5,4},///top
{4,5,1,0},///front
{5,6,2,1},///right
{6,7,3,2},///back
{7,4,0,3},///left
{0,1,2,3} ///bottom
})
Code: Select all
faceWindingMain({0,3,1,1,3,2})
Code: Select all
for(boost::uint32_t i = 0; i < 6; i++)
{
const boost::uint8_t voffset = (i*4) + size;
const boost::uint8_t ioffset = (i*6) + isize;
const boost::uint8_t * winding = /*invertFaceWinding(this->p_nodeVerts, (ECubeFace)i) ? faceWindingInverse :*/ faceWindingMain ;
vertices[0 + voffset] = (Vertex3d(this->p_nodeVerts[faceIndices[i][0]], p_quadTexCoords[0]));
vertices[1 + voffset] = (Vertex3d(this->p_nodeVerts[faceIndices[i][1]], p_quadTexCoords[1]));
vertices[2 + voffset] = (Vertex3d(this->p_nodeVerts[faceIndices[i][2]], p_quadTexCoords[2]));
vertices[3 + voffset] = (Vertex3d(this->p_nodeVerts[faceIndices[i][3]], p_quadTexCoords[3]));
indices[0 + ioffset] = (winding[0]+voffset);
indices[1 + ioffset] = (winding[1]+voffset);
indices[2 + ioffset] = (winding[2]+voffset);
indices[3 + ioffset] = (winding[3]+voffset);
indices[4 + ioffset] = (winding[4]+voffset);
indices[5 + ioffset] = (winding[5]+voffset);
}
I hope I've given enough information.
Working on game: Marrbles (Currently stopped).
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Re: Mesh face winding
You chose a hard one to imagine in the current place and orientation of the cube. But talking about the side facing us, the correct index order is 0,4,1,1,4,5. Irrlicht uses clock-wise winding, so drawing the triangles should go in that order when viweing the front-sides.
Re: Mesh face winding
That would be clock wise winding? I'm using CCW since that's default on opengl, I think.hybrid wrote:But talking about the side facing us, the correct index order is 0,4,1,1,4,5. Irrlicht uses clock-wise winding, so drawing the triangles should go in that order when viweing the front-sides.
P.S. I'm rendering this with my own opengl renderer.
Working on game: Marrbles (Currently stopped).
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Re: Mesh face winding
Ah, ok. OpenGL uses CCW, so counter-clock wise by default.
Re: Mesh face winding
Fixed it all.
Thanks for the help
Thanks for the help
Working on game: Marrbles (Currently stopped).