0 votes

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 canvasitem 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 DEPTHTEXTURE. 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.

in Engine by (26 points)

1 Answer

0 votes
Best answer

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() {
    if (FRONT_FACING) {
        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!

by (26 points)
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.