Per object outline shader / viewport troubles

Godot Version

4.3

Question

I’m trying to have an outline shader that only highlights certain objects. Aiming for a stylistic thing what older animation did where only moving stuff had a border and everything else was painted background. That is why doing the advanced post processing quad child of camera isn’t what I want. I checked the shaders site and there are material shaders that almost but didn’t quite work (see bottom of post). So I’m currently messing with viewports. I think I get why it doesn’t work, but don’t know the solution.

Current setup is this. Everything is in the viewport, things that want to be outlined are on cull layer 1 and 2. The Outline camera sees only cull layer 2. The textureRect is a viewport texture with a canvasItem outline shader.

This almost works but the outlines render over everything. Which makes sense, it’s being rendered after the viewport. So the solution I would think is have an exact copy of everything so that the outer camera can see and cull that. Problem is that it would be an organizational mess in an actual level, so I feel like there’s a better way.

Is there a way to do this cleanly and well organized? Alernatively, does anyone have a material shader that can do an outline on lowpoly meshes? The one I found Pixel Perfect outline Shader - Godot Shaders needs smooth normals which I don’t want on some of my meshes.

Have you seen Godot 4.3 compositor?

With the help of a friend landed on an answer. I was close just had everything backwards.

WorkingOutlinesNodes

For future people to reference the setup is as follows. Outliner (the camera in the subviewport) only sees cull layer 2. The outer camera (has the RemoteTransform on it) can see everything. All rendered meshes are on layers 1 and 2. The ones that you want to have an outline have this as its next pass

shader_type spatial;

void fragment() {
	if( (CAMERA_VISIBLE_LAYERS & 1u) == 1u ) {
		ALPHA = 0.0;
	}
	if( (CAMERA_VISIBLE_LAYERS & 2u) == 2u ) {
		ALBEDO = vec3(10.0, 0., 0.);
	}
}

Yes it’s kinda brute force but it does work.

The TextureRect that has the viewport texture has a canvasitem outline shader. The simplest outline shader (canvas_item) - Godot Shaders or similar should do.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.