Make part of a mesh invisible to specific camera

Godot Version

v4.2.2.stable.mono.official [15073afe3]

Question

I’m trying to make a mirror, I managed to get a working script and shader and the effect is perfect but:
When I set my mirror against a wall, I need to make the wall invisible from the mirror camera.

I tried using visibility layers, but if I have more than one mirror, each mirror will need its own layer to ignore, or else the walls or object will also be invisible even in far away mirror, so that doesn’t work. (I’m already using a lot of the layers to manage other parts of my game, it’s for a puzzle game. Unless there is a way to generate temporary visibility layers at runtime? I don’t think that will work)

I tried using the near setting of the camera, but if I set near high enough to hide the wall, it also hide other parts of the level that should be visible. I tried making near dynamic and make it follow the player distance to the mirror, but then it becomes too small and parts of the walls are visible when the player turn their head to look at the mirror corners

I tried looking into shaders, apparently there is some sort of shader that can cutaway part of meshes? But I couldn’t find a tutorial that worked? (mostly those from someone named Pixezy on YT, I couldn’t get them to function. The scripting part just wouldn’t work)

I tried looking into some occlusion settings but apparently those hide whole objects not part of them?

I’m kinda not sure what else to look into? This is more of a general request for help, to put me on the right path to find a solution.
Thanks to anyone that would share something!

How is the mirror mesh/surface not being drawn by the mirror cam? I imagine it’s probably single sided? I would try and make the wall single sided too.

If those meshes to be a solid for other gameplay reasons, I would give every mirror a unique layer ID at least for the ones nearby that can ‘see’ each other, then on that mirror object, have a property for all of the meshes you want to not be visible to that mirror, then at the start of the level, toggle that mirrors layer ID off on all of the meshes in that array for that mirror.

Might be more flexible and easy to be able to just add meshes to the mirror properties and let some logic do the rest.

1 Like

The mirror itself is a single sided mesh yes, but yeah I had some figure case where I have two sided walls, so I made them two sided from the start… I suppose I could also rework my level design to work around the issue, that’s also an option.

I’ll try that solution with the attribution though, it sound workable as well, I’ll comment again if it works for me!

1 Like

I found a solution that work for me.
I discovered there is a parameter in Godot materials called “Distance fade”
In the case I have a solid 2 sided wall behind my mirror, I simply create a duplicate of that specific wall, and put it on a layer that’s only visible to mirror cameras, while the normal wall is on a layer only the player sees.

That duplicate has the same material as the normal wall, but with it’s fade distance parameter set up so that the camera will see through it.
The other mirror being far away, they won’t see the material as faded, only the one near the one.
And the player will see the normal version of the wall that the mirrors don’t see.

Thanks for the help anyway, you did set me on the right path with the idea that layers were the way to go!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.