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;
}
Tags
multipass, outline
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from QbieShay

Texture mix example

Particle Process V2

Spatial particle shader

Related shaders

Sketchy renderer with optional shadow and tinting.

Hex Line Shader

Make the Water Line Darker v1.0

Subscribe
Notify of
guest

8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
gyrosp
gyrosp
4 years ago

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

last_bender
last_bender
1 year ago

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

LyDek
LyDek
1 year ago
Reply to  last_bender

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

tvvr
tvvr
11 months ago
Reply to  LyDek

and MODEL_MATRIX to MODEL_MATRIX

Rex
Rex
6 months ago

Hey so on line 5 it says Expected valid type hint after

Dan
Dan
22 days ago

Can someone post a working GODOT 4 example of this?

Dan
Dan
11 days ago
Reply to  Dan

/*
Copyright 2021 Ilaria Cislaghi

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in the
Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

shader_type spatial;
render_mode cull_front, unshaded;

uniform sampler2D outline_noise_tex;
uniform vec4 outline_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 = (MODEL_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_THRESHOLD = scissor_value;
}