Last active
May 18, 2023 10:46
-
-
Save keijiro/ddc78ee004f7673279f49747a8f58ca1 to your computer and use it in GitHub Desktop.
Disco mode shader for Windows Terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Texture2D shaderTexture; | |
SamplerState samplerState; | |
cbuffer PixelShaderSettings | |
{ | |
float Time; | |
float Scale; | |
float2 Resolution; | |
float4 Background; | |
}; | |
float Rand(float2 uv) | |
{ | |
return frac(sin(dot(uv, float2(12.9898, 78.233))) * 43758.5453); | |
} | |
float3 Hue2RGB(float h) | |
{ | |
h = frac(h); | |
float r = abs(h * 6 - 3) - 1; | |
float g = 2 - abs(h * 6 - 2); | |
float b = 2 - abs(h * 6 - 4); | |
return saturate(float3(r, g, b)); | |
} | |
float DiscoShake(float2 uv) | |
{ | |
float amp = pow(1 - frac(Time * 2), 5) * 0.02; | |
return sin(uv.y * 40 + Time * 2) * amp; | |
} | |
float3 DiscoHue(float2 uv) | |
{ | |
float2 p = floor(uv * Resolution / float2(32, 256)); | |
float t = floor(Time * 4); | |
float hue = Rand(p * 0.01 + t * 0.001); | |
return Hue2RGB(hue); | |
} | |
float3 DiscoBar(float2 uv, float seed) | |
{ | |
float freq1 = lerp(0.9, 1.8, Rand(seed)); | |
float freq2 = lerp(0.5, 2.2, Rand(seed + 1)); | |
float offs = lerp(-10, 10, Rand(seed + 2)); | |
float y = 0.5 + sin(Time * freq1 + offs) * 0.5; | |
float3 rgb = Hue2RGB(frac(Time * freq2 + offs)); | |
return rgb * saturate(1 - abs(uv.y - y) * Resolution.y / 40); | |
} | |
float4 main(float4 pos : SV_POSITION, float2 uv : TEXCOORD) : SV_TARGET | |
{ | |
uv.y += DiscoShake(uv); | |
float4 src = shaderTexture.Sample(samplerState, uv); | |
float lum = saturate(dot(src.rgb, 1.0 / 3) * 2); | |
float3 rgb = lerp(DiscoHue(uv), 1, 0.1) * lum; | |
for (uint i = 0; i < 6; i++) rgb += DiscoBar(uv, 0.123 * i); | |
return float4(rgb, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment