I was wondering if anyone could give me a little advice regarding this rendering issue of mine.
As you can observe in the first picture, I have a cliffside built from tiles. The game’s (pseudo)isometric so the camera rotates roughly around the center of the screen. That means the camera can get itself behind the cliff (refer to picture no.2). The cliff backfaces are culled via shader and this gives almost desired behavior, with the exception of some front faces appearing because of the mesh shape.
Is there any way to tell Unity to cull off the front faces when looking through the same mesh back faces? I tried to tinker with URP renderer features material and depth overrides in srp renderer settings with no luck.
Is this achievable via custom shader? Any idea would be greatly appreciated.
I’m not sure there’d be any simple way to do that, especially in URP. But the approach most games take to this is to simply use a collider or raycast that prevents the camera from actually being inside geometry like this. Or, if the geometry does obstruct the camera, they fade out the material on that object. Both are things you could easily do in URP.
Another option if you don’t want to fade out the whole object would be to use the raycast to determine if your camera is inside a piece of geometry, and then have a shader keyword you can enable that switches the shader to a version that checks the distance of the fragment from the _WorldSpaceCameraPos and culls it if it’s further than a desired value.
Thank you for your response. The fact that camera clips through the cliff geometry is actually a valid behavior, we don’t want to restrict camera rotations.
The reason is that the buildings you can see in the pictures have interiors and once your character enters one, its roof will disappear and walls turn semi-transparent for better view. To ensure there is no obscuring in more complex interiors, we need the camera to be rotatable all the way around. So if the player should find it hard to see certain interior parts, they can simply rotate to different angle.
That’s why it is valid to have cliffs culled from the back, as it doesn’t add yet another level of possible obscuring.
In fact, I created a shader via shader graph to render backfaces in solid black, which looked alright (since the camera is being cleared with solid black too) but I personally felt it’s heavily obscuring the level.