Topic: X-Ray, Z-order, draw 3d objects order

I think there is a specific term for this, but it doesn't come to mind.
By the way I want to render a 3D object before everything else even if it's far from the camera, so I can e.g. show what's behind a wall.

EDIT: thread title edited

Last edited by 255 (2013-10-23 08:22:20)

Re: X-Ray, Z-order, draw 3d objects order

255 wrote:

I think there is a specific term for this, but it doesn't come to mind.
By the way I want to render a 3D object before everything else even if it's far from the camera, so I can e.g. show what's behind a wall.

The first phrase that came to mind was "Clipping Plane"
The 2nd word that came to mind was "Draw Distance."

I think the 2nd one is the term.

Edit: Seems like both of those terms are good ones to research. They seem to work sorta the same. You could use one or both techniques. The term "Clipping Path" came up while researching Clipping Plane.

Last edited by Tutorial Doctor (2013-10-23 03:39:27)

Re: X-Ray, Z-order, draw 3d objects order

The clipping plane is how much far and how much close objects can be drawn.
The draw distance it's the quality of the distant objects (e.g. viewing a big city from a very distant position and you see good skyscreapers; this relates to LOD).
So both terms don't relate to what I'm asking; "z-order" sounds more correct in this case, even if it's generally used in 2d.

Re: X-Ray, Z-order, draw 3d objects order

do you mean the general painter's algorithm ? (was used for real time software 3d before the z buffer technique)

or do you just want to do a special effect ?

in Maratis the rendering order is managed by MRenderer (here fixedRenderer or standardRenderer),
in the standardRenderer it happen globally like that :

- get the list of objects visible in the camera view
- render all non-transparent sub-meshs from near to far in depth-test only (early Z test) and build occlusion culling
- render occlusion-culled non-transparent sub-meshs in random order
- render transparent sub-meshs in far to near order

It's a bit different in the iOS renderer for example (no early z test because iphone and iPad 3d card uses tiled rendering).

To sort objects you can use MCore's "sortFloatList(int indexList[], float floatList[], int start, int end)"

But all depends on what you want to achieve.

Re: X-Ray, Z-order, draw 3d objects order

anael wrote:

To sort objects you can use MCore's "sortFloatList(int indexList[], float floatList[], int start, int end)"

Thank you it may be that one, I'll try soon.

But all depends on what you want to achieve.

x-ray! How could it not came to my mind! That's the word. So e.g. in a futuristic game you see behind a wall a 3d object that you couldn't see because the wall is rendered after it. I'll add the term in the thread title.
It's even used in Blender for the armature.

Last edited by 255 (2013-10-23 08:22:45)

Re: X-Ray, Z-order, draw 3d objects order

x-ray, ok, so what I say previously is not totally related.

there is multiple ways to do it,

I think the simpler way would be to create a second scene where you put only the objects you want to draw in xray.
Use a clone of the main scene camera to syncronise the perspective and render this scene on top of the main scene as a camera-layer : http://wiki.maratis3d.org/index.php?tit … ameraLayer

Another way would be to do that by hand in MGame::draw,
after the scene draw, you disable the depth test with MRenderingContext and you render the x-ray objects after.

Re: X-Ray, Z-order, draw 3d objects order

The first solution is maybe not so good in performances? And anyway having two scenes and two cameras and one camera should copy the movements of the other camera, and same for the entity, I don't like it much. But the second solution doesn't seem much doable because I would need to access private methods of MRenderer.
My code is as follows:

//custom draw
void MyGame::draw(void)
{
    MGame::draw();

    MRenderingContext* rendering = engine->getRenderingContext();
    rendering->disableDepthTest();
    MRenderer * renderer = engine->getRenderer();

    MOEntity * entity = myEntity;
    MMesh * mesh = entity->getMesh();
    MSubMesh* smeshs = mesh->getSubMeshs();
    MVector3* vertices = smeshs[0].getVertices();
    MVector3* normals = smeshs[0].getNormals();
    MVector3 * tangents = ?
    MColor * colors = ?
    renderer->drawDisplay(smeshs[0],smesh[0].getDisplay(0),vertices,normals,tangents,colors); //not accessible

I could only do ->drawScene but that will be pointless unless I have another scene which bring us in the first solution again.
Hrm.. I need some renderer->drawEntity() method lol.

Re: X-Ray, Z-order, draw 3d objects order

the first method is not necessarily slow as you can either deactivate the x-ray objects in the main scene when they are in x-ray, or have the x-ray objects only in the secondary scene from the beginning (if they are always seen in x-ray).

Other solution is to add an option in MMaterial to ignore depth-test so the object won't be affected by the z-buffer,
but your material should use an additive blending mode to avoid self intersection issues (additive blending can be render in any order).

Re: X-Ray, Z-order, draw 3d objects order

So I could use the first solution and maybe post a feature request for this last idea?
X-Ray is used a lot in games anyway.

Re: X-Ray, Z-order, draw 3d objects order

actually I taught about something even simpler :

void MyGame::draw(void)
{
    // here make all x-ray objects invisible
    ...

    // draw the scene without x-ray objects
    MGame::draw();

    // clear depth buffer
    render->clear(M_BUFFER_DEPTH);

    // here make all x-ray objects visible, and others invisible
    ...

    // draw x-ray objects only
    scene->draw(camera); // [EDIT]
}

11

Re: X-Ray, Z-order, draw 3d objects order

Ahah that's smart, gonna try it soon.

12

Re: X-Ray, Z-order, draw 3d objects order

Yeah, it works; we were overcomplicating things eheh.
BTW doing

MGame::draw();

seems to erase the first draw (so you see only the x-ray object).
So the correct way to go is

engine->getRenderer()->drawScene(scene,camera);

or

scene->draw(camera);

Re: X-Ray, Z-order, draw 3d objects order

yes sorry, you are right, because MGame::draw(); call a clear.