Draw wireframe of covered mesh on top of covering mesh

I have two objects in my 3D scene where one object partially covers the other object. I want to draw the outline / wireframe of the covered object on top of the covering object to give the user a glimpse of the covered object. I am aiming for a similar effect as in the RTS Age of Empires 2, where units that are visually covered by walls are displayed as wireframes as seen in this screenshot:

I am not concerned about the wireframe drawing itself, but how to partially make it wireframe.

My concept to achieve this so far is:

  • Draw the covering object and draw it also to the stencil buffer.
  • Draw the covered object two times, both time with z-Test disabled.
    • One time with the regular material, everywhere it is not covered by the stencil
    • second time with the wireframe material, everywhere where it is covered by the stencil.


  • Is this the right approach?
  • Is there a standard way to draw a Mesh two times with different materials?
    • I think internally, the mesh has several hidden “second” materials, for example for edge rending, glow etc.

Otherwise, I have to clone the mesh or switch the material during rendering and I am afraid this is not a supported usecase.

Best regards,

I’m pretty sure this or similar to this has been discussed before in this forum. I also kind of remember that there must be at least a base around the use of a node material. Best I believe would be to ask (bother :grin:) our ultimate guru and expert (though I think he loves to deal with complex cases, don’t you? :joy:)
cc @PatrickRyan

@axeljaeger, I don’t know if there is a standard method of drawing the mesh twice as you are doing here since you are drawing the mesh, drawing other meshes that occlude it, and then going back to the original mesh and drawing it again with a different material.

I haven’t given much thought to this kind of technique in Babylon in the past, but I can certainly take a stab at how I would approach it. In the meantime, I would also ping @Evgeni_Popov in case he has any quick ideas about the process.

I think thist post may help: