Wireframe shader
A wireframe shader using barycentric coordinates from this article and this gist.
I extended it with more functions such as:
- A wonky width parameter
- Opacity for the model depending on if you want the wireframe only
- Coloring of both the model and the wireframe
Shader code
shader_type spatial;
render_mode unshaded;
uniform vec4 modelColor : source_color;
uniform vec4 wireframeColor : source_color;
uniform float width : hint_range(0.0, 15.) = 1.;
uniform float modelOpacity : hint_range(0.0, 1.0) = 1.;
uniform bool filtered = false;
const vec3 vectors[3] = {
vec3(1.0, 0.0 ,0.0),
vec3(0.0, 1.0 ,0.0),
vec3(0.0, 0.0 ,1.0)
};
varying vec3 baryCoord;
void vertex()
{
baryCoord = vectors[VERTEX_ID % 3];
}
void fragment() {
vec3 dBaryCoordX = dFdx(baryCoord);
vec3 dBaryCoordY = dFdy(baryCoord);
vec3 dBaryCoord = sqrt(dBaryCoordX*dBaryCoordX + dBaryCoordY*dBaryCoordY);
vec3 remap = smoothstep(
vec3(0.0),
dBaryCoord * width,
baryCoord
);
remap = filtered ? remap : step(.5, remap);
float closestEdge = min(min(remap.x, remap.y), remap.z);
ALBEDO = mix(wireframeColor, modelColor, closestEdge).xyz;
ALPHA = mix(1., modelOpacity, closestEdge);
}




It seems to work only for meshes created in godot but not with those imported from blender (in any format). Do you know why could it be?
I changed the render mode to
render_mode wireframe, unshaded;
and it gave me the result I’ve been looking for.
Wireframe render_mode doesnt work with gl_compatibility renderer sadly…
The wireframe render mode will work in Compatibility if you call
RenderingServer.<span style="color: rgb(206, 145, 120);">set_debug_generate_wireframes(true)before loading any meshes. You can put it in an autoload’s_init()function to achieve this.If the shader works weirdly try exporting the model with the .obj format in Blender, then go to Godot and use a CSGMesh3D node and put that model .obj in the “Mesh” property and place the shader in “Material” or wherever it allows you. It worked for me
It seems to be confused by concave meshes 🙁