HLSL starter

glint · Examples · Tutorials · Gallery

The same editor, in HLSL: float3, lerp, frac, saturate, mul... translated to GLSL in the browser. Switch any pass in Pass settings.

Audio-reactive: it moves with music from a microphone, line-in or a file.

HLSL starter: an audio-reactive HLSL 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 HLSL.

vertex shader

// HLSL vertex shader (translated to GLSL in the browser).
float4x4 mvp;

struct VSOut
{
    float4 pos : SV_Position;
    float2 uv : TEXCOORD0;
    float3 normal : NORMAL;
};

VSOut main(float4 pos : POSITION, float3 normal : NORMAL, float2 uv : TEXCOORD0)
{
    VSOut o;
    o.pos = mul(mvp, pos);
    o.uv = uv;
    o.normal = normal;
    return o;
}

fragment shader

// HLSL pixel shader (translated to GLSL in the browser).
// Globals are uniforms, as in Direct3D: glint fills in time, resolution, spectrum, texture0... by name.
float time;
float2 resolution;
float2 mouse;
float3 spectrum;
Texture2D texture0;
SamplerState sampler0;

float3 palette(float t)
{
    return 0.5 + 0.5 * cos(6.28318 * (t + float3(0.0, 0.33, 0.67)));
}

float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD0) : SV_Target
{
    float2 p = (pos.xy - 0.5 * resolution) / resolution.y;
    float2x2 rot = float2x2(cos(time * 0.3), -sin(time * 0.3), sin(time * 0.3), cos(time * 0.3));
    p = mul(rot, p);
    float d = length(p);
    float3 col = palette(d * 2 - time * 0.4 + spectrum.x);
    col *= saturate(1.2 - d);
    col = lerp(col, frac(col * 4), 0.15);
    return float4(col, 1);
}

More HLSL & Bonzomatic examples

Bonzomatic starter · HLSL raymarcher · Fire (HLSL)