Nodes: Spotlight

glint · Examples · Tutorials · Gallery

Visual node mode: a checkerboard lit only where the mouse points: Distance from the mouse, through Smoothstep and One minus, is the light.

Nodes: Spotlight: a GLSL shader

An example in glint, a free live shader editor in the browser: the GLSL code floats over the running picture and recompiles as you type.

The code

One pass, in GLSL.

fragment shader (generated from a node graph)

#version 300 es
precision highp float;

// Generated from nodes: edit the graph, or use "Convert to code" to take it from here by hand.
uniform float time;
uniform vec2 resolution;
uniform vec2 mouse;

in vec2 v_texcoord;
out vec4 fragColor;

vec3 n_hsv(vec3 c) { vec3 p = abs(fract(c.xxx + vec3(1.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - 3.0); return c.z * mix(vec3(1.0), clamp(p - 1.0, 0.0, 1.0), c.y); }

void main() {
  // Time
  float nn5dnha4rwi_t = time * 0.05;
  // HSV
  vec3 nn5dnha5sm9_rgb = n_hsv(vec3(nn5dnha4rwi_t, 0.5, 1.0));
  // UV
  vec2 nn5dng9whhk_uv = (v_texcoord * 2.0 - 1.0) * vec2(resolution.x / resolution.y, 1.0);
  vec2 nn5dng9whhk_st = v_texcoord;
  // Checker
  float nn5dnha1915_out = mod(floor(nn5dng9whhk_uv.x * 8.0 * 0.5) + floor(nn5dng9whhk_uv.y * 8.0 * 0.5), 2.0);
  // Remap
  float nn5dnha28er_out = (0.15 + (nn5dnha1915_out - 0.0) / (1.0 - 0.0) * (0.9 - 0.15));
  // Mouse
  vec2 nn5dng9xmuu_uv = (mouse * 2.0 - 1.0) * vec2(resolution.x / resolution.y, 1.0);
  vec2 nn5dng9xmuu_st = mouse;
  // Distance
  float nn5dng9y6ng_out = distance(nn5dng9whhk_uv, nn5dng9xmuu_uv);
  // Smoothstep
  float nn5dnh9zlw0_out = smoothstep(0.0, 0.6, nn5dng9y6ng_out);
  // One minus
  float nn5dnha0wth_out = (1.0 - nn5dnh9zlw0_out);
  // Multiply
  float nn5dnha3zh3_out = (nn5dnha28er_out * nn5dnha0wth_out);
  // Multiply
  vec3 nn5dnha6smt_out = (nn5dnha5sm9_rgb * vec3(nn5dnha3zh3_out));
  fragColor = vec4(nn5dnha6smt_out, 1.0);
}

More Nodes & glitch examples

Nodes: Kaleido checker · Nodes: Neon grid · Nodes: Expression · Nodes: Sunset stripes · Nodes: Colour wheel rings · Nodes: Marble · Nodes: Beat circle · Nodes: Zoom trails