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;
}
Live Preview
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

Related shaders

Comments 9

  1. gyrosp

    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

    2
    1. 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.

      1
  2. 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

    2
    1. LyDek

      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

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

    0
  4. Can someone post a working GODOT 4 example of this?

    0
    1. /*
      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;
      }

      0
  5. I updated this to Godot 4.x:

    shader_type spatial;
    render_mode cull_front, unshaded;
    
    
    uniform sampler2D outline_noise_tex;
    uniform vec4 outline_color : source_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;
    }
    
    0