The built in stencil outline uses mesh displacement along the normal to render the outline shell. If mesh normals are not smoothed, there will be gaps, so this method requires a smoothed mesh. But that displacement per se has nothing to do with stenciling. Technically, those are two separate things. For your type of mesh the built in stencil method that uses displaced shell might not be ideal.
You’re using a whole screen post-processing shader. How do you plan to exclude the objects that are not supposed to be outlined?
I’ve just been running simple tests to see how each shader works (still learning!)
My tests were on simple objects - just a capsule and a cube intersecting.
What I’m looking for is an outline shader, per object (or group) as I showed in my OP.
They all behave individually.
I read through the shader and even though it uses some screen parameters, I don’t think it affects the entire screen and everything in view.
Well if you apply it on objects it becomes more of an “inline” shader then. That’s why you see it on all meshes of your multi-part object - it renders inside object silhouette instead of outside (the latter you probably expected).
To render an outside silhouette you need a post processing shader. Render all objects that form the silhouette you want outlined into a transparent subviewport that has the same proportion as your main viewport. Run a full screen post processing shader that samples that viewport using gaussian sample distribution. Threshold the result, subtract the original silhouette and superimpose over the main viewport.
This should give you a stable uniform outline around the joined silhouette of all objects that are rendered into the subviewport.
Set viewport camera’s cull mask to a single specific layer and add all objects that constitute the silhouette to that visual instance layer. Other objects should not be on that layer.
Enable transparent background for the viewport.
Put a full-screen plane in front of the camera and run this post processing shader on it. Plug the viewport texture into the shader:
Sorry I took so long to reply after your very fast response to me.
I’ve followed your directions (accurately I thought) but not getting the same results - so I’m certain I’m doing something wrong.
I copied your code directly from your post and everything is running without errors or warnings.
(FYI I’m using Godot v4.62 and tested 4.7 - same results)
Here’s screenshots for what I’ve set up and what I see: