How would I make a mask material in the Game Engine?

Im making a desk with drawers, and the entire game is in wireframe (Wireframe materials) I have a cube in one of the drawers. Im trying to hide the cube, but since the wireframe is transparent, it shows the cube. I’ve tried using the mask transparency option, but it doesn’t mask the cube. Please help.

Either look into using occluders or set visibility of the cube to false when the drawer is closed.

What are occluders? Sorry, I don’t know all of the terms.

Also, these are the drawers, if that helps.

can you even do wireframe in bge?

Yes, If you either render in wireframe or change the materials to Wire instead of Surface.

Where are the occluders?

i would say its time to re eval what you want. maybe just make the materials shadless and manually add wire?

I probably could, I think I even tried that before, but I inset faces, and that would take forever. Plus, the Wireframe Materials show the Wire part right on the edges, whereas Insetting the faces wouldn’t. I don’t know entirely. I still feel that currently, a Mask would be the best option. My question is how would I make the mask?

Basis: occluder objects hide anything caught between them and camera. Think, a screen that forces anything behind it to be invisible (not rendered, rather).

To make an object an occluder: Properties->Physics->Pick “Occluder” from physics type dropdown.
I believe the Blender manual goes into more detail.

1 Like

Ah yes, I found that before, and I added it to the drawer, but it still didn’t hide the cube that was in said drawer.

Either the occluder is too small or occlusion culling is not checked in scene physics.
You can always have python do cube.visible = False if drawer is closed.

1 Like

You could duplicate your mesh, but set material of the copy to a shadeless surface instead of wire. This will hide your object but keep your outlines.

just a side note, the occluders only work if they are visible.

use a node material, and use geometry - object position - find the objects X position, or Y position (which way does the drawer move?) and use a math node to have the object alpha depend on it’s X position,
(if it moves when the drawer slides open -> it becomes visible)

node material

geometry-position-seperateRGB - Math node(offset) ->math node(greater than) -> alpha

if you need to use many of these, use object color[R] to store the offset value per object.

This sort of works, but I think now there’s the problem of Z-Fighting:

@Fox_GAMING_NTF:

I confirm z-Fighting on a small example and found a little workaround. If you delete all faces of the duplicate, leave only the lines and then extrude and fatten by a little amount like 0.001, you can get rid of z-fighting. Comparison in *.blend below.

2019_06_16_BGE_Material_w_wireframe.blend (713.5 KB)