I’m trying to create a decent camera experience when navigating tunnels and enclosed spaces. I’m using GridMap for the base level construction, since it makes level updates easy.
I learned not long ago about backface culling, which is perfect for making the back wall disappear when standing too close to a wall. In this case, I imported my tiles from Blender with backface culling baked in.
However, if the camera peeks outside of a corridor, then the player can see the rest of the dungeon from the outside.
My question is: is there any way to hide the rest of the dungeon, but not the faces of the room the character is in?
In this case, the player can see from outside the tunnel. But further ahead is a big room that stretches to the right, and the outside is occluded. What would be the best way to accomplish this?
Normally you’d keep the camera in bounds. That way it automatically can only see the interior.
Face culling is primarily a performance thing. It allows not to rasterize the triangles that are facing away from the camera and therefore contribute nothing to the picture. Some of the “outside” triangles will still face the camera, as you have discovered.
It is common to make the spaces bigger in videogames than they normally need to be, to have room for the character and the camera filming it.
Then, you are free to invent different approaches that suit your game. Model additional polygons outside the hallways to obscure the distant rooms from the camera, or limit the allowed camera angles for the narrow passages, for example.
That screenshot is from Rockman Dash (or Megaman Legends, depending on where you’re from). I’d guess what they did in that particular case was to build the world out of grid-square sized chunks, and choose whether to draw each chunk based on the camera location, the view frustum and grid adjacency to the character.
Backface culling is potentially part of the solution, but only part.
I ended up going the route of using external polygons to obscure faraway rooms. Not sure if it’s the best solution-- it feels clunky and haphazard. But so far, it does the job:
The black walls have backface culling but on the opposite side as the dungeon walls. They are also positioned so that the camera will never reach outside, otherwise it’d end up all black.
I’m placing the occlusion tiles in a separate Gridmap, which makes level design easier. On the other hand, it also makes it more complex to design a good level and requires better testing.
Jackpot! After doing a lot of playthrough analysis, it seems like they did use outside tiles to hide the farther walls. See my other answer.
In some gameplay videos, it shows a bit when going up slopes. Not sure if they used anything else, I’m barely two months into 3D to even understand if there is a shader or some other mechanism at play.
A shader knows if it’s drawing back or front face. If the face is front, render it normally, if it’s back, either render it black or discard the pixel if it’s close enough to the player, or explicitly set to not be visible for the whole object via a shader uniform.