Animated sketchy line
A sketchy outline material for Godot Engine.
This is a multipass shader that works best with 2 passes: the one provided, and an additional one with cull_back and slightly different parameters. Please see the material configuration on itch.io
Warning: does not work well on hard surfaces and meshes with large flat areas.
Shader code
shader_type spatial;
render_mode cull_front, unshaded;
uniform sampler2D outline_noise_tex;
uniform vec4 outline_color:hint_color;
uniform float scissor_value = 0.5;
uniform vec2 uv_scale = vec2(1.0);
uniform sampler2D falloff_curve;
uniform float outline_size = 0.1;
uniform float offset_fres = 0.3;
uniform float fps = 5.0;
varying float h;
void vertex(){
VERTEX += NORMAL * outline_size * texture(outline_noise_tex, UV).r;
h = (WORLD_MATRIX * vec4(VERTEX, 1.0)).y;
}
void fragment(){
float fres = abs(dot(normalize(-NORMAL), normalize(VERTEX)));
vec3 nor = normalize(NORMAL);
float angle = atan(nor.y, nor.x);
angle /= 3.14;
float fres_remap = texture(falloff_curve, vec2(1.0 - fres)).r + offset_fres;
ALPHA = texture(outline_noise_tex, vec2(angle * uv_scale.x + SCREEN_UV.x, nor.z * uv_scale.y + floor(TIME * fps)/fps)).r * fres_remap;
ALBEDO = outline_color.rgb;
ALPHA_SCISSOR = scissor_value;
}
Hi, I’really like your shader :).
Will this also work on a 2D-Surface?
I tried to make it work but unfortunately without success.
What do you mean with cull_back?
I’m new to shader and godot.
Could you please provide a sample project?
Best regards
gyrosp
Hey gyrosp,
This will not work for a canvas item, because it uses the curvature of the surface to determine where to draw the outline and how to map it.
It could be possible to replicate using an additional edge texture and normal texture.
Hi,
I couldn’t manage to run this. I think it’s for Godot 3.x but not for 4.x Is that correct?
Thanks
to make it work with Godot 4, change “hint_color” into “source_color” at line 5, and “ALPHA_SCISSOR” into “ALPHA_SCISSOR_THRESHOLD” at line 29
and
MODEL_MATRIX to MODEL_MATRIX