Page 1 of 1

Seams where objects meet

Posted: Mon Jul 28, 2014 1:14 pm
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

Re: Seams where objects meet

Posted: Mon Jul 28, 2014 2:04 pm
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 :).

Re: Seams where objects meet

Posted: Mon Jul 28, 2014 9:22 pm
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...

Re: Seams where objects meet

Posted: Tue Jul 29, 2014 7:09 am
by hendu
That's called Z-fighting. Don't draw two surfaces a the exact same position.

Re: Seams where objects meet

Posted: Tue Jul 29, 2014 8:30 am
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)); 
    }

Re: Seams where objects meet

Posted: Tue Jul 29, 2014 8:37 am
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.

Re: Seams where objects meet

Posted: Tue Jul 29, 2014 9:26 am
by Gnasty Gnork
Er.. there are no pillars in this. I dont know what you mean by pillar

Re: Seams where objects meet

Posted: Tue Jul 29, 2014 6:38 pm
by hendu
Image

Re: Seams where objects meet

Posted: Tue Jul 29, 2014 8:19 pm
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

Re: Seams where objects meet

Posted: Thu Jul 31, 2014 10:20 pm
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

Re: Seams where objects meet

Posted: Fri Aug 01, 2014 12:04 pm
by kklouzal
Just a thought, but these 'seams' your seeing is probably how light is casting onto the objects.

Re: Seams where objects meet

Posted: Sat Aug 02, 2014 2:00 am
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.

Re: Seams where objects meet

Posted: Sat Aug 02, 2014 12:15 pm
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)

Re: Seams where objects meet

Posted: Sat Aug 02, 2014 1:59 pm
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.