Item Highlighter

How to use:

 

Add shader to Next Pass in the Surface Material of the MeshInstance

 

In Godot 4:

 

Change  hint_color to source_color and CAMERA_MATRIX to INV_VIEW_MATRIX.

 

Shader code
shader_type spatial;
render_mode unshaded, depth_draw_never;

uniform vec4 shine_color : hint_color = vec4( 1.0, 1.0, 1.0, 1.0 );
uniform float cycle_interval : hint_range(0.5, 5.0) = 1.0;
uniform float shine_speed : hint_range(1.0, 5.0) = 3.0;
uniform float shine_width : hint_range(1.0, 100.0) = 3.0;

void fragment( )
{
	vec3 vertex = ( CAMERA_MATRIX * vec4( VERTEX, 1.0 ) ).xyz;
	float width = shine_width * 0.001 * cycle_interval;
	float frequency = floor( sin( vertex.z * cycle_interval + TIME * shine_speed * cycle_interval ) + width );
	ALBEDO = shine_color.rgb;
	ALPHA = clamp( ( 1.0 - dot( NORMAL, VIEW ) ) * frequency * shine_color.a, 0.0, 1.0 );
}
Live Preview
Tags
collectable, glint, highlight, item, shine
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.

Related shaders

Comments 11

  1. MikeCodev

    For it to work in Godot 4 you need to do two little adjustments:

    Change hint_color to source_color and CAMERA_MATRIX to VIEW_MATRIX

    shader_type spatial;
    render_mode unshaded, depth_draw_never;
    
    uniform vec4 shine_color : source_color = vec4( 1.0, 1.0, 1.0, 1.0 );
    uniform float cycle_interval : hint_range(0.5, 5.0) = 1.0;
    uniform float shine_speed : hint_range(1.0, 5.0) = 3.0;
    uniform float shine_width : hint_range(1.0, 100.0) = 3.0;
    
    void fragment( )
    {
        vec3 vertex = ( VIEW_MATRIX * vec4( VERTEX, 1.0 ) ).xyz;
        float width = shine_width * 0.001 * cycle_interval;
        float frequency = floor( sin( vertex.z * cycle_interval + TIME * shine_speed * cycle_interval ) + width );
        ALBEDO = shine_color.rgb;
        ALPHA = clamp( ( 1.0 - dot( NORMAL, VIEW ) ) * frequency * shine_color.a, 0.0, 1.0 );
    }
    
    15
  2. Is there a way to change the angle of the shine?

    0
  3. jasonheh

    I really like this effect, but because you use the view transform on the vertices, if you are rotating the camera while the effect is playing it has a strange behavior (very rapid oscillations). Changing it to just use VERTEX directly seems to work better for me.

    So you can just change the first line to:

    vec3 vertex = VERTEX.xyz;
    
    5
  4. FindersGrove

    How do we integrate this with the model's regular albedo texture? Also for some reason it needs another shader script to allow there to be a Next Pass slot so what do we do about that?

    0
  5. Just launched a game on Steam using this! Added you to the credits :) Thanks! https://store.steampowered.com/app/3765700/Clown_Camp/

    1