Seams where objects meet

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Evanias
Posts: 6
Joined: Thu Jul 03, 2014 10:30 pm

Seams where objects meet

Post by Evanias »

Hello,
I am working on a project where i'm trying to make a world out of cubes. I have the cubes spawned in with collision working fine, but where the edges of the cubes meet, no matter if they are barely touching, overlapping, or at the exact distance, there are still these ugly lines where they meet. Can somebody help me figure out how to make the lines go away? Oh, and these are simple 3d models of cubes, not cube scene nodes. I couldn't figure out how to texture individual sides of cube scene nodes, so I am using models of cubes. This issue of lines does not occur with cube scene nodes, so if anybody knows how to texture sides of a cubescenenode, I would also take that as an answer. If you need a pic, i can take one, just post if you need one.

Thanks in advance
-Evanias
Professional Timelord
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Seams where objects meet

Post by thanhle »

I saw there used to be a few similar questions about the same problem. You might want to search the forum.
Maybe also shows picture about the problem. It is a bit long to read a long paragraph :).
Gnasty Gnork
Posts: 18
Joined: Fri Jun 20, 2014 12:12 pm

Re: Seams where objects meet

Post by Gnasty Gnork »

Image

I believe this is what he means, it is happening to me too right now and i also have no clue what is this caused by...

Oh and i am using a custom scene node (drawing the cube using vertex and indices) btw...

The lines are relative to the camera position, if i move around the camera i can even get to see no lines at all...
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Seams where objects meet

Post by hendu »

That's called Z-fighting. Don't draw two surfaces a the exact same position.
Gnasty Gnork
Posts: 18
Joined: Fri Jun 20, 2014 12:12 pm

Re: Seams where objects meet

Post by Gnasty Gnork »

hendu wrote:That's called Z-fighting. Don't draw two surfaces a the exact same position.
Could you be more specific?

This is the method i use to draw:

Code: Select all

  
    Vertices[0] = S3DVertex(0,0,0, -1,-1,-1, color, 0, 1);
    Vertices[1] = S3DVertex(10,0,0, 1,-1,-1, color, 1, 1);
    Vertices[2] = S3DVertex(10,10,0, 1,1,-1, color, 1, 0);
    Vertices[3] = S3DVertex(0,10,0, -1,1,-1, color, 0, 0);
    Vertices[4] = S3DVertex(10,0,10, -1,1,-1, color, 0, 1);
    Vertices[5] = S3DVertex(10,10,10, 1,1,1, color, 0, 0);
    Vertices[6] = S3DVertex(0,10,10, -1,1,1, color, 1, 0);
    Vertices[7] = S3DVertex(0,0,10, -1,-1,1, color, 1, 1);
    Vertices[8] = S3DVertex(0,10,10, -1,1,1, color, 0, 1);
    Vertices[9] = S3DVertex(0,10,0, -1,1,-1, color, 1, 1);
    Vertices[10] = S3DVertex(10,0,10, 1,-1,1, color, 1, 0);
    Vertices[11] = S3DVertex(10,0,0, 1,-1,-1, color, 0, 0);
And this is how i index the vertices:

Code: Select all

u16 indices[36] = {0,2,1,   0,3,2,   1,5,4,   1,2,5,   4,6,7,   4,5,6,   7,3,0,   7,6,3,   9,5,2,   9,8,5,   0,11,10,   0,10,7  };
You mean i should use less than 12 vertices?

Or do you mean there is a problem with how i position the cubes? (maybe they overlap?) i dont think so, here is how i position them:

Code: Select all

for (int i = 1; i<300; i++)
    {
        cube[i] = new Cube(smgr->getRootSceneNode(),smgr,0,0,50);
        cube[i]->setPosition(cube[i-1]->getPosition() + vector3df(10,0,0)); 
    }
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Seams where objects meet

Post by hendu »

Nothing to do with your cube but your pillar.

Image

Your pillar's frontside is in the same space as the cube's frontside. So of course they conflict.
Gnasty Gnork
Posts: 18
Joined: Fri Jun 20, 2014 12:12 pm

Re: Seams where objects meet

Post by Gnasty Gnork »

Er.. there are no pillars in this. I dont know what you mean by pillar
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Seams where objects meet

Post by hendu »

Image
Gnasty Gnork
Posts: 18
Joined: Fri Jun 20, 2014 12:12 pm

Re: Seams where objects meet

Post by Gnasty Gnork »

I did not code anything to show a pillar. There are supposed to be only cubes, what you highlighted on that pic is a glitch that i am trying to get rid of.

Perhaps im a complete dumb and you are telling me something that i dont get. :D
Gnasty Gnork
Posts: 18
Joined: Fri Jun 20, 2014 12:12 pm

Re: Seams where objects meet

Post by Gnasty Gnork »

Using

Code: Select all

driver->drawIndexedTriangleList(&Vertices[0], 12, &indices[0], 12);
instead of

Code: Select all

driver->drawVertexPrimitiveList(&Vertices[0], 12, &indices[0], 36, EVT_STANDARD, EPT_TRIANGLES, EIT_16BIT);
the cube has no glitches.

Weird thing is that if i draw the cube using buffer it looks ok with drawVertexPrimitiveList()...
I dont know what i am doing wrong, i even tried to use only 8 vertices (instead of 12) but the glitch is still there.

Image


Problem solved i guess but still.. i would know what was wrong. xD
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Re: Seams where objects meet

Post by kklouzal »

Just a thought, but these 'seams' your seeing is probably how light is casting onto the objects.
Dream Big Or Go Home.
Help Me Help You.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Seams where objects meet

Post by mongoose7 »

Looking at the code,

Code: Select all

driver->drawIndexedTriangleList(&Vertices[0], 12, &indices[0], 12);
does not convert to

Code: Select all

driver->drawVertexPrimitiveList(&Vertices[0], 12, &indices[0], 36, EVT_STANDARD, EPT_TRIANGLES, EIT_16BIT);
It converts to

Code: Select all

driver->drawVertexPrimitiveList(&Vertices[0], 12, &indices[0], 12, EVT_STANDARD, EPT_TRIANGLES, EIT_16BIT);
Also, the second '12' is not the count of vertices, but the count of triangles. I don't know how the vertices are used to create the triangles but mathematics tells me that it must always be less than 12.
Gnasty Gnork
Posts: 18
Joined: Fri Jun 20, 2014 12:12 pm

Re: Seams where objects meet

Post by Gnasty Gnork »

Yeah that was the error, i put the lenght of the indices array (36) but all that parameter asks for is the number of primitives (12). I knew it was an error on my part but i was sure that line was ok. (because im bad)

Thank you very much mongoose!

Btw The triangles need to be 12, you count 2 per face right? A cube has 6 faces so 6*2 = 12 :)

EDIT: oh nvm you were talking about vertices. Yeah i could draw it using 8 vertices but there something i didnt quite understand about texturing (it needs 12 vertex to be textured correctly)
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Seams where objects meet

Post by mongoose7 »

I may have got ahead of myself. Yes, there are 12 triangles. I suppose you could use 12 vertices but with lighting you need 24 for the normals.
Post Reply