Fragment shader inside space

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cj

How do I determine which face is an interior face and make these unshaded?

I am looking to hide the inside of meshes. So for example, if I have a scene like this:

A scene with an exposed interior

I would want to hide that interior to the right, like this:

A scene with a hidden interior

My first thought was to try a ColorRect with a canvas_item shader, but I couldn’t think of a way to access depth information. So then I tried making a spatial shader to use for every mesh, which gave me access to the DEPTH_TEXTURE. When I applied that directly to the ALBEDO, it looked promising, but it stopped when it was clipping with the camera. So now my thought is to disable culling and render these previously culled surfaces differently.

Sorry if my question is relatively basic, I’m not that experienced with shaders in general. Any help is greatly appreciated, even a different approach entirely.

:bust_in_silhouette: Reply From: cj

I managed to figure it out. It was much easier then expected! Completely missed FRONT_FACE which told me exactly which face was outside or inside.

shader_type spatial;
render_mode unshaded, blend_mul, cull_front;

void fragment() {
		ALBEDO = vec3(1.0);
	} else {
		ALBEDO = vec3(0.0);

I could then assign the outside white and the inside black, then blend it together by multiplying.

enter image description here

It’s not perfect, it does mean I need to model faces away from the player and avoid clipping. But I feel like that is a fine compromise!