This is a shader that will add outlines to your scene. It will work in Godot 4.0 and higher. Since it requires access to the viewport normal buffer, it also requires Forward+ mode to work.
Copy the res://shaders/edge_detector_sobel.gdshader shader into your project. Then add a MeshInstance3D to your scene and add a QuadMesh mesh to it.
Then open the GeometryInstance3D/Geometry subsection and add a new ShaderMaterial. Finally, click the Shader dropdown and QuickLoad the edge_detector_sobel.gdshader.
When you first set up your shader, the defaults will have it displaying as a sort of 'magic window' that adds outlines to everything when you look through it. You can use it this way if this is the effect you want, and even apply this shader to any 'window' you want to have this outline effect.
If you want to use it as an overlay instead, click the Map Quad to Viewport option. This is meant to work with Godot's default QuadMesh and will alter its vertices to fill the viewport. If you do this, also make sure to set the MeshIntance3D's Custom AABB to something that will enclose the entire scene area - otherwise the shader will automatically turn off whenever the quad mesh goes outside of the range of the camera. Also set the Render Priority to a value higher than any other mesh in your scene to make sure it runs after everything else has drawn.
The shader works by creating a Sobel matrix to detect changes in the depth and normal images generated by the final scene. The bigger the difference, the more pronounced the genetated line is.
- Line Color - Color of line
- Background Color - Color for spaces between lines
- Detect Type
- Combined - Use both depth and normal differences to determine outline
- Normal Only - Only use normal differences to determine outline
- Depth Only - Only use depth differences to determine outline
- Map Quad to Viewport - Meant to work with the default QuadMesh; ie, a 1x1 square mesh. When checked, this quad will be automatically transfomred to cover the viewport. The quad mesh must still be within the viewport clipping area.
- Kernel Radius - Maximum width of the outline.
- Normal Cutoff - How big the change in the normal map needs to be to generate a line.
- Normal Cutoff Radius - How sharp to make the normal cutoff.
- Depth Cutoff - How big the change in the depth map needs to be to generate a line.
- Depth Cutoff Radius - How sharp to make the depth cutoff.







