Gabor Patch
A Gabor patch is a sinusoidal wave multiplied by a gaussian function
[see https://en.wikipedia.org/wiki/Gabor_filter]
This shader replaces the existing texture with a Gabor patch, including animations for the phase and rotation of the waves in the patch
Available customisations:
- Phase offset
- Phase animation speed
- Rotation offset
- Rotation animation speed
- Wave frequency
- Patch scale (relative to whole UV map)
- Contrast (implemented as alpha)
- Patch colour 1
- Patch colour 2
Shader code
shader_type canvas_item;
// A Gabor patch is a sinusoidal wave multiplied by a gaussian function
// [see https://en.wikipedia.org/wiki/Gabor_filter]
//
// This shader replaces the existing texture with a Gabor patch, including animations for the phase
// and rotation of the waves in the patch
//
// Created by David Eccles (gringer) <bioinformatics@gringene.org>
/**
* Speed of wave movement [1.0 = one half cycle per second]
*/
uniform float speed_phase = 1.0;
/**
* Speed of patch rotation [1.0 = 45 degrees per second]
*/
uniform float speed_rotation = 1.0;
/**
* Initial wave offset [1.0 = one full wave offset (equivalent to 0.0)]
*/
uniform float offset_phase = 0.0;
/**
* Initial rotation offset, in degrees [90.0 = one quarter rotation]
*/
uniform float offset_rotation = 0.0;
/**
* Number of waves per Gabor patch [1.0 = one wave per patch]
*/
uniform float frequency = 2.0;
/**
* Fraction of radius taken up by Gabor patch [1.0 = use the full width/height]
*/
uniform float scale = 1.0;
/**
* Contrast between the two colours (or wave height) [1.0 = maximum contrast]
*/
uniform float contrast = 1.0;
/**
* Colour of the wave crests [defaults to white]
*/
uniform vec4 colour1: source_color = vec4(1.0, 1.0, 1.0, 1.0);
/**
* Colour of the wave valleys [defaults to black]
*/
uniform vec4 colour2: source_color = vec4(0.0, 0.0, 0.0, 1.0);
void fragment() {
float time_phase = TIME * speed_phase * PI + offset_phase * PI * 2.0 + PI/2.0;
float time_rotation = TIME * speed_rotation * PI / 4.0 + offset_rotation * PI * 2.0 / 360.0;
float sinr = sin(time_rotation);
float cosr = cos(time_rotation);
// normalise and adjust scale
vec2 uv = (UV - vec2(0.5)) * vec2(2.0) / sqrt(scale);
// rotation [https://forum.godotengine.org/t/simple-texture-rotation-shader/24198/2]
uv = vec2(uv.x * cosr - uv.y * sinr, uv.x * sinr + uv.y * cosr);
// create wave structure
float dist = length(uv);
float val_phase = (sin(uv.x * PI * 2.0 * frequency + time_phase) + 1.0) * 0.5;
vec4 colour = colour1 * val_phase + colour2 * (1.0-val_phase);
// gaussian smoothing
colour *= smoothstep(0.0, 1.0, 1.0 - dist);
colour.a *= contrast;
COLOR = vec4(colour);
}