+1 vote

I'm trying to create a see-through effect in 3D to display the player and their surroundings behind big obstacles like walls and such.

So far I've setup multiple Viewports rendering 3 different layers on top of each other:

  • Background: whatever isn't between the camera and the player.
  • Mask: the spatial objects containing the shapes that will mask the foregroung.
  • Foreground: obstacles between the camera and the player with an alpha mask applied.

It was extremely difficult to set this up, in contrast to another method using the Stencil Buffer, unfortunately not supported currently in Godot 3.2, but it works.

However, I just realized that I get no shadows from the obstacle itself when the mask is applied, since I use different layers for the background and the foreground objects.

My question is: Is there a way to do it currently in Godot 3.2? If not, will the use of Stencil Buffer solve it in Godot 4.0?

Update: I was able to get the shadows properly, nothing fancy, I just applied the mask properly over the foreground instead of redrawing the masked background. But now, the problem still remains as I'm not able to sort the rendering order of the obstacles when one of them is getting the mask applied to, and is behind another without the mask applied, like the image below:

Spatial see-through effect in Godot problem

Godot version 3.2.2
in Engine by (13 points)
edited by

However, I just realized that I get no shadows from the obstacle itself when the mask is applied, since I use different layers for the background and the foreground objects.

Did you try playing around with the light/shadow cull mask in the light nodes? Note that DirectionalLight cull mask doesn't work in GLES3 yet.

If not, will the use of Stencil Buffer solve it in Godot 4.0?

We don't know for certain whether Godot 4.0 will have stencil buffer support.

Yeah I considered using the Cull Mask, but in my case it wouldn't work since I use two different Render Layers to render each part of the scene. So what I end up with is the foreground (with the mask applied) only renders one of those two layers, so I get no shadow from the obstacles that were taken to another layer to be drawn separately.

I don't think I made it clear, but I get the shadows from the obstacle in their own layer, which is great. What I don't get shadows is when drawing the foreground mask above it, since it has no lighting info about the obstacle, which is in its own layer.

Unless I'm not aware of some lighting techniques, I don't think I can do it with just lighting.

Thanks for the reply though. And I'd also like to ask if this is a rare use case, since I couldn't really find any tutorials or questions about it, at least not with Godot.

I got the shadows working. But just like all of my approaches so far, it resulted in this other more complicated problem: sorting the rendering order of some obstacles over others. I edited the question explaining it better.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.